Coder Social home page Coder Social logo

Comments (10)

Hexer10 avatar Hexer10 commented on August 28, 2024 4

You can extract them it's just that you can't directly.
To explain it clearly: Youtube only provides some subtitles tracks by default (those uploaded by the user and autogenerated ones, iirc they are in the language of the video), the translation of the tracks is not available right away and you need to generate their url with the code I posted before:

var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
var trackInfo = manifest.getByLanguage('en', autoGenerate: false, format: ClosedCaptionFormat.srv3); // Or manifest.tracks.first if you just want to get an available track.
if (trackInfo != null) {
    var subtitles = await yt.videos.closedCaptions.getSubTitles(trackInfo.autoTranslate('vi'));
}

PS: I'm only now noticing that I posted the wrong code in the previous comment, sorry

from youtube_explode_dart.

Hexer10 avatar Hexer10 commented on August 28, 2024

Fetching auto-translated closed captions is not yet support, I'm planning to implement it in the coming days

from youtube_explode_dart.

Hexer10 avatar Hexer10 commented on August 28, 2024

This was implemented see the unit tests to have an idea on how to implement this:

test('Get closed captions of a video', () async {
var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
expect(manifest.tracks, isNotEmpty);
});
test('Get closed caption track of a video', () async {
var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
var trackInfo = manifest.tracks.first;
var track = await yt.videos.closedCaptions.get(trackInfo);
expect(track.captions, isNotEmpty);
});
test('Get closed caption track at a specific time', () async {
var manifest = await yt.videos.closedCaptions
.getManifest('WOxr2dmLHLo', autoGenerated: false);
var trackInfo = manifest.getByLanguage('en');
var track = await yt.videos.closedCaptions.get(trackInfo.first);
var caption =
track.getByTime(const Duration(hours: 0, minutes: 1, seconds: 48));
expect(caption, isNotNull);
expect(caption.parts, isEmpty);
expect(caption.text,
'The second way to add subtitles is the one\nwe always use.');
});
test('Get auto-generated closed caption track at a specific time', () async {
var manifest = await yt.videos.closedCaptions
.getManifest('ppJy5uGZLi4', autoGenerated: true);
var trackInfo = manifest.getByLanguage('en');
var track = await yt.videos.closedCaptions.get(trackInfo.first);
var caption =
track.getByTime(const Duration(hours: 0, minutes: 13, seconds: 22));
var captionPart = caption.getPartByTime(const Duration(milliseconds: 200));
expect(caption, isNotNull);
expect(captionPart, isNotNull);
expect(caption.text, 'how about this black there are some');
expect(captionPart.text, ' about');
});

from youtube_explode_dart.

tuanbs avatar tuanbs commented on August 28, 2024

Hello, thanks for this. The auto-generated works fine, but the auto-translate is not working. Hope it's supported in the near future.

from youtube_explode_dart.

Hexer10 avatar Hexer10 commented on August 28, 2024

Seems like youtube implement some changes recently now the request must include some kind of specific query parameter, I'll look into this when I have time

from youtube_explode_dart.

Hexer10 avatar Hexer10 commented on August 28, 2024

It now should be fixed please read the changelog and try again

from youtube_explode_dart.

tuanbs avatar tuanbs commented on August 28, 2024

Hello, thanks for the update. But it's still not working with auto-translate track. For ex, I tried the following test and got the null result:

var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
var trackInfo = manifest.tracks.firstWhere((element) => element.language.code == 'vi', orElse: () => null);
if (trackInfo != null) {
    var subtitles = await yt.videos.closedCaptions.getSubTitles(trackInfo);
}

I got null value for trackInfo. But as you can see in the attached image, the video has Vietnamese (vi) auto-translate track:
Screen Shot 2020-12-31 at 10 57 21 am

from youtube_explode_dart.

Hexer10 avatar Hexer10 commented on August 28, 2024

Youtube does not provide autotranslated tracks by default you first need to get a track provided by youtube, and then autotranslate it:

var manifest = await yt.videos.closedCaptions.getManifest('WOxr2dmLHLo');
var trackInfo = manifest.getByLanguage('en', autoGenerate: false, format: ClosedCaptionFormat.srv3); // Or manifest.tracks.first if you just want to get an available track.
if (trackInfo != null) {
    var subtitles = await yt.videos.closedCaptions.getSubTitles(trackInfo);
}

from youtube_explode_dart.

tuanbs avatar tuanbs commented on August 28, 2024

@Hexer10 Does that mean youtube_explode_dart cannot extract the auto-translate track? I think it should be possible because I see Youtube-dl can extract it.

from youtube_explode_dart.

tuanbs avatar tuanbs commented on August 28, 2024

@Hexer10 Awesome. Finally I'm able to get the auto-translate CC thanks to your code. Thank you very much. Please keep evolving this plugin as you guys are doing amazing job. ๐Ÿฅ‡

from youtube_explode_dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.