From c40dbb19ab475e8a0e1b29548130adf9ce13ea43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 19 Dec 2015 19:19:26 +0600 Subject: [PATCH] [toggle] Extract thumbnails --- youtube_dl/extractor/togglesg.py | 34 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/youtube_dl/extractor/togglesg.py b/youtube_dl/extractor/togglesg.py index 244c79e8d..a2b89d6bb 100644 --- a/youtube_dl/extractor/togglesg.py +++ b/youtube_dl/extractor/togglesg.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import json +import re from .common import InfoExtractor from ..utils import ( @@ -119,12 +120,8 @@ def _real_extract(self, url): info = self._download_json(req, video_id, 'Downloading video info json') title = info['MediaName'] - duration = int_or_none(info.get('Duration')) - thumbnail = info.get('PicURL') - description = info.get('Description') - created_at = parse_iso8601(info.get('CreationDate') or None) - formats = [] + formats = [] for video_file in info.get('Files', []): ext = determine_ext(video_file['URL']) vid_format = video_file['Format'].replace(' ', '') @@ -146,19 +143,40 @@ def _real_extract(self, url): 'preference': self._FORMAT_PREFERENCES.get(ext + '-' + vid_format) or -1, 'format_note': 'DRM-protected video' if ext == 'wvm' else None }) - if not formats: # Most likely because geo-blocked raise ExtractorError('No downloadable videos found', expected=True) - self._sort_formats(formats) + duration = int_or_none(info.get('Duration')) + description = info.get('Description') + created_at = parse_iso8601(info.get('CreationDate') or None) + + thumbnails = [] + for picture in info.get('Pictures', []): + if not isinstance(picture, dict): + continue + pic_url = picture.get('URL') + if not pic_url: + continue + thumbnail = { + 'url': pic_url, + } + pic_size = picture.get('PicSize', '') + m = re.search(r'(?P\d+)[xX](?P\d+)', pic_size) + if m: + thumbnail.update({ + 'width': int(m.group('width')), + 'height': int(m.group('height')), + }) + thumbnails.append(thumbnail) + return { 'id': video_id, 'title': title, 'description': description, 'duration': duration, 'timestamp': created_at, - 'thumbnail': thumbnail, + 'thumbnails': thumbnails, 'formats': formats, }