nowness.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. from .brightcove import (
  2. BrightcoveLegacyIE,
  3. BrightcoveNewIE,
  4. )
  5. from .common import InfoExtractor
  6. from ..networking import Request
  7. from ..utils import ExtractorError
  8. class NownessBaseIE(InfoExtractor):
  9. def _extract_url_result(self, post):
  10. if post['type'] == 'video':
  11. for media in post['media']:
  12. if media['type'] == 'video':
  13. video_id = media['content']
  14. source = media['source']
  15. if source == 'brightcove':
  16. player_code = self._download_webpage(
  17. f'http://www.nowness.com/iframe?id={video_id}', video_id,
  18. note='Downloading player JavaScript',
  19. errnote='Unable to download player JavaScript')
  20. bc_url = BrightcoveLegacyIE._extract_brightcove_url(player_code)
  21. if bc_url:
  22. return self.url_result(bc_url, BrightcoveLegacyIE.ie_key())
  23. bc_url = BrightcoveNewIE._extract_url(self, player_code)
  24. if bc_url:
  25. return self.url_result(bc_url, BrightcoveNewIE.ie_key())
  26. raise ExtractorError('Could not find player definition')
  27. elif source == 'vimeo':
  28. return self.url_result(f'http://vimeo.com/{video_id}', 'Vimeo')
  29. elif source == 'youtube':
  30. return self.url_result(video_id, 'Youtube')
  31. elif source == 'cinematique':
  32. # yt-dlp currently doesn't support cinematique
  33. # return self.url_result('http://cinematique.com/embed/%s' % video_id, 'Cinematique')
  34. pass
  35. def _api_request(self, url, request_path):
  36. display_id = self._match_id(url)
  37. request = Request(
  38. 'http://api.nowness.com/api/' + request_path % display_id,
  39. headers={
  40. 'X-Nowness-Language': 'zh-cn' if 'cn.nowness.com' in url else 'en-us',
  41. })
  42. return display_id, self._download_json(request, display_id)
  43. class NownessIE(NownessBaseIE):
  44. IE_NAME = 'nowness'
  45. _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/(?:story|(?:series|category)/[^/]+)/(?P<id>[^/]+?)(?:$|[?#])'
  46. _TESTS = [{
  47. 'url': 'https://www.nowness.com/story/candor-the-art-of-gesticulation',
  48. 'md5': '068bc0202558c2e391924cb8cc470676',
  49. 'info_dict': {
  50. 'id': '2520295746001',
  51. 'ext': 'mp4',
  52. 'title': 'Candor: The Art of Gesticulation',
  53. 'description': 'Candor: The Art of Gesticulation',
  54. 'thumbnail': r're:^https?://.*\.jpg',
  55. 'timestamp': 1446745676,
  56. 'upload_date': '20151105',
  57. 'uploader_id': '2385340575001',
  58. },
  59. 'add_ie': ['BrightcoveNew'],
  60. }, {
  61. 'url': 'https://cn.nowness.com/story/kasper-bjorke-ft-jaakko-eino-kalevi-tnr',
  62. 'md5': 'e79cf125e387216f86b2e0a5b5c63aa3',
  63. 'info_dict': {
  64. 'id': '3716354522001',
  65. 'ext': 'mp4',
  66. 'title': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
  67. 'description': 'Kasper Bjørke ft. Jaakko Eino Kalevi: TNR',
  68. 'thumbnail': r're:^https?://.*\.jpg',
  69. 'timestamp': 1407315371,
  70. 'upload_date': '20140806',
  71. 'uploader_id': '2385340575001',
  72. },
  73. 'add_ie': ['BrightcoveNew'],
  74. }, {
  75. # vimeo
  76. 'url': 'https://www.nowness.com/series/nowness-picks/jean-luc-godard-supercut',
  77. 'md5': '9a5a6a8edf806407e411296ab6bc2a49',
  78. 'info_dict': {
  79. 'id': '130020913',
  80. 'ext': 'mp4',
  81. 'title': 'Bleu, Blanc, Rouge - A Godard Supercut',
  82. 'description': 'md5:f0ea5f1857dffca02dbd37875d742cec',
  83. 'thumbnail': r're:^https?://.*\.jpg',
  84. 'upload_date': '20150607',
  85. 'uploader': 'Cinema Sem Lei',
  86. 'uploader_id': 'cinemasemlei',
  87. },
  88. 'add_ie': ['Vimeo'],
  89. }]
  90. def _real_extract(self, url):
  91. _, post = self._api_request(url, 'post/getBySlug/%s')
  92. return self._extract_url_result(post)
  93. class NownessPlaylistIE(NownessBaseIE):
  94. IE_NAME = 'nowness:playlist'
  95. _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/playlist/(?P<id>\d+)'
  96. _TEST = {
  97. 'url': 'https://www.nowness.com/playlist/3286/i-guess-thats-why-they-call-it-the-blues',
  98. 'info_dict': {
  99. 'id': '3286',
  100. },
  101. 'playlist_mincount': 8,
  102. }
  103. def _real_extract(self, url):
  104. playlist_id, playlist = self._api_request(url, 'post?PlaylistId=%s')
  105. entries = [self._extract_url_result(item) for item in playlist['items']]
  106. return self.playlist_result(entries, playlist_id)
  107. class NownessSeriesIE(NownessBaseIE):
  108. IE_NAME = 'nowness:series'
  109. _VALID_URL = r'https?://(?:(?:www|cn)\.)?nowness\.com/series/(?P<id>[^/]+?)(?:$|[?#])'
  110. _TEST = {
  111. 'url': 'https://www.nowness.com/series/60-seconds',
  112. 'info_dict': {
  113. 'id': '60',
  114. 'title': '60 Seconds',
  115. 'description': 'One-minute wisdom in a new NOWNESS series',
  116. },
  117. 'playlist_mincount': 4,
  118. }
  119. def _real_extract(self, url):
  120. display_id, series = self._api_request(url, 'series/getBySlug/%s')
  121. entries = [self._extract_url_result(post) for post in series['posts']]
  122. series_title = None
  123. series_description = None
  124. translations = series.get('translations', [])
  125. if translations:
  126. series_title = translations[0].get('title') or translations[0]['seoTitle']
  127. series_description = translations[0].get('seoDescription')
  128. return self.playlist_result(
  129. entries, str(series['id']), series_title, series_description)