How to force YouTube subtitles (closed captions) t

2019-07-09 02:12发布

问题:

I own a YouTube video, and I typed up subtitles for it.

I've tagged it with yt:cc=on, and I've embedded its iframe onto my website using cc_load_policy=1&cc=1 (see docs).

When I visit my webpage using Chrome on my desktop, the captions appear by default, which is the desired experience.

But when I visit the webpage using my iPhone (Chrome on iOS), the captions do not appear by default. How can I make captions appear by default on iOS?

(They are available if I click the speech bubble icon, but I don't want users to need to know how to do that.)

回答1:

Also answered on this possible duplicate

The only way I found is changing the URI from this pattern

"https://www.youtube.com/watch?v=" + video_id

to this pattern

"https://www.youtube-nocookie.com/embed/" + video_id + "?hl=" lang_code

On bash/Linux you can just copy the URI with that structure and then run this command to transform clipboard content (you can make an alias):

xclip -selection c -o | echo "$(cat -)?&hl=es-419" | sed "s|youtube.com/watch?v=|youtube-nocookie.com/embed/|1" | xclip -selection c

On the example from above I hardcoded Spanish language code. You should use one of the available language codes for that particular video. You can list the available subtitles ISO 639-1 language codes with youtube-dl, under the section Available subtitles for (won't work for automatic captions):

youtube-dl --list-subs "{video_id or url}"

The only drawback is that the video will cover the complete screen... which might be good thing to stop procrastinating with related videos :)