logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

archiveorg.py (3712B)


  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. clean_html,
  5. extract_attributes,
  6. unified_strdate,
  7. unified_timestamp,
  8. )
  9. class ArchiveOrgIE(InfoExtractor):
  10. IE_NAME = 'archive.org'
  11. IE_DESC = 'archive.org videos'
  12. _VALID_URL = r'https?://(?:www\.)?archive\.org/(?:details|embed)/(?P<id>[^/?#&]+)'
  13. _TESTS = [{
  14. 'url': 'http://archive.org/details/XD300-23_68HighlightsAResearchCntAugHumanIntellect',
  15. 'md5': '8af1d4cf447933ed3c7f4871162602db',
  16. 'info_dict': {
  17. 'id': 'XD300-23_68HighlightsAResearchCntAugHumanIntellect',
  18. 'ext': 'ogg',
  19. 'title': '1968 Demo - FJCC Conference Presentation Reel #1',
  20. 'description': 'md5:da45c349df039f1cc8075268eb1b5c25',
  21. 'creator': 'SRI International',
  22. 'release_date': '19681210',
  23. 'uploader': 'SRI International',
  24. 'timestamp': 1268695290,
  25. 'upload_date': '20100315',
  26. }
  27. }, {
  28. 'url': 'https://archive.org/details/Cops1922',
  29. 'md5': '0869000b4ce265e8ca62738b336b268a',
  30. 'info_dict': {
  31. 'id': 'Cops1922',
  32. 'ext': 'mp4',
  33. 'title': 'Buster Keaton\'s "Cops" (1922)',
  34. 'description': 'md5:43a603fd6c5b4b90d12a96b921212b9c',
  35. 'timestamp': 1387699629,
  36. 'upload_date': '20131222',
  37. }
  38. }, {
  39. 'url': 'http://archive.org/embed/XD300-23_68HighlightsAResearchCntAugHumanIntellect',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'https://archive.org/details/MSNBCW_20131125_040000_To_Catch_a_Predator/',
  43. 'only_matching': True,
  44. }]
  45. def _real_extract(self, url):
  46. video_id = self._match_id(url)
  47. webpage = self._download_webpage(
  48. 'http://archive.org/embed/' + video_id, video_id)
  49. playlist = None
  50. play8 = self._search_regex(
  51. r'(<[^>]+\bclass=["\']js-play8-playlist[^>]+>)', webpage,
  52. 'playlist', default=None)
  53. if play8:
  54. attrs = extract_attributes(play8)
  55. playlist = attrs.get('value')
  56. if not playlist:
  57. # Old jwplayer fallback
  58. playlist = self._search_regex(
  59. r"(?s)Play\('[^']+'\s*,\s*(\[.+\])\s*,\s*{.*?}\)",
  60. webpage, 'jwplayer playlist', default='[]')
  61. jwplayer_playlist = self._parse_json(playlist, video_id, fatal=False)
  62. if jwplayer_playlist:
  63. info = self._parse_jwplayer_data(
  64. {'playlist': jwplayer_playlist}, video_id, base_url=url)
  65. else:
  66. # HTML5 media fallback
  67. info = self._parse_html5_media_entries(url, webpage, video_id)[0]
  68. info['id'] = video_id
  69. def get_optional(metadata, field):
  70. return metadata.get(field, [None])[0]
  71. metadata = self._download_json(
  72. 'http://archive.org/details/' + video_id, video_id, query={
  73. 'output': 'json',
  74. })['metadata']
  75. info.update({
  76. 'title': get_optional(metadata, 'title') or info.get('title'),
  77. 'description': clean_html(get_optional(metadata, 'description')),
  78. })
  79. if info.get('_type') != 'playlist':
  80. creator = get_optional(metadata, 'creator')
  81. info.update({
  82. 'creator': creator,
  83. 'release_date': unified_strdate(get_optional(metadata, 'date')),
  84. 'uploader': get_optional(metadata, 'publisher') or creator,
  85. 'timestamp': unified_timestamp(get_optional(metadata, 'publicdate')),
  86. 'language': get_optional(metadata, 'language'),
  87. })
  88. return info