adobetv.py 4.4 KB

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