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.

116 lines
4.1 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. ExtractorError,
  10. )
  11. class DiscoveryGoIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)https?://(?:www\.)?(?:
  13. discovery|
  14. investigationdiscovery|
  15. discoverylife|
  16. animalplanet|
  17. ahctv|
  18. destinationamerica|
  19. sciencechannel|
  20. tlc|
  21. velocitychannel
  22. )go\.com/(?:[^/]+/)*(?P<id>[^/?#&]+)'''
  23. _TEST = {
  24. 'url': 'https://www.discoverygo.com/love-at-first-kiss/kiss-first-ask-questions-later/',
  25. 'info_dict': {
  26. 'id': '57a33c536b66d1cd0345eeb1',
  27. 'ext': 'mp4',
  28. 'title': 'Kiss First, Ask Questions Later!',
  29. 'description': 'md5:fe923ba34050eae468bffae10831cb22',
  30. 'duration': 2579,
  31. 'series': 'Love at First Kiss',
  32. 'season_number': 1,
  33. 'episode_number': 1,
  34. 'age_limit': 14,
  35. },
  36. }
  37. def _real_extract(self, url):
  38. display_id = self._match_id(url)
  39. webpage = self._download_webpage(url, display_id)
  40. container = extract_attributes(
  41. self._search_regex(
  42. r'(<div[^>]+class=["\']video-player-container[^>]+>)',
  43. webpage, 'video container'))
  44. video = self._parse_json(
  45. unescapeHTML(container.get('data-video') or container.get('data-json')),
  46. display_id)
  47. title = video['name']
  48. stream = video.get('stream')
  49. if not stream:
  50. if video.get('authenticated') is True:
  51. raise ExtractorError(
  52. 'This video is only available via cable service provider subscription that'
  53. ' is not currently supported. You may want to use --cookies.', expected=True)
  54. else:
  55. raise ExtractorError('Unable to find stream')
  56. STREAM_URL_SUFFIX = 'streamUrl'
  57. formats = []
  58. for stream_kind in ('', 'hds'):
  59. suffix = STREAM_URL_SUFFIX.capitalize() if stream_kind else STREAM_URL_SUFFIX
  60. stream_url = stream.get('%s%s' % (stream_kind, suffix))
  61. if not stream_url:
  62. continue
  63. if stream_kind == '':
  64. formats.extend(self._extract_m3u8_formats(
  65. stream_url, display_id, 'mp4', entry_protocol='m3u8_native',
  66. m3u8_id='hls', fatal=False))
  67. elif stream_kind == 'hds':
  68. formats.extend(self._extract_f4m_formats(
  69. stream_url, display_id, f4m_id=stream_kind, fatal=False))
  70. self._sort_formats(formats)
  71. video_id = video.get('id') or display_id
  72. description = video.get('description', {}).get('detailed')
  73. duration = int_or_none(video.get('duration'))
  74. series = video.get('show', {}).get('name')
  75. season_number = int_or_none(video.get('season', {}).get('number'))
  76. episode_number = int_or_none(video.get('episodeNumber'))
  77. tags = video.get('tags')
  78. age_limit = parse_age_limit(video.get('parental', {}).get('rating'))
  79. subtitles = {}
  80. captions = stream.get('captions')
  81. if isinstance(captions, list):
  82. for caption in captions:
  83. subtitle_url = caption.get('fileUrl')
  84. if (not subtitle_url or not isinstance(subtitle_url, compat_str) or
  85. not subtitle_url.startswith('http')):
  86. continue
  87. lang = caption.get('fileLang', 'en')
  88. subtitles.setdefault(lang, []).append({'url': subtitle_url})
  89. return {
  90. 'id': video_id,
  91. 'display_id': display_id,
  92. 'title': title,
  93. 'description': description,
  94. 'duration': duration,
  95. 'series': series,
  96. 'season_number': season_number,
  97. 'episode_number': episode_number,
  98. 'tags': tags,
  99. 'age_limit': age_limit,
  100. 'formats': formats,
  101. 'subtitles': subtitles,
  102. }