]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/pokemon.py
[ChangeLog] Actualize
[youtube-dl.git] / 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         },
24         'add_id': ['LimelightMedia'],
25     }, {
26         # no data-video-title
27         'url': 'https://www.pokemon.com/fr/episodes-pokemon/films-pokemon/pokemon-lascension-de-darkrai-2008',
28         'info_dict': {
29             'id': 'dfbaf830d7e54e179837c50c0c6cc0e1',
30             'ext': 'mp4',
31             'title': "Pokémon : L'ascension de Darkrai",
32             'description': 'md5:d1dbc9e206070c3e14a06ff557659fb5',
33         },
34         'add_id': ['LimelightMedia'],
35         'params': {
36             'skip_download': True,
37         },
38     }, {
39         'url': 'http://www.pokemon.com/uk/pokemon-episodes/?play=2e8b5c761f1d4a9286165d7748c1ece2',
40         'only_matching': True,
41     }, {
42         'url': 'http://www.pokemon.com/fr/episodes-pokemon/18_09-un-hiver-inattendu/',
43         'only_matching': True,
44     }, {
45         'url': 'http://www.pokemon.com/de/pokemon-folgen/01_20-bye-bye-smettbo/',
46         'only_matching': True,
47     }]
48
49     def _real_extract(self, url):
50         video_id, display_id = re.match(self._VALID_URL, url).groups()
51         webpage = self._download_webpage(url, video_id or display_id)
52         video_data = extract_attributes(self._search_regex(
53             r'(<[^>]+data-video-id="%s"[^>]*>)' % (video_id if video_id else '[a-z0-9]{32}'),
54             webpage, 'video data element'))
55         video_id = video_data['data-video-id']
56         title = video_data.get('data-video-title') or self._html_search_meta(
57             'pkm-title', webpage, ' title', default=None) or self._search_regex(
58             r'<h1[^>]+\bclass=["\']us-title[^>]+>([^<]+)', webpage, 'title')
59         return {
60             '_type': 'url_transparent',
61             'id': video_id,
62             'url': 'limelight:media:%s' % video_id,
63             'title': title,
64             'description': video_data.get('data-video-summary'),
65             'thumbnail': video_data.get('data-video-poster'),
66             'series': 'Pokémon',
67             'season_number': int_or_none(video_data.get('data-video-season')),
68             'episode': title,
69             'episode_number': int_or_none(video_data.get('data-video-episode')),
70             'ie_key': 'LimelightMedia',
71         }