]>
Commit | Line | Data |
---|---|---|
d73ebac1 RA |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
a74c3ccc | 3 | ExtractorError, |
d73ebac1 RA |
4 | extract_attributes, |
5 | int_or_none, | |
a74c3ccc | 6 | js_to_json, |
7 | merge_dicts, | |
d73ebac1 RA |
8 | ) |
9 | ||
10 | ||
11 | class PokemonIE(InfoExtractor): | |
237d07f1 | 12 | _VALID_URL = r'https?://(?:www\.)?pokemon\.com/[a-z]{2}(?:.*?play=(?P<id>[a-z0-9]{32})|/(?:[^/]+/)+(?P<display_id>[^/?#&]+))' |
d73ebac1 | 13 | _TESTS = [{ |
237d07f1 S |
14 | 'url': 'https://www.pokemon.com/us/pokemon-episodes/20_30-the-ol-raise-and-switch/', |
15 | 'md5': '2fe8eaec69768b25ef898cda9c43062e', | |
d73ebac1 | 16 | 'info_dict': { |
237d07f1 | 17 | 'id': 'afe22e30f01c41f49d4f1d9eab5cd9a4', |
d73ebac1 | 18 | 'ext': 'mp4', |
237d07f1 S |
19 | 'title': 'The Ol’ Raise and Switch!', |
20 | 'description': 'md5:7db77f7107f98ba88401d3adc80ff7af', | |
237d07f1 S |
21 | }, |
22 | 'add_id': ['LimelightMedia'], | |
23 | }, { | |
24 | # no data-video-title | |
2e20cb36 | 25 | 'url': 'https://www.pokemon.com/fr/episodes-pokemon/films-pokemon/pokemon-lascension-de-darkrai-2008', |
237d07f1 | 26 | 'info_dict': { |
2e20cb36 | 27 | 'id': 'dfbaf830d7e54e179837c50c0c6cc0e1', |
237d07f1 | 28 | 'ext': 'mp4', |
2e20cb36 RA |
29 | 'title': "Pokémon : L'ascension de Darkrai", |
30 | 'description': 'md5:d1dbc9e206070c3e14a06ff557659fb5', | |
237d07f1 S |
31 | }, |
32 | 'add_id': ['LimelightMedia'], | |
33 | 'params': { | |
34 | 'skip_download': True, | |
d73ebac1 | 35 | }, |
d73ebac1 RA |
36 | }, { |
37 | 'url': 'http://www.pokemon.com/uk/pokemon-episodes/?play=2e8b5c761f1d4a9286165d7748c1ece2', | |
38 | 'only_matching': True, | |
089a4095 RA |
39 | }, { |
40 | 'url': 'http://www.pokemon.com/fr/episodes-pokemon/18_09-un-hiver-inattendu/', | |
41 | 'only_matching': True, | |
42 | }, { | |
43 | 'url': 'http://www.pokemon.com/de/pokemon-folgen/01_20-bye-bye-smettbo/', | |
44 | 'only_matching': True, | |
d73ebac1 RA |
45 | }] |
46 | ||
47 | def _real_extract(self, url): | |
5ad28e7f | 48 | video_id, display_id = self._match_valid_url(url).groups() |
d73ebac1 RA |
49 | webpage = self._download_webpage(url, video_id or display_id) |
50 | video_data = extract_attributes(self._search_regex( | |
51 | r'(<[^>]+data-video-id="%s"[^>]*>)' % (video_id if video_id else '[a-z0-9]{32}'), | |
52 | webpage, 'video data element')) | |
53 | video_id = video_data['data-video-id'] | |
237d07f1 | 54 | title = video_data.get('data-video-title') or self._html_search_meta( |
4fac463d | 55 | 'pkm-title', webpage, ' title', default=None) or self._search_regex( |
237d07f1 | 56 | r'<h1[^>]+\bclass=["\']us-title[^>]+>([^<]+)', webpage, 'title') |
d73ebac1 RA |
57 | return { |
58 | '_type': 'url_transparent', | |
59 | 'id': video_id, | |
60 | 'url': 'limelight:media:%s' % video_id, | |
61 | 'title': title, | |
62 | 'description': video_data.get('data-video-summary'), | |
63 | 'thumbnail': video_data.get('data-video-poster'), | |
64 | 'series': 'Pokémon', | |
65 | 'season_number': int_or_none(video_data.get('data-video-season')), | |
66 | 'episode': title, | |
67 | 'episode_number': int_or_none(video_data.get('data-video-episode')), | |
68 | 'ie_key': 'LimelightMedia', | |
69 | } | |
a74c3ccc | 70 | |
71 | ||
72 | class PokemonWatchIE(InfoExtractor): | |
e7ff5051 | 73 | _VALID_URL = r'https?://watch\.pokemon\.com/[a-z]{2}-[a-z]{2}/(?:#/)?player(?:\.html)?\?id=(?P<id>[a-z0-9]{32})' |
a74c3ccc | 74 | _API_URL = 'https://www.pokemon.com/api/pokemontv/v2/channels/{0:}' |
75 | _TESTS = [{ | |
76 | 'url': 'https://watch.pokemon.com/en-us/player.html?id=8309a40969894a8e8d5bc1311e9c5667', | |
77 | 'md5': '62833938a31e61ab49ada92f524c42ff', | |
78 | 'info_dict': { | |
79 | 'id': '8309a40969894a8e8d5bc1311e9c5667', | |
80 | 'ext': 'mp4', | |
81 | 'title': 'Lillier and the Staff!', | |
82 | 'description': 'md5:338841b8c21b283d24bdc9b568849f04', | |
83 | } | |
e7ff5051 | 84 | }, { |
85 | 'url': 'https://watch.pokemon.com/en-us/#/player?id=3fe7752ba09141f0b0f7756d1981c6b2', | |
86 | 'only_matching': True | |
a74c3ccc | 87 | }, { |
88 | 'url': 'https://watch.pokemon.com/de-de/player.html?id=b3c402e111a4459eb47e12160ab0ba07', | |
89 | 'only_matching': True | |
90 | }] | |
91 | ||
92 | def _extract_media(self, channel_array, video_id): | |
93 | for channel in channel_array: | |
94 | for media in channel.get('media'): | |
95 | if media.get('id') == video_id: | |
96 | return media | |
97 | return None | |
98 | ||
99 | def _real_extract(self, url): | |
100 | video_id = self._match_id(url) | |
101 | ||
102 | info = { | |
103 | '_type': 'url', | |
104 | 'id': video_id, | |
105 | 'url': 'limelight:media:%s' % video_id, | |
106 | 'ie_key': 'LimelightMedia', | |
107 | } | |
108 | ||
109 | # API call can be avoided entirely if we are listing formats | |
a06916d9 | 110 | if self.get_param('listformats', False): |
a74c3ccc | 111 | return info |
112 | ||
113 | webpage = self._download_webpage(url, video_id) | |
114 | build_vars = self._parse_json(self._search_regex( | |
115 | r'(?s)buildVars\s*=\s*({.*?})', webpage, 'build vars'), | |
116 | video_id, transform_source=js_to_json) | |
117 | region = build_vars.get('region') | |
118 | channel_array = self._download_json(self._API_URL.format(region), video_id) | |
119 | video_data = self._extract_media(channel_array, video_id) | |
120 | ||
121 | if video_data is None: | |
122 | raise ExtractorError( | |
123 | 'Video %s does not exist' % video_id, expected=True) | |
124 | ||
125 | info['_type'] = 'url_transparent' | |
126 | images = video_data.get('images') | |
127 | ||
128 | return merge_dicts(info, { | |
129 | 'title': video_data.get('title'), | |
130 | 'description': video_data.get('description'), | |
131 | 'thumbnail': images.get('medium') or images.get('small'), | |
132 | 'series': 'Pokémon', | |
133 | 'season_number': int_or_none(video_data.get('season')), | |
134 | 'episode': video_data.get('title'), | |
135 | 'episode_number': int_or_none(video_data.get('episode')), | |
136 | }) |