Inaccurate Caption Availability
The project has a bug where, depending on the available captions for a given video, results may not be accurate. Because Youtube seems to return the list of available captions in alphabetical order ( example: English(en) links will be ordered after Dutch(nl) but before German(de)). This means that in the case a language happens to be listed before the user's desired language and is of a different "kind" (ie asr), the project will return poor results.
Example: if "z3Mvd1VEFyw" is the desired video id and languages=['en'], the api will return the CouldNotRetrieveTranscript error despite there being English captions available (just asr).
I am interested in opening a PR to fix this issue and helping maintain the project in general. Let me know if this is ok.
Hi @danielcliu,
thanks for the report. I am aware of this, but haven't gotten around to implementing a proper fix. As you already pointed out this happens, when the timedtext-api URL which is scraped is for an automatically generated subtitle, but the language which is provided by the user, does only have a manually created subtitle (or the other way around). Because the timedtext-api URL contains the kind=asr param, it is only looking for automatically generated subtitles, which it can't find. But the problem goes a bit beyond that. Take a look at this video for example: uzin2GZPJY0. It seems that the subtitles have names on this video. I have only briefly looked into this so far, but this API doesn't work at all for this video, because the way it scrapes and manipulates the timedtext-api URLs isn't compatible to this video.
The solution I see for both of these problems is to find out which transcripts are available for a video and then build the timedtext-api URL according to this, if the option which was chosen by the user is within the list of available transcripts. This is also somewhat related to what was talked about in #22.
As I am currently short on time, I would welcome you contributing to this very much! Have you already looked into this and is there a certain solution you have in mind?
My idea is that where the project already splits at TIMEDTEXT_STRING which contains a list of the available caption links as far as I can tell. I think if I loop through the list and see if '&lang={language}' is in a given link this will solve the problems with the extra url parameters. I believe the manual captions are listed before the ASR ones, so returning the first link that passes the check will give the optimal result
which is basically
The solution I see for both of these problems is to find out which transcripts are available for a video and then build the timedtext-api URL according to this, if the option which was chosen by the user is within the list of available transcripts.
That sounds good. However, I am not sure if "manual captions are listed before the ASR ones" is true. Please double check that before, implementing it this way ;) I am looking forward to your contribution 👍!
I have a branch that I believe fixes the bug, but I can't get it to pass the test test_get_transcript__fallback_language_is_used. I'm unsure how that test is supposed to work.
In addition, is there an auto-formater or something that you want me to use?
@danielcliu Sorry for the late reply, I am currently on holiday.
The point of the test is to make sure that the transcript for en is retrieved, when de fails, while calling YouTubeTranscriptApi.get_transcript('video_id', ['de', 'en']).
There currently is no auto-formatter. Just stick to PEP-8 and it should be fine.
Has this been fixed and updated the module? I have been running tests, calling installed modules and some videos by default returns subtitles in random language.
@wonseokch Ive had a PR out to fix this issue, but it hasn't been merged. So no, this bug is not fixed yet, but you can always just specify as the language you want.
@danielcliu Thanks for the prompt response. I've tried to pass the language as a parameter but it wouldn't work.
YouTubeTranscriptApi.get_transcript(id, ['en'])
How were you specifying the language?
@wonseokch it is probably not working because, as the README implies, languages is a default argument, so you must set it by name. So try YouTubeTranscriptApi.get_transcript(id, languages=['en']). However, I don't see the README cover this call for get_transcript(), so if that doesn't work try YouTubeTranscriptApi.get_transcripts([id], languages=['en']) instead
@danielcliu Thank you! YouTubeTranscriptApi.get_transcript(id, languages=['en']) is working fine
This has been fixed with v0.2.0. Many thanks to @danielcliu for the contribution and efforts in the reviewing process!