瀏覽代碼

[YouTubeDL] Throw an early error if the info_dict result is invalid

Philipp Hagemeister 11 年之前
父節點
當前提交
bec1fad223
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      youtube_dl/YoutubeDL.py

+ 8 - 0
youtube_dl/YoutubeDL.py

@@ -702,6 +702,11 @@ class YoutubeDL(object):
     def process_video_result(self, info_dict, download=True):
     def process_video_result(self, info_dict, download=True):
         assert info_dict.get('_type', 'video') == 'video'
         assert info_dict.get('_type', 'video') == 'video'
 
 
+        if 'id' not in info_dict:
+            raise ExtractorError('Missing "id" field in extractor result')
+        if 'title' not in info_dict:
+            raise ExtractorError('Missing "title" field in extractor result')
+
         if 'playlist' not in info_dict:
         if 'playlist' not in info_dict:
             # It isn't part of a playlist
             # It isn't part of a playlist
             info_dict['playlist'] = None
             info_dict['playlist'] = None
@@ -733,6 +738,9 @@ class YoutubeDL(object):
 
 
         # We check that all the formats have the format and format_id fields
         # We check that all the formats have the format and format_id fields
         for i, format in enumerate(formats):
         for i, format in enumerate(formats):
+            if 'url' not in format:
+                raise ExtractorError('Missing "url" key in result (index %d)' % i)
+
             if format.get('format_id') is None:
             if format.get('format_id') is None:
                 format['format_id'] = compat_str(i)
                 format['format_id'] = compat_str(i)
             if format.get('format') is None:
             if format.get('format') is None: