]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nick.py
[youtube] Force `hl=en` for comments (#594)
[yt-dlp.git] / yt_dlp / extractor / nick.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .mtv import MTVServicesInfoExtractor
7 from ..utils import update_url_query
8
9
10 class NickIE(MTVServicesInfoExtractor):
11 IE_NAME = 'nick.com'
12 _VALID_URL = r'https?://(?P<domain>(?:www\.)?nick(?:jr)?\.com)/(?:[^/]+/)?(?P<type>videos/clip|[^/]+/videos|episodes/[^/]+)/(?P<id>[^/?#.]+)'
13 _FEED_URL = 'http://udat.mtvnservices.com/service1/dispatch.htm'
14 _GEO_COUNTRIES = ['US']
15 _TESTS = [{
16 'url': 'https://www.nick.com/episodes/sq47rw/spongebob-squarepants-a-place-for-pets-lockdown-for-love-season-13-ep-1',
17 'info_dict': {
18 'description': 'md5:0650a9eb88955609d5c1d1c79292e234',
19 'title': 'A Place for Pets/Lockdown for Love',
20 },
21 'playlist': [
22 {
23 'md5': 'cb8a2afeafb7ae154aca5a64815ec9d6',
24 'info_dict': {
25 'id': '85ee8177-d6ce-48f8-9eee-a65364f8a6df',
26 'ext': 'mp4',
27 'title': 'SpongeBob SquarePants: "A Place for Pets/Lockdown for Love" S1',
28 'description': 'A Place for Pets/Lockdown for Love: When customers bring pets into the Krusty Krab, Mr. Krabs realizes pets are more profitable than owners. Plankton ruins another date with Karen, so she puts the Chum Bucket on lockdown until he proves his affection.',
29
30 }
31 },
32 {
33 'md5': '839a04f49900a1fcbf517020d94e0737',
34 'info_dict': {
35 'id': '2e2a9960-8fd4-411d-868b-28eb1beb7fae',
36 'ext': 'mp4',
37 'title': 'SpongeBob SquarePants: "A Place for Pets/Lockdown for Love" S2',
38 'description': 'A Place for Pets/Lockdown for Love: When customers bring pets into the Krusty Krab, Mr. Krabs realizes pets are more profitable than owners. Plankton ruins another date with Karen, so she puts the Chum Bucket on lockdown until he proves his affection.',
39
40 }
41 },
42 {
43 'md5': 'f1145699f199770e2919ee8646955d46',
44 'info_dict': {
45 'id': 'dc91c304-6876-40f7-84a6-7aece7baa9d0',
46 'ext': 'mp4',
47 'title': 'SpongeBob SquarePants: "A Place for Pets/Lockdown for Love" S3',
48 'description': 'A Place for Pets/Lockdown for Love: When customers bring pets into the Krusty Krab, Mr. Krabs realizes pets are more profitable than owners. Plankton ruins another date with Karen, so she puts the Chum Bucket on lockdown until he proves his affection.',
49
50 }
51 },
52 {
53 'md5': 'd463116875aee2585ee58de3b12caebd',
54 'info_dict': {
55 'id': '5d929486-cf4c-42a1-889a-6e0d183a101a',
56 'ext': 'mp4',
57 'title': 'SpongeBob SquarePants: "A Place for Pets/Lockdown for Love" S4',
58 'description': 'A Place for Pets/Lockdown for Love: When customers bring pets into the Krusty Krab, Mr. Krabs realizes pets are more profitable than owners. Plankton ruins another date with Karen, so she puts the Chum Bucket on lockdown until he proves his affection.',
59
60 }
61 },
62 ],
63 }, {
64 'url': 'http://www.nickjr.com/blues-clues-and-you/videos/blues-clues-and-you-original-209-imagination-station/',
65 'info_dict': {
66 'id': '31631529-2fc5-430b-b2ef-6a74b4609abd',
67 'ext': 'mp4',
68 'description': 'md5:9d65a66df38e02254852794b2809d1cf',
69 'title': 'Blue\'s Imagination Station',
70 },
71 }]
72
73 def _get_feed_query(self, uri):
74 return {
75 'feed': 'nick_arc_player_prime',
76 'mgid': uri,
77 }
78
79 def _extract_mgid(self, webpage):
80 mgid = self._search_regex(r'"media":{"video":{"config":{"uri":"(mgid:.*?)"', webpage, 'mgid', default=None)
81 return mgid
82
83 def _real_extract(self, url):
84 domain, video_type, display_id = re.match(self._VALID_URL, url).groups()
85 if video_type.startswith("episodes"):
86 return super()._real_extract(url)
87 video_data = self._download_json(
88 'http://%s/data/video.endLevel.json' % domain,
89 display_id, query={
90 'urlKey': display_id,
91 })
92 return self._get_videos_info(video_data['player'] + video_data['id'])
93
94
95 class NickBrIE(MTVServicesInfoExtractor):
96 IE_NAME = 'nickelodeon:br'
97 _VALID_URL = r'''(?x)
98 https?://
99 (?:
100 (?P<domain>(?:www\.)?nickjr|mundonick\.uol)\.com\.br|
101 (?:www\.)?nickjr\.[a-z]{2}|
102 (?:www\.)?nickelodeonjunior\.fr
103 )
104 /(?:programas/)?[^/]+/videos/(?:episodios/)?(?P<id>[^/?\#.]+)
105 '''
106 _TESTS = [{
107 'url': 'http://www.nickjr.com.br/patrulha-canina/videos/210-labirinto-de-pipoca/',
108 'only_matching': True,
109 }, {
110 'url': 'http://mundonick.uol.com.br/programas/the-loud-house/videos/muitas-irmas/7ljo9j',
111 'only_matching': True,
112 }, {
113 'url': 'http://www.nickjr.nl/paw-patrol/videos/311-ge-wol-dig-om-terug-te-zijn/',
114 'only_matching': True,
115 }, {
116 'url': 'http://www.nickjr.de/blaze-und-die-monster-maschinen/videos/f6caaf8f-e4e8-4cc1-b489-9380d6dcd059/',
117 'only_matching': True,
118 }, {
119 'url': 'http://www.nickelodeonjunior.fr/paw-patrol-la-pat-patrouille/videos/episode-401-entier-paw-patrol/',
120 'only_matching': True,
121 }]
122
123 def _real_extract(self, url):
124 domain, display_id = re.match(self._VALID_URL, url).groups()
125 webpage = self._download_webpage(url, display_id)
126 uri = self._search_regex(
127 r'data-(?:contenturi|mgid)="([^"]+)', webpage, 'mgid')
128 video_id = self._id_from_uri(uri)
129 config = self._download_json(
130 'http://media.mtvnservices.com/pmt/e1/access/index.html',
131 video_id, query={
132 'uri': uri,
133 'configtype': 'edge',
134 }, headers={
135 'Referer': url,
136 })
137 info_url = self._remove_template_parameter(config['feedWithQueryParams'])
138 if info_url == 'None':
139 if domain.startswith('www.'):
140 domain = domain[4:]
141 content_domain = {
142 'mundonick.uol': 'mundonick.com.br',
143 'nickjr': 'br.nickelodeonjunior.tv',
144 }[domain]
145 query = {
146 'mgid': uri,
147 'imageEp': content_domain,
148 'arcEp': content_domain,
149 }
150 if domain == 'nickjr.com.br':
151 query['ep'] = 'c4b16088'
152 info_url = update_url_query(
153 'http://feeds.mtvnservices.com/od/feed/intl-mrss-player-feed', query)
154 return self._get_videos_info_from_url(info_url, video_id)
155
156
157 class NickDeIE(MTVServicesInfoExtractor):
158 IE_NAME = 'nick.de'
159 _VALID_URL = r'https?://(?:www\.)?(?P<host>nick\.(?:de|com\.pl|ch)|nickelodeon\.(?:nl|be|at|dk|no|se))/[^/]+/(?:[^/]+/)*(?P<id>[^/?#&]+)'
160 _TESTS = [{
161 'url': 'http://www.nick.de/playlist/3773-top-videos/videos/episode/17306-zu-wasser-und-zu-land-rauchende-erdnusse',
162 'only_matching': True,
163 }, {
164 'url': 'http://www.nick.de/shows/342-icarly',
165 'only_matching': True,
166 }, {
167 'url': 'http://www.nickelodeon.nl/shows/474-spongebob/videos/17403-een-kijkje-in-de-keuken-met-sandy-van-binnenuit',
168 'only_matching': True,
169 }, {
170 'url': 'http://www.nickelodeon.at/playlist/3773-top-videos/videos/episode/77993-das-letzte-gefecht',
171 'only_matching': True,
172 }, {
173 'url': 'http://www.nick.com.pl/seriale/474-spongebob-kanciastoporty/wideo/17412-teatr-to-jest-to-rodeo-oszolom',
174 'only_matching': True,
175 }, {
176 'url': 'http://www.nickelodeon.no/program/2626-bulderhuset/videoer/90947-femteklasse-veronica-vs-vanzilla',
177 'only_matching': True,
178 }, {
179 'url': 'http://www.nickelodeon.dk/serier/2626-hojs-hus/videoer/761-tissepause',
180 'only_matching': True,
181 }, {
182 'url': 'http://www.nickelodeon.se/serier/2626-lugn-i-stormen/videos/998-',
183 'only_matching': True,
184 }, {
185 'url': 'http://www.nick.ch/shows/2304-adventure-time-abenteuerzeit-mit-finn-und-jake',
186 'only_matching': True,
187 }, {
188 'url': 'http://www.nickelodeon.be/afspeellijst/4530-top-videos/videos/episode/73917-inval-broodschapper-lariekoek-arie',
189 'only_matching': True,
190 }]
191
192 def _get_feed_url(self, uri, url=None):
193 video_id = self._id_from_uri(uri)
194 config = self._download_json(
195 'http://media.mtvnservices.com/pmt/e1/access/index.html?uri=%s&configtype=edge&ref=%s' % (uri, url), video_id)
196 return self._remove_template_parameter(config['feedWithQueryParams'])
197
198
199 class NickNightIE(NickDeIE):
200 IE_NAME = 'nicknight'
201 _VALID_URL = r'https?://(?:www\.)(?P<host>nicknight\.(?:de|at|tv))/(?:playlist|shows)/(?:[^/]+/)*(?P<id>[^/?#&]+)'
202 _TESTS = [{
203 'url': 'http://www.nicknight.at/shows/977-awkward/videos/85987-nimmer-beste-freunde',
204 'only_matching': True,
205 }, {
206 'url': 'http://www.nicknight.at/shows/977-awkward',
207 'only_matching': True,
208 }, {
209 'url': 'http://www.nicknight.at/shows/1900-faking-it',
210 'only_matching': True,
211 }]
212
213 def _extract_mrss_url(self, webpage, *args):
214 return self._search_regex(
215 r'mrss\s*:\s*(["\'])(?P<url>http.+?)\1', webpage,
216 'mrss url', group='url')
217
218
219 class NickRuIE(MTVServicesInfoExtractor):
220 IE_NAME = 'nickelodeonru'
221 _VALID_URL = r'https?://(?:www\.)nickelodeon\.(?:ru|fr|es|pt|ro|hu|com\.tr)/[^/]+/(?:[^/]+/)*(?P<id>[^/?#&]+)'
222 _TESTS = [{
223 'url': 'http://www.nickelodeon.ru/shows/henrydanger/videos/episodes/3-sezon-15-seriya-licenziya-na-polyot/pmomfb#playlist/7airc6',
224 'only_matching': True,
225 }, {
226 'url': 'http://www.nickelodeon.ru/videos/smotri-na-nickelodeon-v-iyule/g9hvh7',
227 'only_matching': True,
228 }, {
229 'url': 'http://www.nickelodeon.fr/programmes/bob-l-eponge/videos/le-marathon-de-booh-kini-bottom-mardi-31-octobre/nfn7z0',
230 'only_matching': True,
231 }, {
232 'url': 'http://www.nickelodeon.es/videos/nickelodeon-consejos-tortitas/f7w7xy',
233 'only_matching': True,
234 }, {
235 'url': 'http://www.nickelodeon.pt/series/spongebob-squarepants/videos/a-bolha-de-tinta-gigante/xutq1b',
236 'only_matching': True,
237 }, {
238 'url': 'http://www.nickelodeon.ro/emisiuni/shimmer-si-shine/video/nahal-din-bomboane/uw5u2k',
239 'only_matching': True,
240 }, {
241 'url': 'http://www.nickelodeon.hu/musorok/spongyabob-kockanadrag/videok/episodes/buborekfujas-az-elszakadt-nadrag/q57iob#playlist/k6te4y',
242 'only_matching': True,
243 }, {
244 'url': 'http://www.nickelodeon.com.tr/programlar/sunger-bob/videolar/kayip-yatak/mgqbjy',
245 'only_matching': True,
246 }]
247
248 def _real_extract(self, url):
249 video_id = self._match_id(url)
250 webpage = self._download_webpage(url, video_id)
251 mgid = self._extract_mgid(webpage, url)
252 return self.url_result('http://media.mtvnservices.com/embed/%s' % mgid)