Skip to content

Commit

Permalink
[archiveorg] most metadata fields are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
derrotebaron committed Dec 28, 2014
1 parent 5a18403 commit ff7a07d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions youtube_dl/extractor/archiveorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -33,10 +39,12 @@ def _real_extract(self, url):
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 = [
{
Expand Down

0 comments on commit ff7a07d

Please sign in to comment.