]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/toongoggles.py
debian/control: Verify compliance with Policy 4.1.4 (no changes needed).
[youtubedl] / youtube_dl / extractor / toongoggles.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 int_or_none,
9 parse_duration,
10 )
11
12
13 class ToonGogglesIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?toongoggles\.com/shows/(?P<show_id>\d+)(?:/[^/]+/episodes/(?P<episode_id>\d+))?'
15 _TESTS = [{
16 'url': 'http://www.toongoggles.com/shows/217143/bernard-season-2/episodes/217147/football',
17 'md5': '18289fc2b951eff6b953a9d8f01e6831',
18 'info_dict': {
19 'id': '217147',
20 'ext': 'mp4',
21 'title': 'Football',
22 'uploader_id': '1',
23 'description': 'Bernard decides to play football in order to be better than Lloyd and tries to beat him no matter how, he even cheats.',
24 'upload_date': '20160718',
25 'timestamp': 1468879330,
26 }
27 }, {
28 'url': 'http://www.toongoggles.com/shows/227759/om-nom-stories-around-the-world',
29 'info_dict': {
30 'id': '227759',
31 'title': 'Om Nom Stories Around The World',
32 },
33 'playlist_mincount': 11,
34 }]
35
36 def _call_api(self, action, page_id, query):
37 query.update({
38 'for_ng': 1,
39 'for_web': 1,
40 'show_meta': 1,
41 'version': 7.0,
42 })
43 return self._download_json('http://api.toongoggles.com/' + action, page_id, query=query)
44
45 def _parse_episode_data(self, episode_data):
46 title = episode_data['episode_name']
47
48 return {
49 '_type': 'url_transparent',
50 'id': episode_data['episode_id'],
51 'title': title,
52 'url': 'kaltura:513551:' + episode_data['entry_id'],
53 'thumbnail': episode_data.get('thumbnail_url'),
54 'description': episode_data.get('description'),
55 'duration': parse_duration(episode_data.get('hms')),
56 'series': episode_data.get('show_name'),
57 'season_number': int_or_none(episode_data.get('season_num')),
58 'episode_id': episode_data.get('episode_id'),
59 'episode': title,
60 'episode_number': int_or_none(episode_data.get('episode_num')),
61 'categories': episode_data.get('categories'),
62 'ie_key': 'Kaltura',
63 }
64
65 def _real_extract(self, url):
66 show_id, episode_id = re.match(self._VALID_URL, url).groups()
67 if episode_id:
68 episode_data = self._call_api('search', episode_id, {
69 'filter': 'episode',
70 'id': episode_id,
71 })['objects'][0]
72 return self._parse_episode_data(episode_data)
73 else:
74 show_data = self._call_api('getepisodesbyshow', show_id, {
75 'max': 1000000000,
76 'showid': show_id,
77 })
78 entries = []
79 for episode_data in show_data.get('objects', []):
80 entries.append(self._parse_episode_data(episode_data))
81 return self.playlist_result(entries, show_id, show_data.get('show_name'))