]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/toongoggles.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / toongoggles.py
CommitLineData
772b5ff5
RA
1from .common import InfoExtractor
2from ..utils import (
3 int_or_none,
4 parse_duration,
5)
6
7
8class ToonGogglesIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?toongoggles\.com/shows/(?P<show_id>\d+)(?:/[^/]+/episodes/(?P<episode_id>\d+))?'
10 _TESTS = [{
11 'url': 'http://www.toongoggles.com/shows/217143/bernard-season-2/episodes/217147/football',
12 'md5': '18289fc2b951eff6b953a9d8f01e6831',
13 'info_dict': {
14 'id': '217147',
15 'ext': 'mp4',
16 'title': 'Football',
17 'uploader_id': '1',
18 'description': 'Bernard decides to play football in order to be better than Lloyd and tries to beat him no matter how, he even cheats.',
19 'upload_date': '20160718',
20 'timestamp': 1468879330,
add96eb9 21 },
772b5ff5
RA
22 }, {
23 'url': 'http://www.toongoggles.com/shows/227759/om-nom-stories-around-the-world',
24 'info_dict': {
25 'id': '227759',
26 'title': 'Om Nom Stories Around The World',
27 },
28 'playlist_mincount': 11,
29 }]
30
31 def _call_api(self, action, page_id, query):
32 query.update({
33 'for_ng': 1,
34 'for_web': 1,
35 'show_meta': 1,
36 'version': 7.0,
37 })
38 return self._download_json('http://api.toongoggles.com/' + action, page_id, query=query)
39
40 def _parse_episode_data(self, episode_data):
41 title = episode_data['episode_name']
42
43 return {
44 '_type': 'url_transparent',
45 'id': episode_data['episode_id'],
46 'title': title,
47 'url': 'kaltura:513551:' + episode_data['entry_id'],
48 'thumbnail': episode_data.get('thumbnail_url'),
49 'description': episode_data.get('description'),
50 'duration': parse_duration(episode_data.get('hms')),
51 'series': episode_data.get('show_name'),
52 'season_number': int_or_none(episode_data.get('season_num')),
53 'episode_id': episode_data.get('episode_id'),
54 'episode': title,
55 'episode_number': int_or_none(episode_data.get('episode_num')),
56 'categories': episode_data.get('categories'),
57 'ie_key': 'Kaltura',
58 }
59
60 def _real_extract(self, url):
5ad28e7f 61 show_id, episode_id = self._match_valid_url(url).groups()
772b5ff5
RA
62 if episode_id:
63 episode_data = self._call_api('search', episode_id, {
64 'filter': 'episode',
65 'id': episode_id,
66 })['objects'][0]
67 return self._parse_episode_data(episode_data)
68 else:
69 show_data = self._call_api('getepisodesbyshow', show_id, {
70 'max': 1000000000,
71 'showid': show_id,
72 })
73 entries = []
74 for episode_data in show_data.get('objects', []):
75 entries.append(self._parse_episode_data(episode_data))
76 return self.playlist_result(entries, show_id, show_data.get('show_name'))