logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

toongoggles.py (3044B)


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