Skip to content

Commit

Permalink
[cnn] Improve thumbnail extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
phihag committed Jun 7, 2014
1 parent d551980 commit be6d722
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ def process_video_result(self, info_dict, download=True):

thumbnails = info_dict.get('thumbnails')
if thumbnails:
thumbnails.sort(key=lambda t: (
t.get('width'), t.get('height'), t.get('url')))
for t in thumbnails:
if 'width' in t and 'height' in t:
t['resolution'] = '%dx%d' % (t['width'], t['height'])
Expand Down
10 changes: 6 additions & 4 deletions youtube_dl/extractor/cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ def _real_extract(self, url):

self._sort_formats(formats)

thumbnails = sorted([((int(t.attrib['height']),int(t.attrib['width'])), t.text) for t in info.findall('images/image')])
thumbs_dict = [{'resolution': res, 'url': t_url} for (res, t_url) in thumbnails]
thumbnails = [{
'height': int(t.attrib['height']),
'width': int(t.attrib['width']),
'url': t.text,
} for t in info.findall('images/image')]

metas_el = info.find('metas')
upload_date = (
Expand All @@ -93,8 +96,7 @@ def _real_extract(self, url):
'id': info.attrib['id'],
'title': info.find('headline').text,
'formats': formats,
'thumbnail': thumbnails[-1][1],
'thumbnails': thumbs_dict,
'thumbnails': thumbnails,
'description': info.find('description').text,
'duration': duration,
'upload_date': upload_date,
Expand Down

0 comments on commit be6d722

Please sign in to comment.