1
0
Fork 0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2026-05-04 16:41:37 +00:00

Implement captions

Automatic subtitles are not supported, because youtube_dlc does not
provide them.
This commit is contained in:
bopol 2021-01-17 23:59:14 +01:00 committed by Cadence Ember
parent 985f0c1c32
commit 6709aa30c2
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
5 changed files with 126 additions and 2 deletions

View file

@ -19,7 +19,9 @@ ytdl_opts = {
"playlist_items": "1-100",
"extract_flat": "in_playlist",
"write_pages": True,
"source_address": "0.0.0.0"
"source_address": "0.0.0.0",
"writesubtitles": True,
"allsubtitles": True,
}
ytdl = youtube_dlc.YoutubeDL(ytdl_opts)
@ -171,6 +173,23 @@ def extract_video(id):
"second__width": format["width"],
"second__height": format["height"]
})
if "requested_subtitles" in info and info["requested_subtitles"]:
for language_code, subtitle in info["requested_subtitles"].items():
if language_code != "live_chat":
subtitle_url = subtitle["url"]
label = get_language_label_from_url(subtitle_url)
subtitle_api_url = get_subtitle_api_url(id, label, language_code)
result["captions"].append({
"label": label if label != "" else language_code,
"languageCode": language_code,
"url": subtitle_api_url,
"second__subtitleUrl": subtitle_url # Direct YouTube url
})
result = get_more_stuff_from_file(info["id"], result)