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.

98 lines
3.5 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import (
  5. extract_attributes,
  6. int_or_none,
  7. parse_age_limit,
  8. unescapeHTML,
  9. )
  10. class DiscoveryGoIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?discoverygo\.com/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  12. _TEST = {
  13. 'url': 'https://www.discoverygo.com/love-at-first-kiss/kiss-first-ask-questions-later/',
  14. 'info_dict': {
  15. 'id': '57a33c536b66d1cd0345eeb1',
  16. 'ext': 'mp4',
  17. 'title': 'Kiss First, Ask Questions Later!',
  18. 'description': 'md5:fe923ba34050eae468bffae10831cb22',
  19. 'duration': 2579,
  20. 'series': 'Love at First Kiss',
  21. 'season_number': 1,
  22. 'episode_number': 1,
  23. 'age_limit': 14,
  24. },
  25. }
  26. def _real_extract(self, url):
  27. display_id = self._match_id(url)
  28. webpage = self._download_webpage(url, display_id)
  29. container = extract_attributes(
  30. self._search_regex(
  31. r'(<div[^>]+class=["\']video-player-container[^>]+>)',
  32. webpage, 'video container'))
  33. video = self._parse_json(
  34. unescapeHTML(container.get('data-video') or container.get('data-json')),
  35. display_id)
  36. title = video['name']
  37. stream = video['stream']
  38. STREAM_URL_SUFFIX = 'streamUrl'
  39. formats = []
  40. for stream_kind in ('', 'hds'):
  41. suffix = STREAM_URL_SUFFIX.capitalize() if stream_kind else STREAM_URL_SUFFIX
  42. stream_url = stream.get('%s%s' % (stream_kind, suffix))
  43. if not stream_url:
  44. continue
  45. if stream_kind == '':
  46. formats.extend(self._extract_m3u8_formats(
  47. stream_url, display_id, 'mp4', entry_protocol='m3u8_native',
  48. m3u8_id='hls', fatal=False))
  49. elif stream_kind == 'hds':
  50. formats.extend(self._extract_f4m_formats(
  51. stream_url, display_id, f4m_id=stream_kind, fatal=False))
  52. self._sort_formats(formats)
  53. video_id = video.get('id') or display_id
  54. description = video.get('description', {}).get('detailed')
  55. duration = int_or_none(video.get('duration'))
  56. series = video.get('show', {}).get('name')
  57. season_number = int_or_none(video.get('season', {}).get('number'))
  58. episode_number = int_or_none(video.get('episodeNumber'))
  59. tags = video.get('tags')
  60. age_limit = parse_age_limit(video.get('parental', {}).get('rating'))
  61. subtitles = {}
  62. captions = stream.get('captions')
  63. if isinstance(captions, list):
  64. for caption in captions:
  65. subtitle_url = caption.get('fileUrl')
  66. if (not subtitle_url or not isinstance(subtitle_url, compat_str) or
  67. not subtitle_url.startswith('http')):
  68. continue
  69. lang = caption.get('fileLang', 'en')
  70. subtitles.setdefault(lang, []).append({'url': subtitle_url})
  71. return {
  72. 'id': video_id,
  73. 'display_id': display_id,
  74. 'title': title,
  75. 'description': description,
  76. 'duration': duration,
  77. 'series': series,
  78. 'season_number': season_number,
  79. 'episode_number': episode_number,
  80. 'tags': tags,
  81. 'age_limit': age_limit,
  82. 'formats': formats,
  83. 'subtitles': subtitles,
  84. }