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.

67 lines
2.3 KiB

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