diff options
author | coletdjnz <coletdjnz@protonmail.com> | 2023-06-03 18:33:51 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-03 06:33:51 +0000 |
commit | 2fb35f6004c7625f0dd493da4a5abf0690f7777c (patch) | |
tree | 39ee7ec51b334991e0d9c29c8fade65f378d6b02 | |
parent | 1a7dcca378e80a387923ee05c250d8ba122441c6 (diff) | |
download | hypervideo-pre-2fb35f6004c7625f0dd493da4a5abf0690f7777c.tar.lz hypervideo-pre-2fb35f6004c7625f0dd493da4a5abf0690f7777c.tar.xz hypervideo-pre-2fb35f6004c7625f0dd493da4a5abf0690f7777c.zip |
[extractor/youtube] Support shorter relative time format (#7191)
See: https://github.com/TeamNewPipe/NewPipeExtractor/issues/1067
Authored by: coletdjnz
-rw-r--r-- | yt_dlp/extractor/youtube.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index ccf97705a..6e7485c03 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -893,9 +893,16 @@ class YoutubeBaseInfoExtractor(InfoExtractor): def extract_relative_time(relative_time_text): """ Extracts a relative time from string and converts to dt object - e.g. 'streamed 6 days ago', '5 seconds ago (edited)', 'updated today' + e.g. 'streamed 6 days ago', '5 seconds ago (edited)', 'updated today', '8 yr ago' """ - mobj = re.search(r'(?P<start>today|yesterday|now)|(?P<time>\d+)\s*(?P<unit>microsecond|second|minute|hour|day|week|month|year)s?\s*ago', relative_time_text) + + # XXX: this could be moved to a general function in utils.py + # The relative time text strings are roughly the same as what + # Javascript's Intl.RelativeTimeFormat function generates. + # See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat + mobj = re.search( + r'(?P<start>today|yesterday|now)|(?P<time>\d+)\s*(?P<unit>sec(?:ond)?|s|min(?:ute)?|h(?:our|r)?|d(?:ay)?|w(?:eek|k)?|mo(?:nth)?|y(?:ear|r)?)s?\s*ago', + relative_time_text) if mobj: start = mobj.group('start') if start: |