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.

131 lines
4.5 KiB

9 years ago
  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. # From https://helpx.adobe.com/acrobat/how-to/new-experience-acrobat-dc.html?set=acrobat--get-started--essential-beginners
  66. 'url': 'https://video.tv.adobe.com/v/2456/',
  67. 'md5': '43662b577c018ad707a63766462b1e87',
  68. 'info_dict': {
  69. 'id': '2456',
  70. 'ext': 'mp4',
  71. 'title': 'New experience with Acrobat DC',
  72. 'description': 'New experience with Acrobat DC',
  73. 'duration': 248.667,
  74. },
  75. }
  76. def _real_extract(self, url):
  77. video_id = self._match_id(url)
  78. webpage = self._download_webpage(url, video_id)
  79. player_params = self._parse_json(self._search_regex(
  80. r'var\s+bridge\s*=\s*([^;]+);', webpage, 'player parameters'),
  81. video_id)
  82. formats = [{
  83. 'url': source['src'],
  84. 'width': source.get('width'),
  85. 'height': source.get('height'),
  86. 'tbr': source.get('bitrate'),
  87. } for source in player_params['sources']]
  88. # For both metadata and downloaded files the duration varies among
  89. # formats. I just pick the max one
  90. duration = max(filter(None, [
  91. float_or_none(source.get('duration'), scale=1000)
  92. for source in player_params['sources']]))
  93. subtitles = {}
  94. for translation in player_params.get('translations', []):
  95. lang_id = translation.get('language_w3c') or ISO639Utils.long2short(translation['language_medium'])
  96. if lang_id not in subtitles:
  97. subtitles[lang_id] = []
  98. subtitles[lang_id].append({
  99. 'url': translation['vttPath'],
  100. 'ext': 'vtt',
  101. })
  102. return {
  103. 'id': video_id,
  104. 'formats': formats,
  105. 'title': player_params['title'],
  106. 'description': self._og_search_description(webpage),
  107. 'duration': duration,
  108. 'subtitles': subtitles,
  109. }