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.

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