Download a video stream
masterYouTube videos provide different stream types:
- Muxed: Contains both audio and video (limited to 360p30).
- Audio-only: Contains only audio.
- Video-only: Contains only video.
To download, first request the stream manifest using yt.videos.streams.getManifest(videoId). You can optionally specify ytClients (e.g., YoutubeApiClient.safari) to merge streams from different clients. After filtering the manifest for a specific streamInfo, use yt.videos.streams.get(streamInfo) to obtain the actual byte Stream and pipe it to a file.
var yt = YoutubeExplode();
// 1. Get the manifest
var manifest = yt.videos.streams.getManifest('Dpp1sIL1m5Q');
// 2. Filter for a specific stream
// highest bitrate audio-only stream
var streamInfo = manifest.audioOnly.withHigestBitrate();
// 3. Get the actual byte stream
var stream = yt.videos.streams.get(streamInfo);
// 4. Pipe to a file
var file = File(filePath);
var fileStream = file.openWrite();
await stream.pipe(fileStream);
await fileStream.flush();
await fileStream.close();