summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSergey M․ <[email protected]>2020-12-31 05:06:54 +0700
committerSergey M․ <[email protected]>2020-12-31 05:07:57 +0700
commit4046ffe1e16a65196e113cb12aa2d935f7f17c06 (patch)
tree1ba633526492bcff1e6dac3df05d5a5573219a05
parentd1d0612160ed2d753cc57b30483776b7c1b03473 (diff)
downloadyoutube-dl-4046ffe1e16a65196e113cb12aa2d935f7f17c06.tar.gz
youtube-dl-4046ffe1e16a65196e113cb12aa2d935f7f17c06.zip
[redditr] Fix review issues and extract source thumbnail (closes #27503)
-rw-r--r--youtube_dl/extractor/reddit.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/youtube_dl/extractor/reddit.py b/youtube_dl/extractor/reddit.py
index 2d1a1fd99..222fa0172 100644
--- a/youtube_dl/extractor/reddit.py
+++ b/youtube_dl/extractor/reddit.py
@@ -8,8 +8,8 @@ from ..utils import (
int_or_none,
float_or_none,
try_get,
- url_or_none,
unescapeHTML,
+ url_or_none,
)
@@ -57,7 +57,8 @@ 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',
@@ -120,16 +121,27 @@ class RedditRIE(InfoExtractor):
age_limit = None
thumbnails = []
- images = try_get(
- data, lambda x: x['preview']['images'][0]['resolutions']) or []
- for image in images:
- url = url_or_none(unescapeHTML(image['url']))
- if url is not None:
- thumbnails.append({
- 'url': url,
- 'width': int_or_none(image['width']),
- 'height': int_or_none(image['height']),
- })
+
+ 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',