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