You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. from .jwplatform import JWPlatformBaseIE
  3. from ..utils import (
  4. unified_strdate,
  5. clean_html,
  6. )
  7. class ArchiveOrgIE(JWPlatformBaseIE):
  8. IE_NAME = 'archive.org'
  9. IE_DESC = 'archive.org videos'
  10. _VALID_URL = r'https?://(?:www\.)?archive\.org/(?:details|embed)/(?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': 'ogg',
  17. 'title': '1968 Demo - FJCC Conference Presentation Reel #1',
  18. 'description': 'md5:da45c349df039f1cc8075268eb1b5c25',
  19. 'upload_date': '19681210',
  20. 'uploader': 'SRI International'
  21. }
  22. }, {
  23. 'url': 'https://archive.org/details/Cops1922',
  24. 'md5': 'bc73c8ab3838b5a8fc6c6651fa7b58ba',
  25. 'info_dict': {
  26. 'id': 'Cops1922',
  27. 'ext': 'mp4',
  28. 'title': 'Buster Keaton\'s "Cops" (1922)',
  29. 'description': 'md5:b4544662605877edd99df22f9620d858',
  30. }
  31. }, {
  32. 'url': 'http://archive.org/embed/XD300-23_68HighlightsAResearchCntAugHumanIntellect',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. webpage = self._download_webpage(
  38. 'http://archive.org/embed/' + video_id, video_id)
  39. jwplayer_playlist = self._parse_json(self._search_regex(
  40. r"(?s)Play\('[^']+'\s*,\s*(\[.+\])\s*,\s*{.*?}\);",
  41. webpage, 'jwplayer playlist'), video_id)
  42. info = self._parse_jwplayer_data(
  43. {'playlist': jwplayer_playlist}, video_id, base_url=url)
  44. def get_optional(metadata, field):
  45. return metadata.get(field, [None])[0]
  46. metadata = self._download_json(
  47. 'http://archive.org/details/' + video_id, video_id, query={
  48. 'output': 'json',
  49. })['metadata']
  50. info.update({
  51. 'title': get_optional(metadata, 'title') or info.get('title'),
  52. 'description': clean_html(get_optional(metadata, 'description')),
  53. })
  54. if info.get('_type') != 'playlist':
  55. info.update({
  56. 'uploader': get_optional(metadata, 'creator'),
  57. 'upload_date': unified_strdate(get_optional(metadata, 'date')),
  58. })
  59. return info