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.

194 lines
7.1 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. parse_duration,
  7. unified_strdate,
  8. str_to_int,
  9. int_or_none,
  10. float_or_none,
  11. ISO639Utils,
  12. determine_ext,
  13. )
  14. class AdobeTVBaseIE(InfoExtractor):
  15. _API_BASE_URL = 'http://tv.adobe.com/api/v4/'
  16. class AdobeTVIE(AdobeTVBaseIE):
  17. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?watch/(?P<show_urlname>[^/]+)/(?P<id>[^/]+)'
  18. _TEST = {
  19. 'url': 'http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/quick-tip-how-to-draw-a-circle-around-an-object-in-photoshop/',
  20. 'md5': '9bc5727bcdd55251f35ad311ca74fa1e',
  21. 'info_dict': {
  22. 'id': '10981',
  23. 'ext': 'mp4',
  24. 'title': 'Quick Tip - How to Draw a Circle Around an Object in Photoshop',
  25. 'description': 'md5:99ec318dc909d7ba2a1f2b038f7d2311',
  26. 'thumbnail': 're:https?://.*\.jpg$',
  27. 'upload_date': '20110914',
  28. 'duration': 60,
  29. 'view_count': int,
  30. },
  31. }
  32. def _real_extract(self, url):
  33. language, show_urlname, urlname = re.match(self._VALID_URL, url).groups()
  34. if not language:
  35. language = 'en'
  36. video_data = self._download_json(
  37. self._API_BASE_URL + 'episode/get/?language=%s&show_urlname=%s&urlname=%s&disclosure=standard' % (language, show_urlname, urlname),
  38. urlname)['data'][0]
  39. formats = [{
  40. 'url': source['url'],
  41. 'format_id': source.get('quality_level') or source['url'].split('-')[-1].split('.')[0] or None,
  42. 'width': int_or_none(source.get('width')),
  43. 'height': int_or_none(source.get('height')),
  44. 'tbr': int_or_none(source.get('video_data_rate')),
  45. } for source in video_data['videos']]
  46. self._sort_formats(formats)
  47. return {
  48. 'id': compat_str(video_data['id']),
  49. 'title': video_data['title'],
  50. 'description': video_data.get('description'),
  51. 'thumbnail': video_data.get('thumbnail'),
  52. 'upload_date': unified_strdate(video_data.get('start_date')),
  53. 'duration': parse_duration(video_data.get('duration')),
  54. 'view_count': str_to_int(video_data.get('playcount')),
  55. 'formats': formats,
  56. }
  57. class AdobeTVPlaylistBaseIE(AdobeTVBaseIE):
  58. def _parse_page_data(self, page_data):
  59. return [self.url_result(self._get_element_url(element_data)) for element_data in page_data]
  60. def _extract_playlist_entries(self, url, display_id):
  61. page = self._download_json(url, display_id)
  62. entries = self._parse_page_data(page['data'])
  63. for page_num in range(2, page['paging']['pages'] + 1):
  64. entries.extend(self._parse_page_data(
  65. self._download_json(url + '&page=%d' % page_num, display_id)['data']))
  66. return entries
  67. class AdobeTVShowIE(AdobeTVPlaylistBaseIE):
  68. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?show/(?P<id>[^/]+)'
  69. _TEST = {
  70. 'url': 'http://tv.adobe.com/show/the-complete-picture-with-julieanne-kost',
  71. 'info_dict': {
  72. 'id': '36',
  73. 'title': 'The Complete Picture with Julieanne Kost',
  74. 'description': 'md5:fa50867102dcd1aa0ddf2ab039311b27',
  75. },
  76. 'playlist_mincount': 136,
  77. }
  78. def _get_element_url(self, element_data):
  79. return element_data['urls'][0]
  80. def _real_extract(self, url):
  81. language, show_urlname = re.match(self._VALID_URL, url).groups()
  82. if not language:
  83. language = 'en'
  84. query = 'language=%s&show_urlname=%s' % (language, show_urlname)
  85. show_data = self._download_json(self._API_BASE_URL + 'show/get/?%s' % query, show_urlname)['data'][0]
  86. return self.playlist_result(
  87. self._extract_playlist_entries(self._API_BASE_URL + 'episode/?%s' % query, show_urlname),
  88. compat_str(show_data['id']),
  89. show_data['show_name'],
  90. show_data['show_description'])
  91. class AdobeTVChannelIE(AdobeTVPlaylistBaseIE):
  92. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?channel/(?P<id>[^/]+)(?:/(?P<category_urlname>[^/]+))?'
  93. _TEST = {
  94. 'url': 'http://tv.adobe.com/channel/development',
  95. 'info_dict': {
  96. 'id': 'development',
  97. },
  98. 'playlist_mincount': 96,
  99. }
  100. def _get_element_url(self, element_data):
  101. return element_data['url']
  102. def _real_extract(self, url):
  103. language, channel_urlname, category_urlname = re.match(self._VALID_URL, url).groups()
  104. if not language:
  105. language = 'en'
  106. query = 'language=%s&channel_urlname=%s' % (language, channel_urlname)
  107. if category_urlname:
  108. query += '&category_urlname=%s' % category_urlname
  109. return self.playlist_result(
  110. self._extract_playlist_entries(self._API_BASE_URL + 'show/?%s' % query, channel_urlname),
  111. channel_urlname)
  112. class AdobeTVVideoIE(InfoExtractor):
  113. _VALID_URL = r'https?://video\.tv\.adobe\.com/v/(?P<id>\d+)'
  114. _TEST = {
  115. # From https://helpx.adobe.com/acrobat/how-to/new-experience-acrobat-dc.html?set=acrobat--get-started--essential-beginners
  116. 'url': 'https://video.tv.adobe.com/v/2456/',
  117. 'md5': '43662b577c018ad707a63766462b1e87',
  118. 'info_dict': {
  119. 'id': '2456',
  120. 'ext': 'mp4',
  121. 'title': 'New experience with Acrobat DC',
  122. 'description': 'New experience with Acrobat DC',
  123. 'duration': 248.667,
  124. },
  125. }
  126. def _real_extract(self, url):
  127. video_id = self._match_id(url)
  128. video_data = self._download_json(url + '?format=json', video_id)
  129. formats = [{
  130. 'format_id': '%s-%s' % (determine_ext(source['src']), source.get('height')),
  131. 'url': source['src'],
  132. 'width': int_or_none(source.get('width')),
  133. 'height': int_or_none(source.get('height')),
  134. 'tbr': int_or_none(source.get('bitrate')),
  135. } for source in video_data['sources']]
  136. self._sort_formats(formats)
  137. # For both metadata and downloaded files the duration varies among
  138. # formats. I just pick the max one
  139. duration = max(filter(None, [
  140. float_or_none(source.get('duration'), scale=1000)
  141. for source in video_data['sources']]))
  142. subtitles = {}
  143. for translation in video_data.get('translations', []):
  144. lang_id = translation.get('language_w3c') or ISO639Utils.long2short(translation['language_medium'])
  145. if lang_id not in subtitles:
  146. subtitles[lang_id] = []
  147. subtitles[lang_id].append({
  148. 'url': translation['vttPath'],
  149. 'ext': 'vtt',
  150. })
  151. return {
  152. 'id': video_id,
  153. 'formats': formats,
  154. 'title': video_data['title'],
  155. 'description': video_data.get('description'),
  156. 'thumbnail': video_data['video'].get('poster'),
  157. 'duration': duration,
  158. 'subtitles': subtitles,
  159. }