logo

youtube-dl

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

amara.py (3583B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .youtube import YoutubeIE
  5. from .vimeo import VimeoIE
  6. from ..utils import (
  7. int_or_none,
  8. parse_iso8601,
  9. update_url_query,
  10. )
  11. class AmaraIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?amara\.org/(?:\w+/)?videos/(?P<id>\w+)'
  13. _TESTS = [{
  14. # Youtube
  15. 'url': 'https://amara.org/en/videos/jVx79ZKGK1ky/info/why-jury-trials-are-becoming-less-common/?tab=video',
  16. 'md5': 'ea10daf2b6154b8c1ecf9922aca5e8ae',
  17. 'info_dict': {
  18. 'id': 'h6ZuVdvYnfE',
  19. 'ext': 'mp4',
  20. 'title': 'Why jury trials are becoming less common',
  21. 'description': 'md5:a61811c319943960b6ab1c23e0cbc2c1',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'subtitles': dict,
  24. 'upload_date': '20160813',
  25. 'uploader': 'PBS NewsHour',
  26. 'uploader_id': 'PBSNewsHour',
  27. 'timestamp': 1549639570,
  28. }
  29. }, {
  30. # Vimeo
  31. 'url': 'https://amara.org/en/videos/kYkK1VUTWW5I/info/vimeo-at-ces-2011',
  32. 'md5': '99392c75fa05d432a8f11df03612195e',
  33. 'info_dict': {
  34. 'id': '18622084',
  35. 'ext': 'mov',
  36. 'title': 'Vimeo at CES 2011!',
  37. 'description': 'md5:d41d8cd98f00b204e9800998ecf8427e',
  38. 'thumbnail': r're:^https?://.*\.jpg$',
  39. 'subtitles': dict,
  40. 'timestamp': 1294763658,
  41. 'upload_date': '20110111',
  42. 'uploader': 'Sam Morrill',
  43. 'uploader_id': 'sammorrill'
  44. }
  45. }, {
  46. # Direct Link
  47. 'url': 'https://amara.org/en/videos/s8KL7I3jLmh6/info/the-danger-of-a-single-story/',
  48. 'md5': 'd3970f08512738ee60c5807311ff5d3f',
  49. 'info_dict': {
  50. 'id': 's8KL7I3jLmh6',
  51. 'ext': 'mp4',
  52. 'title': 'The danger of a single story',
  53. 'description': 'md5:d769b31139c3b8bb5be9177f62ea3f23',
  54. 'thumbnail': r're:^https?://.*\.jpg$',
  55. 'subtitles': dict,
  56. 'upload_date': '20091007',
  57. 'timestamp': 1254942511,
  58. }
  59. }]
  60. def _real_extract(self, url):
  61. video_id = self._match_id(url)
  62. meta = self._download_json(
  63. 'https://amara.org/api/videos/%s/' % video_id,
  64. video_id, query={'format': 'json'})
  65. title = meta['title']
  66. video_url = meta['all_urls'][0]
  67. subtitles = {}
  68. for language in (meta.get('languages') or []):
  69. subtitles_uri = language.get('subtitles_uri')
  70. if not (subtitles_uri and language.get('published')):
  71. continue
  72. subtitle = subtitles.setdefault(language.get('code') or 'en', [])
  73. for f in ('json', 'srt', 'vtt'):
  74. subtitle.append({
  75. 'ext': f,
  76. 'url': update_url_query(subtitles_uri, {'format': f}),
  77. })
  78. info = {
  79. 'url': video_url,
  80. 'id': video_id,
  81. 'subtitles': subtitles,
  82. 'title': title,
  83. 'description': meta.get('description'),
  84. 'thumbnail': meta.get('thumbnail'),
  85. 'duration': int_or_none(meta.get('duration')),
  86. 'timestamp': parse_iso8601(meta.get('created')),
  87. }
  88. for ie in (YoutubeIE, VimeoIE):
  89. if ie.suitable(video_url):
  90. info.update({
  91. '_type': 'url_transparent',
  92. 'ie_key': ie.ie_key(),
  93. })
  94. break
  95. return info