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.

108 lines
3.7 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'''(?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. unescapeHTML(container.get('data-video') or container.get('data-json')),
  45. display_id)
  46. title = video['name']
  47. stream = video['stream']
  48. STREAM_URL_SUFFIX = 'streamUrl'
  49. formats = []
  50. for stream_kind in ('', 'hds'):
  51. suffix = STREAM_URL_SUFFIX.capitalize() if stream_kind else STREAM_URL_SUFFIX
  52. stream_url = stream.get('%s%s' % (stream_kind, suffix))
  53. if not stream_url:
  54. continue
  55. if stream_kind == '':
  56. formats.extend(self._extract_m3u8_formats(
  57. stream_url, display_id, 'mp4', entry_protocol='m3u8_native',
  58. m3u8_id='hls', fatal=False))
  59. elif stream_kind == 'hds':
  60. formats.extend(self._extract_f4m_formats(
  61. stream_url, display_id, f4m_id=stream_kind, fatal=False))
  62. self._sort_formats(formats)
  63. video_id = video.get('id') or display_id
  64. description = video.get('description', {}).get('detailed')
  65. duration = int_or_none(video.get('duration'))
  66. series = video.get('show', {}).get('name')
  67. season_number = int_or_none(video.get('season', {}).get('number'))
  68. episode_number = int_or_none(video.get('episodeNumber'))
  69. tags = video.get('tags')
  70. age_limit = parse_age_limit(video.get('parental', {}).get('rating'))
  71. subtitles = {}
  72. captions = stream.get('captions')
  73. if isinstance(captions, list):
  74. for caption in captions:
  75. subtitle_url = caption.get('fileUrl')
  76. if (not subtitle_url or not isinstance(subtitle_url, compat_str) or
  77. not subtitle_url.startswith('http')):
  78. continue
  79. lang = caption.get('fileLang', 'en')
  80. subtitles.setdefault(lang, []).append({'url': subtitle_url})
  81. return {
  82. 'id': video_id,
  83. 'display_id': display_id,
  84. 'title': title,
  85. 'description': description,
  86. 'duration': duration,
  87. 'series': series,
  88. 'season_number': season_number,
  89. 'episode_number': episode_number,
  90. 'tags': tags,
  91. 'age_limit': age_limit,
  92. 'formats': formats,
  93. 'subtitles': subtitles,
  94. }