]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[archiveorg] most metadata fields are optional
authorJohannes Knoedtel <johannes@dev-baron.de>
Sun, 28 Dec 2014 19:04:21 +0000 (20:04 +0100)
committerJohannes Knoedtel <johannes@dev-baron.de>
Sun, 28 Dec 2014 19:31:25 +0000 (20:31 +0100)
Example: https://archive.org/details/Cops1922

youtube_dl/extractor/archiveorg.py

index 34ce8429b121261784a1645c28e2a33cb76bcacb..ba94b54547122a37e9054cf703d5c2e7cce71eb9 100644 (file)
@@ -25,6 +25,12 @@ class ArchiveOrgIE(InfoExtractor):
         }
     }
 
+    def get_optional_metadata(self, data, field):
+        try:
+            return data['metadata'][field][0]
+        except KeyError:
+            return None
+
     def _real_extract(self, url):
         mobj = re.match(self._VALID_URL, url)
         video_id = mobj.group('id')
@@ -33,10 +39,12 @@ class ArchiveOrgIE(InfoExtractor):
         json_data = self._download_webpage(json_url, video_id)
         data = json.loads(json_data)
 
-        title = data['metadata']['title'][0]
-        description = data['metadata']['description'][0]
-        uploader = data['metadata']['creator'][0]
-        upload_date = unified_strdate(data['metadata']['date'][0])
+        title = self.get_optional_metadata(data, 'title')
+        description = self.get_optional_metadata(data, 'description')
+        uploader = self.get_optional_metadata(data, 'creator')
+        upload_date = self.get_optional_metadata(data, 'date')
+        if upload_date:
+            upload_date = unified_strdate(upload_date)
 
         formats = [
             {