youtube_explode/README.md

94 lines
3.5 KiB
Markdown
Raw Normal View History

2020-02-20 19:54:08 +01:00
# YoutubeExplodeDart
2020-02-28 22:38:01 +01:00
This is a port of the [YoutubeExplode] library from C#, most of the API functions or doc comments come from YoutubeExplode's API.
2020-02-20 19:50:10 +01:00
2020-02-28 22:38:01 +01:00
---
2020-02-20 19:54:08 +01:00
2020-02-28 22:38:01 +01:00
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.
2020-02-20 19:54:08 +01:00
2020-02-28 22:38:01 +01:00
## 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
## Differences from YoutubeExplode
- The entry point is `YoutubeExplode`, not `YoutubeClient`.
## Install
Add the dependency to the pubspec.yaml (Check for the latest version)
```yaml
2020-06-07 23:08:49 +02:00
youtube_explode_dart: ^1.0.0
2020-02-28 22:38:01 +01:00
```
Import the library
```dart
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.
```dart
var yt = YoutubeExplode();
```
## Get video metadata
The [Video][Video] class contains info about the video such as the video title, the duration or the search keywords.
```dart
2020-06-05 20:14:22 +02:00
var video = yt.video.get(id); // Returns a Video instance.
2020-02-28 22:38:01 +01:00
```
2020-06-07 23:08:49 +02:00
## Get video streams
2020-06-05 20:18:42 +02:00
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][VidExample]).
2020-02-28 22:38:01 +01:00
```dart
2020-06-05 20:18:42 +02:00
var manifest = yt.videos.streamsClient.getManifest(videoId);
2020-02-28 22:38:01 +01:00
2020-06-05 20:18:42 +02:00
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.
2020-02-28 22:38:01 +01:00
```
Be aware, the muxed streams don't hold the best quality, to achieve so, you'd need to merge the audio and video streams.
2020-06-07 23:08:49 +02:00
## Closed Captions
2020-02-28 22:38:01 +01:00
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.
```dart
2020-06-07 23:08:49 +02:00
var trackInfos = await yt.videos.closedCaptions.getManifest(videoId); // Get the caption track infos
var trackInfo = manifest.getByLanguage(en); // Get english caption.
var track = await track.getByTime(duration); // Get the caption displayed at `duration`.
2020-02-28 22:38:01 +01:00
```
## Cleanup
You need to close `YoutubeExplode`'s http client when done otherwise this could halt the dart process.
```dart
yt.close();
```
2020-03-06 23:18:33 +01:00
# Examples:
Available on [GitHub][Examples]
2020-02-28 22:38:01 +01:00
---
2020-03-06 23:18:33 +01:00
2020-02-28 22:38:01 +01:00
Check the [api doc][API] for additional information.
[YoutubeExplode]: https://github.com/Tyrrrz/YoutubeExplode/
[Video]: https://pub.dev/documentation/youtube_explode_dart/latest/youtube_explode/Video-class.html
[VidExample]: https://github.com/Hexer10/youtube_explode_dart/blob/master/example/video_download.dart
2020-03-06 23:18:33 +01:00
[API]: https://pub.dev/documentation/youtube_explode_dart/latest/youtube_explode/youtube_explode-library.html
[Examples]: [https://github.com/Hexer10/youtube_explode_dart/tree/master/example]