toongoggles.py 2.9 KB

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