]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/pokemon.py
[pokemon] Add new extractor(closes #10093)
[yt-dlp.git] / youtube_dl / extractor / pokemon.py
CommitLineData
d73ebac1
RA
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..utils import (
8 extract_attributes,
9 int_or_none,
10)
11
12
13class PokemonIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?pokemon\.com/[a-z]{2}(?:.*?play=(?P<id>[a-z0-9]{32})|/pokemon-episodes/(?P<display_id>[^/?#]+))'
15 _TESTS = [{
16 'url': 'http://www.pokemon.com/us/pokemon-episodes/19_01-from-a-to-z/?play=true',
17 'md5': '9fb209ae3a569aac25de0f5afc4ee08f',
18 'info_dict': {
19 'id': 'd0436c00c3ce4071ac6cee8130ac54a1',
20 'ext': 'mp4',
21 'title': 'From A to Z!',
22 'description': 'Bonnie makes a new friend, Ash runs into an old friend, and a terrifying premonition begins to unfold!',
23 'timestamp': 1460478136,
24 'upload_date': '20160412',
25 },
26 'add_id': ['LimelightMedia']
27 }, {
28 'url': 'http://www.pokemon.com/uk/pokemon-episodes/?play=2e8b5c761f1d4a9286165d7748c1ece2',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 video_id, display_id = re.match(self._VALID_URL, url).groups()
34 webpage = self._download_webpage(url, video_id or display_id)
35 video_data = extract_attributes(self._search_regex(
36 r'(<[^>]+data-video-id="%s"[^>]*>)' % (video_id if video_id else '[a-z0-9]{32}'),
37 webpage, 'video data element'))
38 video_id = video_data['data-video-id']
39 title = video_data['data-video-title']
40 return {
41 '_type': 'url_transparent',
42 'id': video_id,
43 'url': 'limelight:media:%s' % video_id,
44 'title': title,
45 'description': video_data.get('data-video-summary'),
46 'thumbnail': video_data.get('data-video-poster'),
47 'series': 'Pokémon',
48 'season_number': int_or_none(video_data.get('data-video-season')),
49 'episode': title,
50 'episode_number': int_or_none(video_data.get('data-video-episode')),
51 'ie_key': 'LimelightMedia',
52 }