• Stars
    star
    262
  • Rank 151,207 (Top 4 %)
  • Language
    Dart
  • License
    BSD 3-Clause "New...
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dart library to interact with many Youtube APIs

YoutubeExplodeDart

This is a port of the YoutubeExplode library from C#, most of the functions, doc comments, readme information, is taken from YoutubeExplode repository.

Pub Version GitHub Workflow Status License Lint

It used to build Youtube Downloader Flutter (A cross-platoform application to download video streams from youtube using this library & flutter)


YoutubeExplode is a library that provides an interface to query metadata of YouTube videos, playlists and channels, as well as to resolve and download video streams and closed caption tracks. Behind a layer of abstraction, the library parses raw page content and uses reverse-engineered AJAX requests to retrieve information. As it doesn't use the official API, there's also no need for an API key and there are no usage quotas.

Features from YoutubeExplode

  • Retrieve metadata on videos, playlists, channels, streams, and closed captions
  • Execute search queries and get resulting videos.
  • Get or download video streams.
  • Get closed captions.
  • Get video comments.
  • All model extend Equatable to easily perform equality checks

Differences from YoutubeExplode

  • The entry point is YoutubeExplode, not YoutubeClient.
  • Download closed captions as srt is not supported yet.
  • Search queries can be fetched from the search page as well (thus fetch Videos, Channels and Playlists).
  • More APIs implemented.

Usage

Install

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

youtube_explode_dart: ^1.10.4

Import the library

import 'package:youtube_explode_dart/youtube_explode_dart.dart';

Getting metadata of a video

The following example shows how you can extract various metadata from a YouTube video:

// You can provide either a video ID or URL as String or an instance of `VideoId`.
var video = yt.videos.get('https://youtube.com/watch?v=Dpp1sIL1m5Q'); // Returns a Video instance.

var title = video.title; // "Scamazon Prime"
var author = video.author; // "Jim Browning"
var duration = video.duration; // Instance of Duration - 0:19:48.00000

Downloading a video stream

Every YouTube video has a number of streams available. These streams may have different containers, video quality, bitrate, etc.

On top of that, depending on the content of the stream, the streams are further divided into 3 categories:

  • Muxed streams -- contain both video and audio
  • Audio-only streams -- contain only audio -- Video-only streams -- contain only video

You can request the stream manifest to get available streams for a particular video:

var yt = YoutubeExplode();

var manifest = yt.videos.streamsClient.getManifest('Dpp1sIL1m5Q');

Once you get the manifest, you can filter through the streams and choose the one you're interested in downloading:

// Get highest quality muxed stream
var streamInfo = streamManifest.muxed.withHigestVideoQuality();

// ...or highest bitrate audio-only stream
var streamInfo = streamManifest.audioOnly.withHigestBitrate()

// ...or highest quality MP4 video-only stream
var streamInfo.videoOnly.where((e) => e.container == Container)

Finally, you can get the actual Stream object represented by the metadata:

if (streamInfo != null) {
  // Get the actual stream
  var stream = yt.video.streamClient.get(streamInfo);
  
  // Open a file for writing.
  var file = File(filePath);
  var fileStream = file.openWrite();

  // Pipe all the content of the stream into the file.
  await stream.pipe(fileStream);

  // Close the file.
  await fileStream.flush();
  await fileStream.close();
}

While it may be tempting to just always use muxed streams, it's important to note that they are limited in quality. Muxed streams don't go beyond 720p30.

If you want to download the video in maximum quality, you need to download the audio-only and video-only streams separately and then mux them together on your own. There are tools like FFmpeg that let you do that.

Working with playlists

Among other things, YoutubeExplode also supports playlists:

var yt = YoutubeExplode();

// Get playlist metadata.
var playlist = await yt.playlists.get('xxxxx');

var title = playlist.title;
var author = playlist.author;

  await for (var video in yt.playlists.getVideos(playlist.id)) {
    var videoTitle = video.title;
    var videoAuthor = video.author;
  }

var playlistVideos = await yt.playlists.getVideos(playlist.id);

// Get first 20 playlist videos.
var somePlaylistVideos = await yt.playlists.getVideos(playlist.id).take(20);

Extracting closed captions

Similarly, to streams, you can extract closed captions by getting the manifest and choosing the track you're interested in:

  var yt = YoutubeExplode();

  var trackManifest = await yt.videos.closedCaptions.getManifest('_QdPW8JrYzQ')

  var trackInfo = manifest.getByLanguage('en'); // Get english caption.
  
  if (trackInfo != null)
  {
     // Get the actual closed caption track.
     var track = await youtube.videos.closedCaptions.get(trackInfo);
      
    // Get the caption displayed at 1:01
    var caption = track.getByTime(Duration(seconds: 61));
    var text = caption?.text; // "And the game was afoot."
  }

Getting comments

You can easily get the video comments of a given video, the return value of commentsClient.getComments(video) is a list-like object which behaves exactly like a List but has an additional method nextPage() which is used in order to get the next comments, it returns null when there are no comments to be fetched anymore.

var comments = await yt.videos.commentsClient.getComments(video);

var replies = await yt.videos.commentsClient.getReplies(comment); // Fetch the comment replies 

Cleanup

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

yt.close();

Examples:

More examples available on GitHub.


Check the api documentation for additional information. You can find how most APIs can be used in the files inside the test/ folder.

Credits

More Repositories

1

youtube_downloader_flutter

YouTube downloader built fully in Flutter
Dart
124
star
2

HexTags

Customize tags & chat colors!
SourcePawn
54
star
3

steam_login

Library to authenticate users with Steam OpenID
Dart
17
star
4

flutter_autoclicker

Autoclicker for windows made in flutter
C++
16
star
5

Sourcemod-HandleDumpParser

Parser for sourcemod handle dumps
Dart
16
star
6

HexRedirect

Workaround for motd in CSGO
PHP
14
star
7

dart_winapi

Dart implementation of winapi
Dart
11
star
8

AirDrop-Core

API To CallAirDrops
SourcePawn
11
star
9

source_server

Source Dedicated Server Rcon Client built with Dart
Dart
10
star
10

HexProps

Allows Admins to spawn props!
SourcePawn
10
star
11

dllimport_gen

A code generation tool that aims to quickly generate dart code from the windows api documentation emulating the DllImport notation in C#.
Dart
10
star
12

Live-Interface

Live interface to view servers
PHP
9
star
13

Telegram

SourcePawn
8
star
14

SourceRCONBot

Get info about your Source server and send RCON commands from Telegram!
PHP
6
star
15

HexVips

Plugin for VIP menu & advantages
SourcePawn
6
star
16

HexTS3Verifier

Verify ts3 user's identiy by logining in you csgo server
SourcePawn
5
star
17

HexSpy

Allow admins to see other player commands!
SourcePawn
5
star
18

HexTTS

Make client latedownload text to speech sounds
C++
4
star
19

windows_clipboard

Dart
4
star
20

SteamAuth

Authenticated users using steam openid and/or gather users informations (/using their SteamID64)!
PHP
4
star
21

StackHealthShot

Reach more that 100HP using healthshots
SourcePawn
3
star
22

TeamSpeak3-Library

TeamSpeak3 ServerQuery library written in Dart
Dart
3
star
23

etag

Create simple HTTP ETags. Port over from JS.
Dart
3
star
24

camera_test_web

Dart
2
star
25

Hexer10

2
star
26

dart_benchmark

A simple banchmarking library for Dart.
Dart
2
star
27

live-server-viewer-app

View the server chat & players from a mobile app
Dart
2
star
28

live-server-viewer

View the live chat in your server from this mobile app
SourcePawn
2
star
29

HexFuture

Issue a command to be done in the future!
SourcePawn
1
star
30

NoKnifeSound

If no damage is done disables the knife damage sound.
SourcePawn
1
star
31

everylint

A library which combines all the linter packages into a single one.
Dart
1
star
32

trenitalia_explode

Dart
1
star
33

RCON-TelegramBOT

Allows connecting to the RCON using a TelegramBOT
PHP
1
star
34

flutter_web_camera

Dart
1
star