2014-01-07 18:04:48 +09:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2017-02-17 00:42:36 +09:00
|
|
|
from .common import InfoExtractor
|
2016-08-06 00:40:21 +09:00
|
|
|
from ..utils import (
|
|
|
|
clean_html,
|
2021-02-07 22:34:41 +09:00
|
|
|
extract_attributes,
|
|
|
|
unified_strdate,
|
|
|
|
unified_timestamp,
|
2016-08-06 00:40:21 +09:00
|
|
|
)
|
2013-07-08 09:04:11 +09:00
|
|
|
|
|
|
|
|
2017-02-17 00:42:36 +09:00
|
|
|
class ArchiveOrgIE(InfoExtractor):
|
2013-07-08 09:04:11 +09:00
|
|
|
IE_NAME = 'archive.org'
|
|
|
|
IE_DESC = 'archive.org videos'
|
2021-02-07 22:34:41 +09:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?archive\.org/(?:details|embed)/(?P<id>[^/?#&]+)'
|
2014-12-29 05:08:46 +09:00
|
|
|
_TESTS = [{
|
|
|
|
'url': 'http://archive.org/details/XD300-23_68HighlightsAResearchCntAugHumanIntellect',
|
2014-01-07 18:04:48 +09:00
|
|
|
'md5': '8af1d4cf447933ed3c7f4871162602db',
|
|
|
|
'info_dict': {
|
2014-12-29 05:08:46 +09:00
|
|
|
'id': 'XD300-23_68HighlightsAResearchCntAugHumanIntellect',
|
2016-08-06 00:40:21 +09:00
|
|
|
'ext': 'ogg',
|
2014-12-29 05:08:46 +09:00
|
|
|
'title': '1968 Demo - FJCC Conference Presentation Reel #1',
|
2016-08-06 00:40:21 +09:00
|
|
|
'description': 'md5:da45c349df039f1cc8075268eb1b5c25',
|
2021-02-07 22:34:41 +09:00
|
|
|
'creator': 'SRI International',
|
|
|
|
'release_date': '19681210',
|
|
|
|
'uploader': 'SRI International',
|
|
|
|
'timestamp': 1268695290,
|
|
|
|
'upload_date': '20100315',
|
2013-07-08 09:04:11 +09:00
|
|
|
}
|
2014-12-29 05:08:46 +09:00
|
|
|
}, {
|
|
|
|
'url': 'https://archive.org/details/Cops1922',
|
2017-04-28 05:48:32 +09:00
|
|
|
'md5': '0869000b4ce265e8ca62738b336b268a',
|
2014-12-29 05:08:46 +09:00
|
|
|
'info_dict': {
|
|
|
|
'id': 'Cops1922',
|
2016-08-06 00:40:21 +09:00
|
|
|
'ext': 'mp4',
|
2014-12-29 05:08:46 +09:00
|
|
|
'title': 'Buster Keaton\'s "Cops" (1922)',
|
2021-02-07 22:34:41 +09:00
|
|
|
'description': 'md5:43a603fd6c5b4b90d12a96b921212b9c',
|
|
|
|
'timestamp': 1387699629,
|
|
|
|
'upload_date': '20131222',
|
2014-12-29 05:08:46 +09:00
|
|
|
}
|
2016-08-06 00:40:21 +09:00
|
|
|
}, {
|
|
|
|
'url': 'http://archive.org/embed/XD300-23_68HighlightsAResearchCntAugHumanIntellect',
|
|
|
|
'only_matching': True,
|
2021-02-07 22:34:41 +09:00
|
|
|
}, {
|
|
|
|
'url': 'https://archive.org/details/MSNBCW_20131125_040000_To_Catch_a_Predator/',
|
|
|
|
'only_matching': True,
|
2014-12-29 05:08:46 +09:00
|
|
|
}]
|
2014-12-29 04:04:21 +09:00
|
|
|
|
2013-07-08 09:04:11 +09:00
|
|
|
def _real_extract(self, url):
|
2014-12-29 05:08:46 +09:00
|
|
|
video_id = self._match_id(url)
|
2016-08-06 00:40:21 +09:00
|
|
|
webpage = self._download_webpage(
|
|
|
|
'http://archive.org/embed/' + video_id, video_id)
|
2021-02-07 22:34:41 +09:00
|
|
|
|
|
|
|
playlist = None
|
|
|
|
play8 = self._search_regex(
|
|
|
|
r'(<[^>]+\bclass=["\']js-play8-playlist[^>]+>)', webpage,
|
|
|
|
'playlist', default=None)
|
|
|
|
if play8:
|
|
|
|
attrs = extract_attributes(play8)
|
|
|
|
playlist = attrs.get('value')
|
|
|
|
if not playlist:
|
|
|
|
# Old jwplayer fallback
|
|
|
|
playlist = self._search_regex(
|
|
|
|
r"(?s)Play\('[^']+'\s*,\s*(\[.+\])\s*,\s*{.*?}\)",
|
|
|
|
webpage, 'jwplayer playlist', default='[]')
|
|
|
|
jwplayer_playlist = self._parse_json(playlist, video_id, fatal=False)
|
|
|
|
if jwplayer_playlist:
|
|
|
|
info = self._parse_jwplayer_data(
|
|
|
|
{'playlist': jwplayer_playlist}, video_id, base_url=url)
|
|
|
|
else:
|
|
|
|
# HTML5 media fallback
|
|
|
|
info = self._parse_html5_media_entries(url, webpage, video_id)[0]
|
|
|
|
info['id'] = video_id
|
2013-07-08 09:04:11 +09:00
|
|
|
|
2016-08-06 00:40:21 +09:00
|
|
|
def get_optional(metadata, field):
|
|
|
|
return metadata.get(field, [None])[0]
|
2013-07-08 09:04:11 +09:00
|
|
|
|
2016-08-06 00:40:21 +09:00
|
|
|
metadata = self._download_json(
|
|
|
|
'http://archive.org/details/' + video_id, video_id, query={
|
|
|
|
'output': 'json',
|
|
|
|
})['metadata']
|
|
|
|
info.update({
|
|
|
|
'title': get_optional(metadata, 'title') or info.get('title'),
|
|
|
|
'description': clean_html(get_optional(metadata, 'description')),
|
|
|
|
})
|
|
|
|
if info.get('_type') != 'playlist':
|
2021-02-07 22:34:41 +09:00
|
|
|
creator = get_optional(metadata, 'creator')
|
2016-08-06 00:40:21 +09:00
|
|
|
info.update({
|
2021-02-07 22:34:41 +09:00
|
|
|
'creator': creator,
|
|
|
|
'release_date': unified_strdate(get_optional(metadata, 'date')),
|
|
|
|
'uploader': get_optional(metadata, 'publisher') or creator,
|
|
|
|
'timestamp': unified_timestamp(get_optional(metadata, 'publicdate')),
|
|
|
|
'language': get_optional(metadata, 'language'),
|
2016-08-06 00:40:21 +09:00
|
|
|
})
|
2016-08-06 01:16:19 +09:00
|
|
|
return info
|