From e72c48ffbd863f478431c19ea751feeff5e7a61a Mon Sep 17 00:00:00 2001 From: girst Date: Wed, 2 Feb 2022 17:13:50 +0100 Subject: [PATCH] improve reddit video length matching - strict xx:yy or xx:yy:zz format - ignore hours if 00 (not 00 minutes) --- app/reddit/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/reddit/lib.py b/app/reddit/lib.py index feb1381..3a3db48 100644 --- a/app/reddit/lib.py +++ b/app/reddit/lib.py @@ -54,7 +54,7 @@ def parse_reddit_videos(data): match = re.match(r'^https?://(?:www.|m.)?(?:youtube.com/watch\?(?:.*&)?v=|youtu.be/|youtube.com/embed/|youtube.com/)([-_0-9A-Za-z]+)(?:[?&#]t=([0-9hms:]+))?', e['url']) video_id = match.group(1) timestamp = match.group(2) - maybe_length = re.match(r'.*[\[(]([0-9:mhs]+)[\])]', e['title']) # .* to match last occurence in line (probably terrible for performance?) + maybe_length = re.match(r'.*[\[(](?:00:)?(\d\d(?::\d\d){1,2})[\])]', e['title']) # .* to match last occurence in line (probably terrible for performance?) maybe_length = maybe_length.group(1) if maybe_length else None except: continue # XXX: should we log that? -- 2.39.3