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.

115 lines
4.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. )
  11. class DisneyIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. https?://(?P<domain>(?:[^/]+\.)?(?:disney\.[a-z]{2,3}(?:\.[a-z]{2})?|disney(?:(?:me|latino)\.com|turkiye\.com\.tr)|starwars\.com))/(?:embed/|(?:[^/]+/)+[\w-]+-)(?P<id>[a-z0-9]{24})'''
  14. _TESTS = [{
  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. 'url': 'http://videos.disneylatino.com/ver/spider-man-de-regreso-a-casa-primer-adelanto-543a33a1850bdcfcca13bae2',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://video.en.disneyme.com/watch/future-worm/robo-carp-2001-544b66002aa7353cdd3f5114',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://video.disneyturkiye.com.tr/izle/7c-7-cuceler/kimin-sesi-zaten-5456f3d015f6b36c8afdd0e2',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://disneyjunior.disney.com/embed/546a4798ddba3d1612e4005d',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://www.starwars.com/embed/54690d1e6c42e5f09a0fb097',
  41. 'only_matching': True,
  42. }]
  43. def _real_extract(self, url):
  44. domain, video_id = re.match(self._VALID_URL, url).groups()
  45. webpage = self._download_webpage(
  46. 'http://%s/embed/%s' % (domain, video_id), video_id)
  47. video_data = self._parse_json(self._search_regex(
  48. r'Disney\.EmbedVideo=({.+});', webpage, 'embed data'), video_id)['video']
  49. for external in video_data.get('externals', []):
  50. if external.get('source') == 'vevo':
  51. return self.url_result('vevo:' + external['data_id'], 'Vevo')
  52. title = video_data['title']
  53. formats = []
  54. for flavor in video_data.get('flavors', []):
  55. flavor_format = flavor.get('format')
  56. flavor_url = flavor.get('url')
  57. if not flavor_url or not re.match(r'https?://', flavor_url):
  58. continue
  59. tbr = int_or_none(flavor.get('bitrate'))
  60. if tbr == 99999:
  61. formats.extend(self._extract_m3u8_formats(
  62. flavor_url, video_id, 'mp4', m3u8_id=flavor_format, fatal=False))
  63. continue
  64. format_id = []
  65. if flavor_format:
  66. format_id.append(flavor_format)
  67. if tbr:
  68. format_id.append(compat_str(tbr))
  69. ext = determine_ext(flavor_url)
  70. if flavor_format == 'applehttp' or ext == 'm3u8':
  71. ext = 'mp4'
  72. width = int_or_none(flavor.get('width'))
  73. height = int_or_none(flavor.get('height'))
  74. formats.append({
  75. 'format_id': '-'.join(format_id),
  76. 'url': flavor_url,
  77. 'width': width,
  78. 'height': height,
  79. 'tbr': tbr,
  80. 'ext': ext,
  81. 'vcodec': 'none' if (width == 0 and height == 0) else None,
  82. })
  83. self._sort_formats(formats)
  84. subtitles = {}
  85. for caption in video_data.get('captions', []):
  86. caption_url = caption.get('url')
  87. caption_format = caption.get('format')
  88. if not caption_url or caption_format.startswith('unknown'):
  89. continue
  90. subtitles.setdefault(caption.get('language', 'en'), []).append({
  91. 'url': caption_url,
  92. 'ext': {
  93. 'webvtt': 'vtt',
  94. }.get(caption_format, caption_format),
  95. })
  96. return {
  97. 'id': video_id,
  98. 'title': title,
  99. 'description': video_data.get('description') or video_data.get('short_desc'),
  100. 'thumbnail': video_data.get('thumb') or video_data.get('thumb_secure'),
  101. 'duration': int_or_none(video_data.get('duration_sec')),
  102. 'upload_date': unified_strdate(video_data.get('publish_date')),
  103. 'formats': formats,
  104. 'subtitles': subtitles,
  105. }