diff options
author | pukkandan <pukkandan@gmail.com> | 2021-01-01 17:56:37 +0530 |
---|---|---|
committer | pukkandan <pukkandan@gmail.com> | 2021-01-05 00:02:27 +0530 |
commit | 29f7c58aafb25a094e267a8a3fb355e102e42792 (patch) | |
tree | 5537f53fb970bc5b29370f97e8f190a6e4dc7d4e /youtube_dlc/extractor/reddit.py | |
parent | c2b5f3114ff0f2888af211323ad60505d87fb2fd (diff) | |
download | hypervideo-pre-29f7c58aafb25a094e267a8a3fb355e102e42792.tar.lz hypervideo-pre-29f7c58aafb25a094e267a8a3fb355e102e42792.tar.xz hypervideo-pre-29f7c58aafb25a094e267a8a3fb355e102e42792.zip |
Update to ytdl-2021.01.03
Diffstat (limited to 'youtube_dlc/extractor/reddit.py')
-rw-r--r-- | youtube_dlc/extractor/reddit.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/youtube_dlc/extractor/reddit.py b/youtube_dlc/extractor/reddit.py index cd9125388..77f66c966 100644 --- a/youtube_dlc/extractor/reddit.py +++ b/youtube_dlc/extractor/reddit.py @@ -7,6 +7,8 @@ from ..utils import ( ExtractorError, int_or_none, float_or_none, + try_get, + unescapeHTML, url_or_none, ) @@ -55,10 +57,12 @@ class RedditRIE(InfoExtractor): 'id': 'zv89llsvexdz', 'ext': 'mp4', 'title': 'That small heart attack.', - 'thumbnail': r're:^https?://.*\.jpg$', + 'thumbnail': r're:^https?://.*\.(?:jpg|png)', + 'thumbnails': 'count:4', 'timestamp': 1501941939, 'upload_date': '20170805', 'uploader': 'Antw87', + 'duration': 12, 'like_count': int, 'dislike_count': int, 'comment_count': int, @@ -116,13 +120,40 @@ class RedditRIE(InfoExtractor): else: age_limit = None + thumbnails = [] + + def add_thumbnail(src): + if not isinstance(src, dict): + return + thumbnail_url = url_or_none(src.get('url')) + if not thumbnail_url: + return + thumbnails.append({ + 'url': unescapeHTML(thumbnail_url), + 'width': int_or_none(src.get('width')), + 'height': int_or_none(src.get('height')), + }) + + for image in try_get(data, lambda x: x['preview']['images']) or []: + if not isinstance(image, dict): + continue + add_thumbnail(image.get('source')) + resolutions = image.get('resolutions') + if isinstance(resolutions, list): + for resolution in resolutions: + add_thumbnail(resolution) + return { '_type': 'url_transparent', 'url': video_url, 'title': data.get('title'), - 'thumbnail': url_or_none(data.get('thumbnail')), + 'thumbnails': thumbnails, 'timestamp': float_or_none(data.get('created_utc')), 'uploader': data.get('author'), + 'duration': int_or_none(try_get( + data, + (lambda x: x['media']['reddit_video']['duration'], + lambda x: x['secure_media']['reddit_video']['duration']))), 'like_count': int_or_none(data.get('ups')), 'dislike_count': int_or_none(data.get('downs')), 'comment_count': int_or_none(data.get('num_comments')), |