adobetv.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. unified_strdate,
  7. str_to_int,
  8. int_or_none,
  9. float_or_none,
  10. ISO639Utils,
  11. )
  12. class AdobeTVIE(InfoExtractor):
  13. _VALID_URL = r'https?://tv\.adobe\.com/(?:(?P<language>fr|de|es|jp)/)?watch/(?P<show_urlname>[^/]+)/(?P<id>[^/]+)'
  14. _TEST = {
  15. 'url': 'http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/quick-tip-how-to-draw-a-circle-around-an-object-in-photoshop/',
  16. 'md5': '9bc5727bcdd55251f35ad311ca74fa1e',
  17. 'info_dict': {
  18. 'id': '10981',
  19. 'ext': 'mp4',
  20. 'title': 'Quick Tip - How to Draw a Circle Around an Object in Photoshop',
  21. 'description': 'md5:99ec318dc909d7ba2a1f2b038f7d2311',
  22. 'thumbnail': 're:https?://.*\.jpg$',
  23. 'upload_date': '20110914',
  24. 'duration': 60,
  25. 'view_count': int,
  26. },
  27. }
  28. def _real_extract(self, url):
  29. language, show_urlname, urlname = re.match(self._VALID_URL, url).groups()
  30. if not language:
  31. language = 'en'
  32. video_data = self._download_json(
  33. 'http://tv.adobe.com/api/v4/episode/get/?language=%s&show_urlname=%s&urlname=%s&disclosure=standard' % (language, show_urlname, urlname),
  34. urlname)['data'][0]
  35. formats = [{
  36. 'url': source['url'],
  37. 'format_id': source.get('quality_level') or source['url'].split('-')[-1].split('.')[0] or None,
  38. 'width': int_or_none(source.get('width')),
  39. 'height': int_or_none(source.get('height')),
  40. 'tbr': int_or_none(source.get('video_data_rate')),
  41. } for source in video_data['videos']]
  42. self._sort_formats(formats)
  43. return {
  44. 'id': str(video_data['id']),
  45. 'title': video_data['title'],
  46. 'description': video_data.get('description'),
  47. 'thumbnail': video_data.get('thumbnail'),
  48. 'upload_date': unified_strdate(video_data.get('start_date')),
  49. 'duration': parse_duration(video_data.get('duration')),
  50. 'view_count': str_to_int(video_data.get('playcount')),
  51. 'formats': formats,
  52. }
  53. class AdobeTVVideoIE(InfoExtractor):
  54. _VALID_URL = r'https?://video\.tv\.adobe\.com/v/(?P<id>\d+)'
  55. _TEST = {
  56. # From https://helpx.adobe.com/acrobat/how-to/new-experience-acrobat-dc.html?set=acrobat--get-started--essential-beginners
  57. 'url': 'https://video.tv.adobe.com/v/2456/',
  58. 'md5': '43662b577c018ad707a63766462b1e87',
  59. 'info_dict': {
  60. 'id': '2456',
  61. 'ext': 'mp4',
  62. 'title': 'New experience with Acrobat DC',
  63. 'description': 'New experience with Acrobat DC',
  64. 'duration': 248.667,
  65. },
  66. }
  67. def _real_extract(self, url):
  68. video_id = self._match_id(url)
  69. webpage = self._download_webpage(url, video_id)
  70. player_params = self._parse_json(self._search_regex(
  71. r'var\s+bridge\s*=\s*([^;]+);', webpage, 'player parameters'),
  72. video_id)
  73. formats = [{
  74. 'url': source['src'],
  75. 'width': source.get('width'),
  76. 'height': source.get('height'),
  77. 'tbr': source.get('bitrate'),
  78. } for source in player_params['sources']]
  79. # For both metadata and downloaded files the duration varies among
  80. # formats. I just pick the max one
  81. duration = max(filter(None, [
  82. float_or_none(source.get('duration'), scale=1000)
  83. for source in player_params['sources']]))
  84. subtitles = {}
  85. for translation in player_params.get('translations', []):
  86. lang_id = translation.get('language_w3c') or ISO639Utils.long2short(translation['language_medium'])
  87. if lang_id not in subtitles:
  88. subtitles[lang_id] = []
  89. subtitles[lang_id].append({
  90. 'url': translation['vttPath'],
  91. 'ext': 'vtt',
  92. })
  93. return {
  94. 'id': video_id,
  95. 'formats': formats,
  96. 'title': player_params['title'],
  97. 'description': self._og_search_description(webpage),
  98. 'duration': duration,
  99. 'subtitles': subtitles,
  100. }