cartoonnetwork.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from .turner import TurnerBaseIE
  2. from ..utils import int_or_none
  3. class CartoonNetworkIE(TurnerBaseIE):
  4. _VALID_URL = r'https?://(?:www\.)?cartoonnetwork\.com/video/(?:[^/]+/)+(?P<id>[^/?#]+)-(?:clip|episode)\.html'
  5. _TEST = {
  6. 'url': 'https://www.cartoonnetwork.com/video/ben-10/how-to-draw-upgrade-episode.html',
  7. 'info_dict': {
  8. 'id': '6e3375097f63874ebccec7ef677c1c3845fa850e',
  9. 'ext': 'mp4',
  10. 'title': 'How to Draw Upgrade',
  11. 'description': 'md5:2061d83776db7e8be4879684eefe8c0f',
  12. },
  13. 'params': {
  14. # m3u8 download
  15. 'skip_download': True,
  16. },
  17. }
  18. def _real_extract(self, url):
  19. display_id = self._match_id(url)
  20. webpage = self._download_webpage(url, display_id)
  21. def find_field(global_re, name, content_re=None, value_re='[^"]+', fatal=False):
  22. metadata_re = ''
  23. if content_re:
  24. metadata_re = r'|video_metadata\.content_' + content_re
  25. return self._search_regex(
  26. rf'(?:_cnglobal\.currentVideo\.{global_re}{metadata_re})\s*=\s*"({value_re})";',
  27. webpage, name, fatal=fatal)
  28. media_id = find_field('mediaId', 'media id', 'id', '[0-9a-f]{40}', True)
  29. title = find_field('episodeTitle', 'title', '(?:episodeName|name)', fatal=True)
  30. info = self._extract_ngtv_info(
  31. media_id, {'networkId': 'cartoonnetwork'}, {
  32. 'url': url,
  33. 'site_name': 'CartoonNetwork',
  34. 'auth_required': find_field('authType', 'auth type') != 'unauth',
  35. })
  36. series = find_field(
  37. 'propertyName', 'series', 'showName') or self._html_search_meta('partOfSeries', webpage)
  38. info.update({
  39. 'id': media_id,
  40. 'display_id': display_id,
  41. 'title': title,
  42. 'description': self._html_search_meta('description', webpage),
  43. 'series': series,
  44. 'episode': title,
  45. })
  46. for field in ('season', 'episode'):
  47. field_name = field + 'Number'
  48. info[field + '_number'] = int_or_none(find_field(
  49. field_name, field + ' number', value_re=r'\d+') or self._html_search_meta(field_name, webpage))
  50. return info