1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_str
17 class DiscoveryGoBaseIE(InfoExtractor):
18 _VALID_URL_TEMPLATE = r'''(?x)https?://(?:www\.)?(?:
20 investigationdiscovery|
28 )go\.com/%s(?P<id>[^/?#&]+)'''
31 class DiscoveryGoIE(DiscoveryGoBaseIE):
32 _VALID_URL = DiscoveryGoBaseIE._VALID_URL_TEMPLATE % r'(?:[^/]+/)+'
34 'url': 'https://www.discoverygo.com/love-at-first-kiss/kiss-first-ask-questions-later/',
36 'id': '57a33c536b66d1cd0345eeb1',
38 'title': 'Kiss First, Ask Questions Later!',
39 'description': 'md5:fe923ba34050eae468bffae10831cb22',
41 'series': 'Love at First Kiss',
48 def _real_extract(self, url):
49 display_id = self._match_id(url)
51 webpage = self._download_webpage(url, display_id)
53 container = extract_attributes(
55 r'(<div[^>]+class=["\']video-player-container[^>]+>)',
56 webpage, 'video container'))
58 video = self._parse_json(
59 container.get('data-video') or container.get('data-json'),
64 stream = video.get('stream')
66 if video.get('authenticated') is True:
68 'This video is only available via cable service provider subscription that'
69 ' is not currently supported. You may want to use --cookies.', expected=True)
71 raise ExtractorError('Unable to find stream')
72 STREAM_URL_SUFFIX = 'streamUrl'
74 for stream_kind in ('', 'hds'):
75 suffix = STREAM_URL_SUFFIX.capitalize() if stream_kind else STREAM_URL_SUFFIX
76 stream_url = stream.get('%s%s' % (stream_kind, suffix))
80 formats.extend(self._extract_m3u8_formats(
81 stream_url, display_id, 'mp4', entry_protocol='m3u8_native',
82 m3u8_id='hls', fatal=False))
83 elif stream_kind == 'hds':
84 formats.extend(self._extract_f4m_formats(
85 stream_url, display_id, f4m_id=stream_kind, fatal=False))
86 self._sort_formats(formats)
88 video_id = video.get('id') or display_id
89 description = video.get('description', {}).get('detailed')
90 duration = int_or_none(video.get('duration'))
92 series = video.get('show', {}).get('name')
93 season_number = int_or_none(video.get('season', {}).get('number'))
94 episode_number = int_or_none(video.get('episodeNumber'))
96 tags = video.get('tags')
97 age_limit = parse_age_limit(video.get('parental', {}).get('rating'))
100 captions = stream.get('captions')
101 if isinstance(captions, list):
102 for caption in captions:
103 subtitle_url = caption.get('fileUrl')
104 if (not subtitle_url or not isinstance(subtitle_url, compat_str) or
105 not subtitle_url.startswith('http')):
107 lang = caption.get('fileLang', 'en')
108 subtitles.setdefault(lang, []).append({'url': subtitle_url})
112 'display_id': display_id,
114 'description': description,
115 'duration': duration,
117 'season_number': season_number,
118 'episode_number': episode_number,
120 'age_limit': age_limit,
122 'subtitles': subtitles,
126 class DiscoveryGoPlaylistIE(DiscoveryGoBaseIE):
127 _VALID_URL = DiscoveryGoBaseIE._VALID_URL_TEMPLATE % ''
129 'url': 'https://www.discoverygo.com/bering-sea-gold/',
131 'id': 'bering-sea-gold',
132 'title': 'Bering Sea Gold',
133 'description': 'md5:cc5c6489835949043c0cc3ad66c2fa0e',
135 'playlist_mincount': 6,
139 def suitable(cls, url):
140 return False if DiscoveryGoIE.suitable(url) else super(
141 DiscoveryGoPlaylistIE, cls).suitable(url)
143 def _real_extract(self, url):
144 display_id = self._match_id(url)
146 webpage = self._download_webpage(url, display_id)
149 for mobj in re.finditer(r'data-json=(["\'])(?P<json>{.+?})\1', webpage):
150 data = self._parse_json(
151 mobj.group('json'), display_id,
152 transform_source=unescapeHTML, fatal=False)
153 if not isinstance(data, dict) or data.get('type') != 'episode':
155 episode_url = data.get('socialUrl')
158 entries.append(self.url_result(
159 episode_url, ie=DiscoveryGoIE.ie_key(),
160 video_id=data.get('id')))
162 return self.playlist_result(
164 remove_end(self._og_search_title(
165 webpage, fatal=False), ' | Discovery GO'),
166 self._og_search_description(webpage))