瀏覽代碼

YoutubeIE: extract the thumbnail in the best possible quality

Jaime Marquínez Ferrándiz 12 年之前
父節點
當前提交
7763b04e5f
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      youtube_dl/extractor/youtube.py

+ 6 - 1
youtube_dl/extractor/youtube.py

@@ -473,7 +473,12 @@ class YoutubeIE(InfoExtractor):
         video_title = compat_urllib_parse.unquote_plus(video_info['title'][0])
         video_title = compat_urllib_parse.unquote_plus(video_info['title'][0])
 
 
         # thumbnail image
         # thumbnail image
-        if 'thumbnail_url' not in video_info:
+        # We try first to get a high quality image:
+        m_thumb = re.search(r'<span itemprop="thumbnail".*?href="(.*?)">',
+                            video_webpage, re.DOTALL)
+        if m_thumb is not None:
+            video_thumbnail = m_thumb.group(1)
+        elif 'thumbnail_url' not in video_info:
             self._downloader.report_warning(u'unable to extract video thumbnail')
             self._downloader.report_warning(u'unable to extract video thumbnail')
             video_thumbnail = ''
             video_thumbnail = ''
         else:   # don't panic if we can't find it
         else:   # don't panic if we can't find it