1
0
Fork 0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2026-03-18 02:11:36 +00:00

Remove with requests when it is unnecessary

This commit is contained in:
Cadence Ember 2022-01-16 21:51:26 +13:00
parent 73b4fbabf7
commit 68cfbb809f
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
6 changed files with 244 additions and 244 deletions

View file

@ -16,12 +16,12 @@ def extract_captions_from_dict(captions, *, lang=None, label=None):
return captions
url = next(caption["second__remoteUrl"] for caption in captions["captions"] if caption["languageCode"] == lang or caption["label"] == label)
with requests.get(url) as r:
r.raise_for_status()
# remove extraneous " align:start position:0%" on timestamps lines on auto-generated captions
if (lang and "auto-generated" in lang) or (label and "auto-generated" in label):
return re.sub(r"^([0-9:.]+ --> [0-9:.]+).*$", r"\1", r.content.decode("utf8"), flags=re.MULTILINE)
return r
r = requests.get(url)
r.raise_for_status()
# remove extraneous " align:start position:0%" on timestamps lines on auto-generated captions
if (lang and "auto-generated" in lang) or (label and "auto-generated" in label):
return re.sub(r"^([0-9:.]+ --> [0-9:.]+).*$", r"\1", r.content.decode("utf8"), flags=re.MULTILINE)
return r
def extract_captions_from_video(id):
return {