You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

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