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