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.

159 lines
6.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. unified_strdate,
  8. compat_str,
  9. determine_ext,
  10. ExtractorError,
  11. )
  12. class DisneyIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://(?P<domain>(?:[^/]+\.)?(?:disney\.[a-z]{2,3}(?:\.[a-z]{2})?|disney(?:(?:me|latino)\.com|turkiye\.com\.tr)|(?:starwars|marvelkids)\.com))/(?:(?:embed/|(?:[^/]+/)+[\w-]+-)(?P<id>[a-z0-9]{24})|(?:[^/]+/)?(?P<display_id>[^/?#]+))'''
  15. _TESTS = [{
  16. # Disney.EmbedVideo
  17. 'url': 'http://video.disney.com/watch/moana-trailer-545ed1857afee5a0ec239977',
  18. 'info_dict': {
  19. 'id': '545ed1857afee5a0ec239977',
  20. 'ext': 'mp4',
  21. 'title': 'Moana - Trailer',
  22. 'description': 'A fun adventure for the entire Family! Bring home Moana on Digital HD Feb 21 & Blu-ray March 7',
  23. 'upload_date': '20170112',
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. }
  29. }, {
  30. # Grill.burger
  31. 'url': 'http://www.starwars.com/video/rogue-one-a-star-wars-story-intro-featurette',
  32. 'info_dict': {
  33. 'id': '5454e9f4e9804a552e3524c8',
  34. 'ext': 'mp4',
  35. 'title': '"Intro" Featurette: Rogue One: A Star Wars Story',
  36. 'upload_date': '20170104',
  37. 'description': 'Go behind-the-scenes of Rogue One: A Star Wars Story in this featurette with Director Gareth Edwards and the cast of the film.',
  38. },
  39. 'params': {
  40. # m3u8 download
  41. 'skip_download': True,
  42. }
  43. }, {
  44. 'url': 'http://videos.disneylatino.com/ver/spider-man-de-regreso-a-casa-primer-adelanto-543a33a1850bdcfcca13bae2',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'http://video.en.disneyme.com/watch/future-worm/robo-carp-2001-544b66002aa7353cdd3f5114',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://video.disneyturkiye.com.tr/izle/7c-7-cuceler/kimin-sesi-zaten-5456f3d015f6b36c8afdd0e2',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'http://disneyjunior.disney.com/embed/546a4798ddba3d1612e4005d',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'http://www.starwars.com/embed/54690d1e6c42e5f09a0fb097',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'http://spiderman.marvelkids.com/embed/522900d2ced3c565e4cc0677',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'http://spiderman.marvelkids.com/videos/contest-of-champions-part-four-clip-1',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'http://disneyjunior.en.disneyme.com/dj/watch-my-friends-tigger-and-pooh-promo',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'http://disneyjunior.disney.com/galactech-the-galactech-grab-galactech-an-admiral-rescue',
  69. 'only_matching': True,
  70. }]
  71. def _real_extract(self, url):
  72. domain, video_id, display_id = re.match(self._VALID_URL, url).groups()
  73. if not video_id:
  74. webpage = self._download_webpage(url, display_id)
  75. grill = re.sub(r'"\s*\+\s*"', '', self._search_regex(
  76. r'Grill\.burger\s*=\s*({.+})\s*:',
  77. webpage, 'grill data'))
  78. page_data = next(s for s in self._parse_json(grill, display_id)['stack'] if s.get('type') == 'video')
  79. video_data = page_data['data'][0]
  80. else:
  81. webpage = self._download_webpage(
  82. 'http://%s/embed/%s' % (domain, video_id), video_id)
  83. page_data = self._parse_json(self._search_regex(
  84. r'Disney\.EmbedVideo\s*=\s*({.+});',
  85. webpage, 'embed data'), video_id)
  86. video_data = page_data['video']
  87. for external in video_data.get('externals', []):
  88. if external.get('source') == 'vevo':
  89. return self.url_result('vevo:' + external['data_id'], 'Vevo')
  90. video_id = video_data['id']
  91. title = video_data['title']
  92. formats = []
  93. for flavor in video_data.get('flavors', []):
  94. flavor_format = flavor.get('format')
  95. flavor_url = flavor.get('url')
  96. if not flavor_url or not re.match(r'https?://', flavor_url) or flavor_format == 'mp4_access':
  97. continue
  98. tbr = int_or_none(flavor.get('bitrate'))
  99. if tbr == 99999:
  100. formats.extend(self._extract_m3u8_formats(
  101. flavor_url, video_id, 'mp4',
  102. m3u8_id=flavor_format, fatal=False))
  103. continue
  104. format_id = []
  105. if flavor_format:
  106. format_id.append(flavor_format)
  107. if tbr:
  108. format_id.append(compat_str(tbr))
  109. ext = determine_ext(flavor_url)
  110. if flavor_format == 'applehttp' or ext == 'm3u8':
  111. ext = 'mp4'
  112. width = int_or_none(flavor.get('width'))
  113. height = int_or_none(flavor.get('height'))
  114. formats.append({
  115. 'format_id': '-'.join(format_id),
  116. 'url': flavor_url,
  117. 'width': width,
  118. 'height': height,
  119. 'tbr': tbr,
  120. 'ext': ext,
  121. 'vcodec': 'none' if (width == 0 and height == 0) else None,
  122. })
  123. if not formats and video_data.get('expired'):
  124. raise ExtractorError(
  125. '%s said: %s' % (self.IE_NAME, page_data['translations']['video_expired']),
  126. expected=True)
  127. self._sort_formats(formats)
  128. subtitles = {}
  129. for caption in video_data.get('captions', []):
  130. caption_url = caption.get('url')
  131. caption_format = caption.get('format')
  132. if not caption_url or caption_format.startswith('unknown'):
  133. continue
  134. subtitles.setdefault(caption.get('language', 'en'), []).append({
  135. 'url': caption_url,
  136. 'ext': {
  137. 'webvtt': 'vtt',
  138. }.get(caption_format, caption_format),
  139. })
  140. return {
  141. 'id': video_id,
  142. 'title': title,
  143. 'description': video_data.get('description') or video_data.get('short_desc'),
  144. 'thumbnail': video_data.get('thumb') or video_data.get('thumb_secure'),
  145. 'duration': int_or_none(video_data.get('duration_sec')),
  146. 'upload_date': unified_strdate(video_data.get('publish_date')),
  147. 'formats': formats,
  148. 'subtitles': subtitles,
  149. }