youtube_caption_scraper 0.2.0 copy "youtube_caption_scraper: ^0.2.0" to clipboard
youtube_caption_scraper: ^0.2.0 copied to clipboard

Parse subtitles/captions from YouTube without authorization.

example/youtube_caption_scraper_example.dart

import 'package:youtube_caption_scraper/youtube_caption_scraper.dart';

Future<void> main(List<String> arguments) async {
  if (arguments.length != 1) {
    throw Exception('Incorrect usage.');
  }

  final videoUrl = arguments[0];

  final captionScraper = YouTubeCaptionScraper();
  final captionTracks = await captionScraper.getCaptionTracks(videoUrl);

  final subtitles = await captionScraper.getSubtitles(captionTracks[0]);
  for (final subtitle in subtitles) {
    print(
      '${_formatDuration(subtitle.start)} - '
      '${_formatDuration(subtitle.duration)} - '
      '${subtitle.text}',
    );
  }
}

String _formatDuration(Duration duration) {
  return '${duration.inHours}:'
      '${duration.inMinutes.remainder(60)}:'
      '${duration.inSeconds.remainder(60)}:'
      '${duration.inMilliseconds.remainder(60)}';
}
18
likes
160
pub points
74%
popularity

Publisher

verified publisherfperson.dev

Parse subtitles/captions from YouTube without authorization.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

html, http

More

Packages that depend on youtube_caption_scraper