1
0
Fork 0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2026-03-05 12:01:38 +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

@ -2,6 +2,7 @@ import configuration
import datetime
import re
import time
from urllib.parse import urlparse, parse_qs, quote_plus
def length_text_to_seconds(text):
s = text.split(":")
@ -205,3 +206,20 @@ def time_to_past_text(timestamp):
number = diff // unit_value
plural_unit = unit_name if number == 1 else unit_name + "s"
return "{} {} ago".format(number, plural_unit)
def get_language_label_from_url(url_string):
url = urlparse(url_string)
params = parse_qs(url.query)
label = params["name"][0] if "name" in params else "" # name may be in params with empty value
return label
def get_subtitle_api_url(id, label, language_code):
subtitle_api_url = "{}/api/v1/captions/{}?".format(configuration.website_origin, id)
if label == "":
label = language_code
subtitle_api_url += "lang=" + quote_plus(language_code)
else:
subtitle_api_url += "label=" + quote_plus(label)
return subtitle_api_url