logo

youtube-dl

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

adobetv.py (10291B)


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