adobetv.py 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import functools
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ISO639Utils,
  6. OnDemandPagedList,
  7. float_or_none,
  8. int_or_none,
  9. join_nonempty,
  10. parse_duration,
  11. str_or_none,
  12. str_to_int,
  13. unified_strdate,
  14. )
  15. class AdobeTVBaseIE(InfoExtractor):
  16. def _call_api(self, path, video_id, query, note=None):
  17. return self._download_json(
  18. 'http://tv.adobe.com/api/v4/' + path,
  19. video_id, note, query=query)['data']
  20. def _parse_subtitles(self, video_data, url_key):
  21. subtitles = {}
  22. for translation in video_data.get('translations', []):
  23. vtt_path = translation.get(url_key)
  24. if not vtt_path:
  25. continue
  26. lang = translation.get('language_w3c') or ISO639Utils.long2short(translation['language_medium'])
  27. subtitles.setdefault(lang, []).append({
  28. 'ext': 'vtt',
  29. 'url': vtt_path,
  30. })
  31. return subtitles
  32. def _parse_video_data(self, video_data):
  33. video_id = str(video_data['id'])
  34. title = video_data['title']
  35. s3_extracted = False
  36. formats = []
  37. for source in video_data.get('videos', []):
  38. source_url = source.get('url')
  39. if not source_url:
  40. continue
  41. f = {
  42. 'format_id': source.get('quality_level'),
  43. 'fps': int_or_none(source.get('frame_rate')),
  44. 'height': int_or_none(source.get('height')),
  45. 'tbr': int_or_none(source.get('video_data_rate')),
  46. 'width': int_or_none(source.get('width')),
  47. 'url': source_url,
  48. }
  49. original_filename = source.get('original_filename')
  50. if original_filename:
  51. if not (f.get('height') and f.get('width')):
  52. mobj = re.search(r'_(\d+)x(\d+)', original_filename)
  53. if mobj:
  54. f.update({
  55. 'height': int(mobj.group(2)),
  56. 'width': int(mobj.group(1)),
  57. })
  58. if original_filename.startswith('s3://') and not s3_extracted:
  59. formats.append({
  60. 'format_id': 'original',
  61. 'quality': 1,
  62. 'url': original_filename.replace('s3://', 'https://s3.amazonaws.com/'),
  63. })
  64. s3_extracted = True
  65. formats.append(f)
  66. return {
  67. 'id': video_id,
  68. 'title': title,
  69. 'description': video_data.get('description'),
  70. 'thumbnail': video_data.get('thumbnail'),
  71. 'upload_date': unified_strdate(video_data.get('start_date')),
  72. 'duration': parse_duration(video_data.get('duration')),
  73. 'view_count': str_to_int(video_data.get('playcount')),
  74. 'formats': formats,
  75. 'subtitles': self._parse_subtitles(video_data, 'vtt'),
  76. }
  77. class AdobeTVEmbedIE(AdobeTVBaseIE):
  78. IE_NAME = 'adobetv:embed'
  79. _VALID_URL = r'https?://tv\.adobe\.com/embed/\d+/(?P<id>\d+)'
  80. _TEST = {
  81. 'url': 'https://tv.adobe.com/embed/22/4153',
  82. 'md5': 'c8c0461bf04d54574fc2b4d07ac6783a',
  83. 'info_dict': {
  84. 'id': '4153',
  85. 'ext': 'flv',
  86. 'title': 'Creating Graphics Optimized for BlackBerry',
  87. 'description': 'md5:eac6e8dced38bdaae51cd94447927459',
  88. 'thumbnail': r're:https?://.*\.jpg$',
  89. 'upload_date': '20091109',
  90. 'duration': 377,
  91. 'view_count': int,
  92. },
  93. }
  94. def _real_extract(self, url):
  95. video_id = self._match_id(url)
  96. video_data = self._call_api(
  97. 'episode/' + video_id, video_id, {'disclosure': 'standard'})[0]
  98. return self._parse_video_data(video_data)
  99. class AdobeTVIE(AdobeTVBaseIE):
  100. IE_NAME = 'adobetv'
  101. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?watch/(?P<show_urlname>[^/]+)/(?P<id>[^/]+)'
  102. _TEST = {
  103. 'url': 'http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/quick-tip-how-to-draw-a-circle-around-an-object-in-photoshop/',
  104. 'md5': '9bc5727bcdd55251f35ad311ca74fa1e',
  105. 'info_dict': {
  106. 'id': '10981',
  107. 'ext': 'mp4',
  108. 'title': 'Quick Tip - How to Draw a Circle Around an Object in Photoshop',
  109. 'description': 'md5:99ec318dc909d7ba2a1f2b038f7d2311',
  110. 'thumbnail': r're:https?://.*\.jpg$',
  111. 'upload_date': '20110914',
  112. 'duration': 60,
  113. 'view_count': int,
  114. },
  115. }
  116. def _real_extract(self, url):
  117. language, show_urlname, urlname = self._match_valid_url(url).groups()
  118. if not language:
  119. language = 'en'
  120. video_data = self._call_api(
  121. 'episode/get', urlname, {
  122. 'disclosure': 'standard',
  123. 'language': language,
  124. 'show_urlname': show_urlname,
  125. 'urlname': urlname,
  126. })[0]
  127. return self._parse_video_data(video_data)
  128. class AdobeTVPlaylistBaseIE(AdobeTVBaseIE):
  129. _PAGE_SIZE = 25
  130. def _fetch_page(self, display_id, query, page):
  131. page += 1
  132. query['page'] = page
  133. for element_data in self._call_api(
  134. self._RESOURCE, display_id, query, f'Download Page {page}'):
  135. yield self._process_data(element_data)
  136. def _extract_playlist_entries(self, display_id, query):
  137. return OnDemandPagedList(functools.partial(
  138. self._fetch_page, display_id, query), self._PAGE_SIZE)
  139. class AdobeTVShowIE(AdobeTVPlaylistBaseIE):
  140. IE_NAME = 'adobetv:show'
  141. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?show/(?P<id>[^/]+)'
  142. _TEST = {
  143. 'url': 'http://tv.adobe.com/show/the-complete-picture-with-julieanne-kost',
  144. 'info_dict': {
  145. 'id': '36',
  146. 'title': 'The Complete Picture with Julieanne Kost',
  147. 'description': 'md5:fa50867102dcd1aa0ddf2ab039311b27',
  148. },
  149. 'playlist_mincount': 136,
  150. }
  151. _RESOURCE = 'episode'
  152. _process_data = AdobeTVBaseIE._parse_video_data
  153. def _real_extract(self, url):
  154. language, show_urlname = self._match_valid_url(url).groups()
  155. if not language:
  156. language = 'en'
  157. query = {
  158. 'disclosure': 'standard',
  159. 'language': language,
  160. 'show_urlname': show_urlname,
  161. }
  162. show_data = self._call_api(
  163. 'show/get', show_urlname, query)[0]
  164. return self.playlist_result(
  165. self._extract_playlist_entries(show_urlname, query),
  166. str_or_none(show_data.get('id')),
  167. show_data.get('show_name'),
  168. show_data.get('show_description'))
  169. class AdobeTVChannelIE(AdobeTVPlaylistBaseIE):
  170. IE_NAME = 'adobetv:channel'
  171. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?channel/(?P<id>[^/]+)(?:/(?P<category_urlname>[^/]+))?'
  172. _TEST = {
  173. 'url': 'http://tv.adobe.com/channel/development',
  174. 'info_dict': {
  175. 'id': 'development',
  176. },
  177. 'playlist_mincount': 96,
  178. }
  179. _RESOURCE = 'show'
  180. def _process_data(self, show_data):
  181. return self.url_result(
  182. show_data['url'], 'AdobeTVShow', str_or_none(show_data.get('id')))
  183. def _real_extract(self, url):
  184. language, channel_urlname, category_urlname = self._match_valid_url(url).groups()
  185. if not language:
  186. language = 'en'
  187. query = {
  188. 'channel_urlname': channel_urlname,
  189. 'language': language,
  190. }
  191. if category_urlname:
  192. query['category_urlname'] = category_urlname
  193. return self.playlist_result(
  194. self._extract_playlist_entries(channel_urlname, query),
  195. channel_urlname)
  196. class AdobeTVVideoIE(AdobeTVBaseIE):
  197. IE_NAME = 'adobetv:video'
  198. _VALID_URL = r'https?://video\.tv\.adobe\.com/v/(?P<id>\d+)'
  199. _EMBED_REGEX = [r'<iframe[^>]+src=[\'"](?P<url>(?:https?:)?//video\.tv\.adobe\.com/v/\d+[^"]+)[\'"]']
  200. _TEST = {
  201. # From https://helpx.adobe.com/acrobat/how-to/new-experience-acrobat-dc.html?set=acrobat--get-started--essential-beginners
  202. 'url': 'https://video.tv.adobe.com/v/2456/',
  203. 'md5': '43662b577c018ad707a63766462b1e87',
  204. 'info_dict': {
  205. 'id': '2456',
  206. 'ext': 'mp4',
  207. 'title': 'New experience with Acrobat DC',
  208. 'description': 'New experience with Acrobat DC',
  209. 'duration': 248.667,
  210. },
  211. }
  212. def _real_extract(self, url):
  213. video_id = self._match_id(url)
  214. webpage = self._download_webpage(url, video_id)
  215. video_data = self._parse_json(self._search_regex(
  216. r'var\s+bridge\s*=\s*([^;]+);', webpage, 'bridged data'), video_id)
  217. title = video_data['title']
  218. formats = []
  219. sources = video_data.get('sources') or []
  220. for source in sources:
  221. source_src = source.get('src')
  222. if not source_src:
  223. continue
  224. formats.append({
  225. 'filesize': int_or_none(source.get('kilobytes') or None, invscale=1000),
  226. 'format_id': join_nonempty(source.get('format'), source.get('label')),
  227. 'height': int_or_none(source.get('height') or None),
  228. 'tbr': int_or_none(source.get('bitrate') or None),
  229. 'width': int_or_none(source.get('width') or None),
  230. 'url': source_src,
  231. })
  232. # For both metadata and downloaded files the duration varies among
  233. # formats. I just pick the max one
  234. duration = max(filter(None, [
  235. float_or_none(source.get('duration'), scale=1000)
  236. for source in sources]))
  237. return {
  238. 'id': video_id,
  239. 'formats': formats,
  240. 'title': title,
  241. 'description': video_data.get('description'),
  242. 'thumbnail': video_data.get('video', {}).get('poster'),
  243. 'duration': duration,
  244. 'subtitles': self._parse_subtitles(video_data, 'vttPath'),
  245. }