youtube_api 0.2.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 36

Youtube API (youtube_api)

pub package

A Flutter plugin for fetching interacting with Youtube Server to fetch data using API. Supports iOS and Android.

Features:

  • Search Video, Playlist, Channel on youtube.
  • Play Youtube Video [Coming Soon]

Usage

To use this plugin, add youtube_api as a dependency in your pubspec.yaml file.

Complete Example Code

Example

alt text


static String key = 'YOUR_API_KEY';
YoutubeAPI ytApi = new YoutubeAPI(key);
List<YT_API> ytResult = [];

String query = "Flutter";
ytResult = await ytApi.Search(query);
// data which are available in ytResult are shown below 

These data are stored in ytResult

[
    {
        "kind": "video",
        "id": "9vzd289Eedk",
        "channelTitle": "Java",
        "title": "WEBINAR - Programmatic Trading in Indian Markets using Python with Kite Connect API",
         "description": "For traders today, Python is the most preferred programming language for trading, as it provides great flexibility in terms of building and executing strategies.",
        "publishedAt":"2016-10-18T14:41:14.000Z",
        "channelId": "UC8kXgHG13XdgsigIPRmrIyA",
        "thumbnails": {
             "default": {
              "url": "https://i.ytimg.com/vi/9vzd289Eedk/default.jpg",
              "width": 120,
              "height": 90
             },
             "medium": {
              "url": "https://i.ytimg.com/vi/9vzd289Eedk/mqdefault.jpg",
              "width": 320,
              "height": 180
             },
             "high": {
              "url": "https://i.ytimg.com/vi/9vzd289Eedk/hqdefault.jpg",
              "width": 480,
              "height": 360
             }
        },
        "channelurl":"https://www.youtube.com/channel/UC8kXgHG13XdgsigIPRmrIyA",
        "url":"https://www.youtube.com/watch?v=9vzd289Eedk"
    },
    {
      "kind": "video"
       // Here will you next result
    },
    {
       // Here will you next result
    },
    {
       // Here will you next result
        "url":"https://www.youtube.com/watch?v=9vzd289Eedk"
    }
 ]

Default Per-page result is 10 and by default it you search for video only.

Type(String) can be video, playlist , channel

maxResults(int) can be 1 - 50

int max = 25;
String type = "channel";
YoutubeAPI ytApi = new YoutubeAPI(key,maxResults: max,Type: type);

Note: This plugin is still under development, and some APIs might not be available yet. Feedback welcome and Pull Requests are most welcome!

[0.1.1] - May 09th 2018

  • Readme Updated

[0.1.0] - May 09th 2018

  • Initial Open Source release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:youtube_api/youtube_api.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}


class _MyAppState extends State<MyApp> {
  static String key = 'YOUTUBE_API_KEY';
  YoutubeAPI ytApi = new YoutubeAPI(key);
  List<YT_API> ytResult = [];

  call_API() async {
    print('UI callled');
    String query = "FLUTTER";
    ytResult = await ytApi.Search(query);
    setState(() {
      print('UI Updated');
    });
  }
  @override
  void initState() {
    super.initState();
    call_API();
    print('hello');
  }
  @override
  Widget build(BuildContext context) {
    call_API();
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: Text('Youtube API'),
          ),
          body: new Container(
            child: ListView.builder(
                itemCount: ytResult.length,
                itemBuilder: (_, int index) => ListItem(index)
            ),
          )
      ),
    );
  }
  Widget ListItem(index){
    return new Card(
      child: new Container(
        margin: EdgeInsets.symmetric(vertical: 7.0),
        padding: EdgeInsets.all(12.0),
        child:new Row(
          children: <Widget>[
            new Image.network(ytResult[index].thumbnail['default']['url'],),
            new Padding(padding: EdgeInsets.only(right: 20.0)),
            new Expanded(child: new Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                new Text(
                  ytResult[index].title,
                  softWrap: true,
                  style: TextStyle(fontSize:18.0),
                ),
                new Padding(padding: EdgeInsets.only(bottom: 1.5)),
                new Text(
                  ytResult[index].channelTitle,
                  softWrap: true,
                ),
                new Padding(padding: EdgeInsets.only(bottom: 3.0)),
                new Text(
                  ytResult[index].description,
                  softWrap: true,
                ),
              ]
            ))
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  youtube_api: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:youtube_api/youtube_api.dart';
  
Version Uploaded Documentation Archive
0.2.1 May 9, 2018 Go to the documentation of youtube_api 0.2.1 Download youtube_api 0.2.1 archive
0.2.0 May 9, 2018 Go to the documentation of youtube_api 0.2.0 Download youtube_api 0.2.0 archive
0.1.1 May 9, 2018 Go to the documentation of youtube_api 0.1.1 Download youtube_api 0.1.1 archive
0.0.1 May 9, 2018 Go to the documentation of youtube_api 0.0.1 Download youtube_api 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
71
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
36
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Health suggestions

Fix lib/youtube_api.dart. (-1 points)

Analysis of lib/youtube_api.dart reported 2 hints:

line 8 col 30: The value of the field '_channel' isn't used.

line 134 col 7: Name types using UpperCamelCase.

Fix lib/generated/i18n.dart. (-0.50 points)

Analysis of lib/generated/i18n.dart reported 1 hint:

line 29 col 7: Name types using UpperCamelCase.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
http >=0.11.3+16 <0.12.0 0.11.3+17 0.12.0
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6
path 1.6.2
sky_engine 0.0.99
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
vector_math 2.0.8