]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pokemon.py
debian/patches: Add patch to skip style checks from flake8 during test.
[youtubedl] / youtube_dl / extractor / pokemon.py
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 extract_attributes,
9 int_or_none,
10 )
11
12
13 class PokemonIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?pokemon\.com/[a-z]{2}(?:.*?play=(?P<id>[a-z0-9]{32})|/(?:[^/]+/)+(?P<display_id>[^/?#&]+))'
15 _TESTS = [{
16 'url': 'https://www.pokemon.com/us/pokemon-episodes/20_30-the-ol-raise-and-switch/',
17 'md5': '2fe8eaec69768b25ef898cda9c43062e',
18 'info_dict': {
19 'id': 'afe22e30f01c41f49d4f1d9eab5cd9a4',
20 'ext': 'mp4',
21 'title': 'The Ol’ Raise and Switch!',
22 'description': 'md5:7db77f7107f98ba88401d3adc80ff7af',
23 'timestamp': 1511824728,
24 'upload_date': '20171127',
25 },
26 'add_id': ['LimelightMedia'],
27 }, {
28 # no data-video-title
29 'url': 'https://www.pokemon.com/us/pokemon-episodes/pokemon-movies/pokemon-the-rise-of-darkrai-2008',
30 'info_dict': {
31 'id': '99f3bae270bf4e5097274817239ce9c8',
32 'ext': 'mp4',
33 'title': 'Pokémon: The Rise of Darkrai',
34 'description': 'md5:ea8fbbf942e1e497d54b19025dd57d9d',
35 'timestamp': 1417778347,
36 'upload_date': '20141205',
37 },
38 'add_id': ['LimelightMedia'],
39 'params': {
40 'skip_download': True,
41 },
42 }, {
43 'url': 'http://www.pokemon.com/uk/pokemon-episodes/?play=2e8b5c761f1d4a9286165d7748c1ece2',
44 'only_matching': True,
45 }, {
46 'url': 'http://www.pokemon.com/fr/episodes-pokemon/18_09-un-hiver-inattendu/',
47 'only_matching': True,
48 }, {
49 'url': 'http://www.pokemon.com/de/pokemon-folgen/01_20-bye-bye-smettbo/',
50 'only_matching': True,
51 }]
52
53 def _real_extract(self, url):
54 video_id, display_id = re.match(self._VALID_URL, url).groups()
55 webpage = self._download_webpage(url, video_id or display_id)
56 video_data = extract_attributes(self._search_regex(
57 r'(<[^>]+data-video-id="%s"[^>]*>)' % (video_id if video_id else '[a-z0-9]{32}'),
58 webpage, 'video data element'))
59 video_id = video_data['data-video-id']
60 title = video_data.get('data-video-title') or self._html_search_meta(
61 'pkm-title', webpage, ' title', default=None) or self._search_regex(
62 r'<h1[^>]+\bclass=["\']us-title[^>]+>([^<]+)', webpage, 'title')
63 return {
64 '_type': 'url_transparent',
65 'id': video_id,
66 'url': 'limelight:media:%s' % video_id,
67 'title': title,
68 'description': video_data.get('data-video-summary'),
69 'thumbnail': video_data.get('data-video-poster'),
70 'series': 'Pokémon',
71 'season_number': int_or_none(video_data.get('data-video-season')),
72 'episode': title,
73 'episode_number': int_or_none(video_data.get('data-video-episode')),
74 'ie_key': 'LimelightMedia',
75 }