패키지, 저장소 및 앱 카테고리 검색

패키지 상세v3.1.0

youtube_explode_dart

YouTube Explode 라이브러리의 다트 버전입니다. YouTube API 키 없이도 여러 API 기능을 지원합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
5.9만
좋아요
699
Pub 점수
140

패키지 설치

flutter pub add youtube_explode_dart

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

youtube_explode_dart는 YouTube Explode 프로젝트의 기능을 재현하는 Dart 라이브러리로, YouTube API 키 없이도 직접 YouTube 콘텐츠와 상호작용할 수 있게 해줍니다. YouTube의 공개 데이터를 파싱하여 동영상 세부 정보, 플레이리스트, 검색 결과 등을 가져올 수 있습니다. 크로스플랫폼 사용을 위해 설계되어 Android, iOS, Web, macOS, Windows, Linux에서 원활하게 작동합니다. 최소한의 설정으로 실시간 YouTube 데이터에 접근이 필요한 애플리케이션에 적합합니다.

사용 사례

  • 비디오 메타데이터 가져오는 중
  • YouTube 동영상 검색
  • 플레이리스트 내용 추출
  • YouTube 클라이언트 빌드
  • 동적 콘텐츠를 가진 비디오 플레이어 만들기

주요 기능

  • API 키가 필요하지 않습니다
  • 크로스 플랫폼 지원
  • 실시간 데이터 파싱
  • 가볍고 빠름
  • 비디오, 재생 목록 및 검색 작업을 지원합니다

적합한 대상

  • 유튜브 기반 앱
  • 미디어 탐색 도구
  • 교육 플랫폼
  • 콘텐츠 집약 서비스
  • 오프라인 비디오 탐색기

고려 사항

  • 공개된 YouTube HTML 파싱에 의존합니다
  • YouTube 인터페이스 변경 시 작동하지 않을 수 있습니다
  • 고용량 요청에 적합하지 않습니다
  • 제한된 공식 지원
  • 직접 스크래핑으로 인해 속도 제한이 발생할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

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 License Lint

It used to build Youtube Downloader Flutter (A cross-platform 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

  • 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.

Usage

Install

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

youtube_explode_dart: ^2.3.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 (available only in 360p)
  • 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.streams.getManifest('Dpp1sIL1m5Q');

print(manifest); // Prints the list of streams available for the video.

// If you want to specify which youtube clients to use to get the manifest you can do so:
var manifest = yt.videos.streams.getManifest(videoId, ytClients: [
  YoutubeApiClient.safari,
  YoutubeApiClient.androidVr  
]); // The streams provided by both clients will be merged.

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

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

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

// Muxed (audio + video) stream with the highest video quality. NOTE: Don't rely on this, muxed streams are limited to 360p30.
var streamInfo = streamManifest.muxed.withHigestVideoQuality();

// HLS (m3u8) streams are also supported
var streamInfo = streamManifest.hls;

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

// Get the actual byte stream
var stream = yt.video.streams.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 360p30.

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.

Using a signature solver

Some youtube clients require you to complete a js challenge in order to download a video. This requires having a full js runtime like deno, nodejs or quickjs. Currently the only implemented runtime is deno, see the following snippet for how to use it:

import 'package:youtube_explode_dart/solvers.dart';

final solver = await DenoEJSSolver.init();
var yt = YoutubeExplode(jsSolver: solver);

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."
  }
Get a list of related videos
var video = yt.videos.get('https://youtube.com/watch?v=Dpp1sIL1m5Q');
var relatedVideos = await yt.videos.getRelatedVideos(video); // video must be a Video instance.
print(relatedVideos); //prints the list of related videos

// to get the next page of related videos
relatedVideos = await relatedVideos.nextPage();

If no related video is found getRelatedVideos or nextPage will return null.

Get comments

You can easily get the video comments of a given video, the return value of comments.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.comments.getComments(video);

var replies = await yt.videos.comments.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();
Troubleshooting

If you encounter any issues, please check that it has not been reported already in the issues section.

When reporting a new issue, make sure to follow the issue template and report the logs after having enabled the logging:

import 'package:logging/logging.dart';

...

// Before any YoutubeExplode code
Logger.root.level = Level.FINER;
Logger.root.onRecord.listen((e)  {
  print(e);
  if (e.error != null) {
   print(e.error);
   print(e.stackTrace);
  }
});

To the very minimum the video id causing the issue (if applicable) and the code snippet that is causing the issue must be provided.

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
  • Tyrrrz for creating YoutubeExplode in C#
  • Hexer10 (me) who ported the library over to Dart.
  • yt-dlp for documentation and reverse engineering about the YouTube apis, and implementation of the EJS modules.
  • All the Contributors of this repository.

카테고리

의존성

의존성 목록 12 개

소스 저장소

이 패키지를 사용하는 프로젝트