]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/archiveorg.py
debian/changelog: Initiate a new release.
[youtubedl] / youtube_dl / extractor / archiveorg.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import unified_strdate
5
6
7 class ArchiveOrgIE(InfoExtractor):
8 IE_NAME = 'archive.org'
9 IE_DESC = 'archive.org videos'
10 _VALID_URL = r'https?://(?:www\.)?archive\.org/details/(?P<id>[^?/]+)(?:[?].*)?$'
11 _TESTS = [{
12 'url': 'http://archive.org/details/XD300-23_68HighlightsAResearchCntAugHumanIntellect',
13 'md5': '8af1d4cf447933ed3c7f4871162602db',
14 'info_dict': {
15 'id': 'XD300-23_68HighlightsAResearchCntAugHumanIntellect',
16 'ext': 'ogv',
17 'title': '1968 Demo - FJCC Conference Presentation Reel #1',
18 'description': 'md5:1780b464abaca9991d8968c877bb53ed',
19 'upload_date': '19681210',
20 'uploader': 'SRI International'
21 }
22 }, {
23 'url': 'https://archive.org/details/Cops1922',
24 'md5': '18f2a19e6d89af8425671da1cf3d4e04',
25 'info_dict': {
26 'id': 'Cops1922',
27 'ext': 'ogv',
28 'title': 'Buster Keaton\'s "Cops" (1922)',
29 'description': 'md5:70f72ee70882f713d4578725461ffcc3',
30 }
31 }]
32
33 def _real_extract(self, url):
34 video_id = self._match_id(url)
35
36 json_url = url + ('&' if '?' in url else '?') + 'output=json'
37 data = self._download_json(json_url, video_id)
38
39 def get_optional(data_dict, field):
40 return data_dict['metadata'].get(field, [None])[0]
41
42 title = get_optional(data, 'title')
43 description = get_optional(data, 'description')
44 uploader = get_optional(data, 'creator')
45 upload_date = unified_strdate(get_optional(data, 'date'))
46
47 formats = [
48 {
49 'format': fdata['format'],
50 'url': 'http://' + data['server'] + data['dir'] + fn,
51 'file_size': int(fdata['size']),
52 }
53 for fn, fdata in data['files'].items()
54 if 'Video' in fdata['format']]
55
56 self._sort_formats(formats)
57
58 return {
59 '_type': 'video',
60 'id': video_id,
61 'title': title,
62 'formats': formats,
63 'description': description,
64 'uploader': uploader,
65 'upload_date': upload_date,
66 'thumbnail': data.get('misc', {}).get('image'),
67 }