+ 'http://archive.org/metadata/' + identifier, identifier)
+ m = metadata['metadata']
+ identifier = m['identifier']
+
+ info = {
+ 'id': identifier,
+ 'title': m['title'],
+ 'description': clean_html(m.get('description')),
+ 'uploader': dict_get(m, ['uploader', 'adder']),
+ 'creator': m.get('creator'),
+ 'license': m.get('licenseurl'),
+ 'release_date': unified_strdate(m.get('date')),
+ 'timestamp': unified_timestamp(dict_get(m, ['publicdate', 'addeddate'])),
+ 'webpage_url': 'https://archive.org/details/' + identifier,
+ 'location': m.get('venue'),
+ 'release_year': int_or_none(m.get('year'))}
+
+ for f in metadata['files']:
+ if f['name'] in entries:
+ entries[f['name']] = merge_dicts(entries[f['name']], {
+ 'id': identifier + '/' + f['name'],
+ 'title': f.get('title') or f['name'],
+ 'display_id': f['name'],
+ 'description': clean_html(f.get('description')),
+ 'creator': f.get('creator'),
+ 'duration': parse_duration(f.get('length')),
+ 'track_number': int_or_none(f.get('track')),
+ 'album': f.get('album'),
+ 'discnumber': int_or_none(f.get('disc')),
+ 'release_year': int_or_none(f.get('year'))})
+ entry = entries[f['name']]
+ elif f.get('original') in entries:
+ entry = entries[f['original']]
+ else:
+ continue
+
+ if f.get('format') == 'Thumbnail':
+ entry['thumbnails'].append({
+ 'id': f['name'],
+ 'url': 'https://archive.org/download/' + identifier + '/' + f['name'],
+ 'width': int_or_none(f.get('width')),
+ 'height': int_or_none(f.get('width')),
+ 'filesize': int_or_none(f.get('size'))})
+
+ extension = (f['name'].rsplit('.', 1) + [None])[1]
+ if extension in KNOWN_EXTENSIONS:
+ entry['formats'].append({
+ 'url': 'https://archive.org/download/' + identifier + '/' + f['name'],
+ 'format': f.get('format'),
+ 'width': int_or_none(f.get('width')),
+ 'height': int_or_none(f.get('height')),
+ 'filesize': int_or_none(f.get('size')),
+ 'protocol': 'https'})
+
+ # Sort available formats by filesize
+ for entry in entries.values():
+ entry['formats'] = list(sorted(entry['formats'], key=lambda x: x.get('filesize', -1)))
+
+ if len(entries) == 1:
+ # If there's only one item, use it as the main info dict
+ only_video = entries[list(entries.keys())[0]]
+ if entry_id:
+ info = merge_dicts(only_video, info)
+ else:
+ info = merge_dicts(info, only_video)
+ else:
+ # Otherwise, we have a playlist.
+ info['_type'] = 'playlist'
+ info['entries'] = list(entries.values())
+
+ if metadata.get('reviews'):
+ info['comments'] = []
+ for review in metadata['reviews']:
+ info['comments'].append({
+ 'id': review.get('review_id'),
+ 'author': review.get('reviewer'),
+ 'text': str_or_none(review.get('reviewtitle'), '') + '\n\n' + review.get('reviewbody'),
+ 'timestamp': unified_timestamp(review.get('createdate')),
+ 'parent': 'root'})
+