disney.py 6.6 KB

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