youtube_explode_dart 1.0.0-beta

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

YoutubeExplodeDart #

This is a port of the YoutubeExplode library from C#, most of the API functions or doc comments come from YoutubeExplode's API.


This library provides a class to query metadata of Youtube videos, playlists and channels. This doesn't require an API key and has no usage quotas.

Features from YoutubeExplode #

  • Retrieve info about videos, playlists, channels, media streams, closed caption tracks.
  • Handles all types of videos, including legacy, signed, restricted, non-embeddable and unlisted videos
  • Downloads videos by exposing their media content as a stream
  • Parses and downloads closed caption tracks
  • All metadata properties are exposed using strong types and enums
  • Provides static methods to validate IDs and to parse IDs from URLs
  • No need for an API key and no usage quotas
  • All model extend Equatable to easily perform equality checks
  • Download Stream

Differences from YoutubeExplode #

  • The entry point is YoutubeExplode, not YoutubeClient.

Install #

Add the dependency to the pubspec.yaml (Check for the latest version)

youtube_explode_dart: ^1.0.0-beta

Import the library

import 'package:youtube_explode_dart/youtube_explode_dart.dart';

Usage #

To start using the API you need to initialize the YoutubeExplode class (which will create a new http client), and get (for example) the video id of the video you'd want to retrieve information, which usually is the v parameter.

var yt = YoutubeExplode();

Get video metadata #

The Video class contains info about the video such as the video title, the duration or the search keywords.

var video = yt.video.get(id); // Returns a Video instance.

Get video mediaStream #

The Manifest contains the audio, video and muxed streams of the video. Each of the streams provides an url which can be used to download a video with a get request (See example).

var manifest = yt.videos.streamsClient.getManifest(videoId);

var muxed = manifest.muxed; // List of `MuxedStreamInfo` sorted by video quality.
var audio = manifest.audio; // List of `AudioStreamInfo` sorted by bitrate.
var video = manifest.video; // List of `VideoSteamInfo` sorted by video quality.
// There are available manifest.audioOnly and manifest.videoOnly as well.

Be aware, the muxed streams don't hold the best quality, to achieve so, you'd need to merge the audio and video streams.

Closed Captions - Not yet implemented #

To get the video closed caption it is need to query before the caption track infos, which can be used to retrieve the closed caption.

  var trackInfos = await yt.getVideoClosedCaptionTrackInfos(id); // Get the caption track infos
  if (trackInfos.isEmpty) {
    // No caption is available.
    return;
  }

  var enTrack = trackInfos.firstWhere(
      (e) => e.language.code == 'en'); // Find the english caption track.

  if (enTrack == null) {
    // The english track doesn't exist.
    return;
  }

  var captionTrack = await yt.getClosedCaptionTrack(enTrack); // Get the english closed caption track 
  var captions = captionTrack.captions; // List of ClosedCaption

  captions.first; // Get the first displayed caption.
  captions.getByTime(7); // Get the caption displayed at the 7th second.

Cleanup #

You need to close YoutubeExplode's http client when done otherwise this could halt the dart process.

yt.close();

Examples: #

Available on GitHub


Check the api doc for additional information. More features are provided through extensions.

1.0.0-beta #

  • Updated to v5 of YouTube Explode for C#

0.0.1 #

  • Initial version, created by Stagehand

0.0.2 #

  • Implement channel api

0.0.3 #

  • Remove dart:io dependency.

0.0.4 #

  • Fix #3 : Head request to ge the content length
  • Fix error when getting videos without any keyword.

0.0.5 #

  • Implement Search Api (SearchExtension)

0.0.6 #

  • Implement Caption Api ('CaptionExtension`)
  • Add Custom Exceptions

0.0.7 #

  • Implement Video Purchase error
  • Implement Equatable for models

0.0.8 #

  • Downgrade xml to ^3.5.0

0.0.9 #

  • Bug Fix(PR 11): Use url when retrieving the video's content length.

0.0.10 #

  • Bug fix: Don't throw when captions are not present.
  • New extension: CaptionListExtension adding getByTime function.

0.0.11 #

  • New extension: DownloadExtension adding downloadStream function.

0.0.12 #

  • Bug fix(#15): Fix invalid upload date.

0.0.13 #

  • Bug fix(#15): Fix valid channel expression

0.0.14 #

  • getChannelWatchPage and getVideoWatchPage methods are now public
  • New method: getChannelIdFromVideo

0.0.15 #

0.0.16 #

  • When a video is not available(403) a VideoStreamUnavailableException

0.0.17 #

  • Fixed bug in #23

example/example.dart

import 'package:youtube_explode_dart/youtube_explode_dart.dart';

Future<void> main() async {
  var yt = YoutubeExplode();
  var video =
      await yt.videos.get('https://www.youtube.com/watch?v=bo_efYhYU2A');

  print('Title: ${video.title}');

  // Close the YoutubeExplode's http client.
  yt.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  youtube_explode_dart: ^1.0.0-beta

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:youtube_explode_dart/youtube_explode_dart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
83
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
85
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Fix lib/src/reverse_engineering/responses/watch_page.dart. (-1 points)

Analysis of lib/src/reverse_engineering/responses/watch_page.dart reported 2 hints:

line 16 col 16: The value of the field '_videoLikeExp' isn't used.

line 17 col 16: The value of the field '_videoDislikeExp' isn't used.

Format lib/src/channels/channel_client.dart.

Run dartfmt to format lib/src/channels/channel_client.dart.

Format lib/src/channels/channels.dart.

Run dartfmt to format lib/src/channels/channels.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/exceptions/request_limit_exceeded_exception.dart (Run dartfmt to format lib/src/exceptions/request_limit_exceeded_exception.dart.)
  • lib/src/playlists/playlist_id.dart (Run dartfmt to format lib/src/playlists/playlist_id.dart.)
  • lib/src/reverse_engineering/responses/player_source.dart (Run dartfmt to format lib/src/reverse_engineering/responses/player_source.dart.)
  • lib/src/videos/closed_captions/closed_caption_track.dart (Run dartfmt to format lib/src/videos/closed_captions/closed_caption_track.dart.)
  • lib/src/videos/streams/framerate.dart (Run dartfmt to format lib/src/videos/streams/framerate.dart.)
  • lib/src/videos/streams/video_quality.dart (Run dartfmt to format lib/src/videos/streams/video_quality.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (xml).

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
equatable ^1.1.0 1.2.0
html ^0.14.0+3 0.14.0+3
http ^0.12.0+4 0.12.1
http_parser ^3.1.3 3.1.4
xml ^3.5.0 3.7.0 4.2.0
Transitive dependencies
charcode 1.1.3
collection 1.14.13
convert 2.1.1
csslib 0.16.1
meta 1.1.8
path 1.7.0
pedantic 1.9.0 1.9.1
petitparser 3.0.4
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
Dev dependencies
dart_console ^0.5.0
effective_dart ^1.2.1
test ^1.12.0