]>
Commit | Line | Data |
---|---|---|
05c7feec | 1 | from .theplatform import ThePlatformIE |
d8873d4d | 2 | from ..utils import ( |
4f1e02ad | 3 | ExtractorError, |
29f7c58a | 4 | GeoRestrictedError, |
4f1e02ad | 5 | int_or_none, |
d8873d4d | 6 | update_url_query, |
29f7c58a | 7 | urlencode_postdata, |
42362fdb RA |
8 | ) |
9 | ||
10 | ||
6368e2e6 | 11 | class AENetworksBaseIE(ThePlatformIE): # XXX: Do not subclass from concrete IE |
29f7c58a | 12 | _BASE_URL_REGEX = r'''(?x)https?:// |
13 | (?:(?:www|play|watch)\.)? | |
14 | (?P<domain> | |
15 | (?:history(?:vault)?|aetv|mylifetime|lifetimemovieclub)\.com| | |
16 | fyi\.tv | |
17 | )/''' | |
3b34e388 W |
18 | _THEPLATFORM_KEY = '43jXaGRQud' |
19 | _THEPLATFORM_SECRET = 'S10BPXHMlb' | |
29f7c58a | 20 | _DOMAIN_MAP = { |
21 | 'history.com': ('HISTORY', 'history'), | |
22 | 'aetv.com': ('AETV', 'aetv'), | |
23 | 'mylifetime.com': ('LIFETIME', 'lifetime'), | |
24 | 'lifetimemovieclub.com': ('LIFETIMEMOVIECLUB', 'lmc'), | |
25 | 'fyi.tv': ('FYI', 'fyi'), | |
26 | 'historyvault.com': (None, 'historyvault'), | |
27 | 'biography.com': (None, 'biography'), | |
28 | } | |
b9c7a973 | 29 | |
4f1e02ad | 30 | def _extract_aen_smil(self, smil_url, video_id, auth=None): |
1cddfdc5 JT |
31 | query = { |
32 | 'mbr': 'true', | |
33 | 'formats': 'M3U+none,MPEG-DASH+none,MPEG4,MP3', | |
34 | } | |
4f1e02ad RA |
35 | if auth: |
36 | query['auth'] = auth | |
37 | TP_SMIL_QUERY = [{ | |
38 | 'assetTypes': 'high_video_ak', | |
1cddfdc5 | 39 | 'switch': 'hls_high_ak', |
4f1e02ad | 40 | }, { |
1cddfdc5 | 41 | 'assetTypes': 'high_video_s3', |
4f1e02ad RA |
42 | }, { |
43 | 'assetTypes': 'high_video_s3', | |
29f7c58a | 44 | 'switch': 'hls_high_fastly', |
4f1e02ad RA |
45 | }] |
46 | formats = [] | |
47 | subtitles = {} | |
48 | last_e = None | |
49 | for q in TP_SMIL_QUERY: | |
50 | q.update(query) | |
51 | m_url = update_url_query(smil_url, q) | |
52 | m_url = self._sign_url(m_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET) | |
53 | try: | |
54 | tp_formats, tp_subtitles = self._extract_theplatform_smil( | |
55 | m_url, video_id, 'Downloading %s SMIL data' % (q.get('switch') or q['assetTypes'])) | |
56 | except ExtractorError as e: | |
29f7c58a | 57 | if isinstance(e, GeoRestrictedError): |
58 | raise | |
4f1e02ad RA |
59 | last_e = e |
60 | continue | |
61 | formats.extend(tp_formats) | |
62 | subtitles = self._merge_subtitles(subtitles, tp_subtitles) | |
63 | if last_e and not formats: | |
64 | raise last_e | |
4f1e02ad RA |
65 | return { |
66 | 'id': video_id, | |
67 | 'formats': formats, | |
68 | 'subtitles': subtitles, | |
69 | } | |
70 | ||
29f7c58a | 71 | def _extract_aetn_info(self, domain, filter_key, filter_value, url): |
72 | requestor_id, brand = self._DOMAIN_MAP[domain] | |
73 | result = self._download_json( | |
74 | 'https://feeds.video.aetnd.com/api/v2/%s/videos' % brand, | |
75 | filter_value, query={'filter[%s]' % filter_key: filter_value})['results'][0] | |
76 | title = result['title'] | |
77 | video_id = result['id'] | |
78 | media_url = result['publicUrl'] | |
79 | theplatform_metadata = self._download_theplatform_metadata(self._search_regex( | |
80 | r'https?://link\.theplatform\.com/s/([^?]+)', media_url, 'theplatform_path'), video_id) | |
81 | info = self._parse_theplatform_metadata(theplatform_metadata) | |
82 | auth = None | |
83 | if theplatform_metadata.get('AETN$isBehindWall'): | |
84 | resource = self._get_mvpd_resource( | |
85 | requestor_id, theplatform_metadata['title'], | |
86 | theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'), | |
87 | theplatform_metadata['ratings'][0]['rating']) | |
88 | auth = self._extract_mvpd_auth( | |
89 | url, video_id, requestor_id, resource) | |
90 | info.update(self._extract_aen_smil(media_url, video_id, auth)) | |
91 | info.update({ | |
92 | 'title': title, | |
93 | 'series': result.get('seriesName'), | |
94 | 'season_number': int_or_none(result.get('tvSeasonNumber')), | |
95 | 'episode_number': int_or_none(result.get('tvSeasonEpisodeNumber')), | |
96 | }) | |
97 | return info | |
98 | ||
b9c7a973 | 99 | |
42362fdb | 100 | class AENetworksIE(AENetworksBaseIE): |
855f90fa | 101 | IE_NAME = 'aenetworks' |
3ad6dabd | 102 | IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network and History Vault' |
29f7c58a | 103 | _VALID_URL = AENetworksBaseIE._BASE_URL_REGEX + r'''(?P<id> |
104 | shows/[^/]+/season-\d+/episode-\d+| | |
105 | (?: | |
106 | (?:movie|special)s/[^/]+| | |
107 | (?:shows/[^/]+/)?videos | |
108 | )/[^/?#&]+ | |
109 | )''' | |
b9c7a973 | 110 | _TESTS = [{ |
52767c1b | 111 | 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1', |
112 | 'info_dict': { | |
42362fdb | 113 | 'id': '22253814', |
52767c1b | 114 | 'ext': 'mp4', |
4f1e02ad | 115 | 'title': 'Winter is Coming', |
1358b941 | 116 | 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74', |
79ba9140 | 117 | 'timestamp': 1338306241, |
118 | 'upload_date': '20120529', | |
119 | 'uploader': 'AENE-NEW', | |
52767c1b | 120 | }, |
4f1e02ad RA |
121 | 'params': { |
122 | # m3u8 download | |
123 | 'skip_download': True, | |
124 | }, | |
b9c7a973 | 125 | 'add_ie': ['ThePlatform'], |
29f7c58a | 126 | 'skip': 'This video is only available for users of participating TV providers.', |
587dfd44 | 127 | }, { |
29f7c58a | 128 | 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1', |
42362fdb | 129 | 'info_dict': { |
29f7c58a | 130 | 'id': '600587331957', |
131 | 'ext': 'mp4', | |
132 | 'title': 'Inlawful Entry', | |
133 | 'description': 'md5:57c12115a2b384d883fe64ca50529e08', | |
134 | 'timestamp': 1452634428, | |
135 | 'upload_date': '20160112', | |
136 | 'uploader': 'AENE-NEW', | |
42362fdb | 137 | }, |
29f7c58a | 138 | 'params': { |
139 | # m3u8 download | |
140 | 'skip_download': True, | |
42362fdb | 141 | }, |
29f7c58a | 142 | 'add_ie': ['ThePlatform'], |
587dfd44 | 143 | }, { |
42362fdb | 144 | 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8', |
587dfd44 | 145 | 'only_matching': True |
146 | }, { | |
42362fdb | 147 | 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6', |
587dfd44 | 148 | 'only_matching': True |
70157c2c RA |
149 | }, { |
150 | 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie', | |
151 | 'only_matching': True | |
459818e2 | 152 | }, { |
29f7c58a | 153 | 'url': 'https://watch.lifetimemovieclub.com/movies/10-year-reunion/full-movie', |
459818e2 | 154 | 'only_matching': True |
95728fda S |
155 | }, { |
156 | 'url': 'http://www.history.com/specials/sniper-into-the-kill-zone/full-special', | |
157 | 'only_matching': True | |
3ad6dabd | 158 | }, { |
29f7c58a | 159 | 'url': 'https://www.aetv.com/specials/hunting-jonbenets-killer-the-untold-story/preview-hunting-jonbenets-killer-the-untold-story', |
160 | 'only_matching': True | |
161 | }, { | |
162 | 'url': 'http://www.history.com/videos/history-of-valentines-day', | |
3ad6dabd | 163 | 'only_matching': True |
4f1e02ad | 164 | }, { |
29f7c58a | 165 | 'url': 'https://play.aetv.com/shows/duck-dynasty/videos/best-of-duck-dynasty-getting-quack-in-shape', |
4f1e02ad | 166 | 'only_matching': True |
b9c7a973 S |
167 | }] |
168 | ||
169 | def _real_extract(self, url): | |
5ad28e7f | 170 | domain, canonical = self._match_valid_url(url).groups() |
29f7c58a | 171 | return self._extract_aetn_info(domain, 'canonical', '/' + canonical, url) |
172 | ||
173 | ||
174 | class AENetworksListBaseIE(AENetworksBaseIE): | |
175 | def _call_api(self, resource, slug, brand, fields): | |
176 | return self._download_json( | |
177 | 'https://yoga.appsvcs.aetnd.com/graphql', | |
178 | slug, query={'brand': brand}, data=urlencode_postdata({ | |
179 | 'query': '''{ | |
180 | %s(slug: "%s") { | |
181 | %s | |
182 | } | |
183 | }''' % (resource, slug, fields), | |
184 | }))['data'][resource] | |
185 | ||
186 | def _real_extract(self, url): | |
5ad28e7f | 187 | domain, slug = self._match_valid_url(url).groups() |
29f7c58a | 188 | _, brand = self._DOMAIN_MAP[domain] |
189 | playlist = self._call_api(self._RESOURCE, slug, brand, self._FIELDS) | |
190 | base_url = 'http://watch.%s' % domain | |
191 | ||
192 | entries = [] | |
193 | for item in (playlist.get(self._ITEMS_KEY) or []): | |
194 | doc = self._get_doc(item) | |
195 | canonical = doc.get('canonical') | |
196 | if not canonical: | |
197 | continue | |
198 | entries.append(self.url_result( | |
199 | base_url + canonical, AENetworksIE.ie_key(), doc.get('id'))) | |
200 | ||
201 | description = None | |
202 | if self._PLAYLIST_DESCRIPTION_KEY: | |
203 | description = playlist.get(self._PLAYLIST_DESCRIPTION_KEY) | |
204 | ||
205 | return self.playlist_result( | |
206 | entries, playlist.get('id'), | |
207 | playlist.get(self._PLAYLIST_TITLE_KEY), description) | |
208 | ||
209 | ||
210 | class AENetworksCollectionIE(AENetworksListBaseIE): | |
211 | IE_NAME = 'aenetworks:collection' | |
212 | _VALID_URL = AENetworksBaseIE._BASE_URL_REGEX + r'(?:[^/]+/)*(?:list|collections)/(?P<id>[^/?#&]+)/?(?:[?#&]|$)' | |
213 | _TESTS = [{ | |
214 | 'url': 'https://watch.historyvault.com/list/america-the-story-of-us', | |
215 | 'info_dict': { | |
216 | 'id': '282', | |
217 | 'title': 'America The Story of Us', | |
218 | }, | |
219 | 'playlist_mincount': 12, | |
220 | }, { | |
221 | 'url': 'https://watch.historyvault.com/shows/america-the-story-of-us-2/season-1/list/america-the-story-of-us', | |
222 | 'only_matching': True | |
223 | }, { | |
224 | 'url': 'https://www.historyvault.com/collections/mysteryquest', | |
225 | 'only_matching': True | |
226 | }] | |
227 | _RESOURCE = 'list' | |
228 | _ITEMS_KEY = 'items' | |
229 | _PLAYLIST_TITLE_KEY = 'display_title' | |
230 | _PLAYLIST_DESCRIPTION_KEY = None | |
231 | _FIELDS = '''id | |
232 | display_title | |
233 | items { | |
234 | ... on ListVideoItem { | |
235 | doc { | |
236 | canonical | |
237 | id | |
238 | } | |
239 | } | |
240 | }''' | |
241 | ||
242 | def _get_doc(self, item): | |
243 | return item.get('doc') or {} | |
244 | ||
245 | ||
246 | class AENetworksShowIE(AENetworksListBaseIE): | |
247 | IE_NAME = 'aenetworks:show' | |
248 | _VALID_URL = AENetworksBaseIE._BASE_URL_REGEX + r'shows/(?P<id>[^/?#&]+)/?(?:[?#&]|$)' | |
249 | _TESTS = [{ | |
250 | 'url': 'http://www.history.com/shows/ancient-aliens', | |
251 | 'info_dict': { | |
2181983a | 252 | 'id': 'SERIES1574', |
29f7c58a | 253 | 'title': 'Ancient Aliens', |
254 | 'description': 'md5:3f6d74daf2672ff3ae29ed732e37ea7f', | |
255 | }, | |
a820dc72 | 256 | 'playlist_mincount': 150, |
29f7c58a | 257 | }] |
258 | _RESOURCE = 'series' | |
259 | _ITEMS_KEY = 'episodes' | |
260 | _PLAYLIST_TITLE_KEY = 'title' | |
261 | _PLAYLIST_DESCRIPTION_KEY = 'description' | |
262 | _FIELDS = '''description | |
263 | id | |
264 | title | |
265 | episodes { | |
266 | canonical | |
267 | id | |
268 | }''' | |
269 | ||
270 | def _get_doc(self, item): | |
271 | return item | |
b9c7a973 | 272 | |
b9c7a973 | 273 | |
42362fdb RA |
274 | class HistoryTopicIE(AENetworksBaseIE): |
275 | IE_NAME = 'history:topic' | |
276 | IE_DESC = 'History.com Topic' | |
4f1e02ad | 277 | _VALID_URL = r'https?://(?:www\.)?history\.com/topics/[^/]+/(?P<id>[\w+-]+?)-video' |
42362fdb | 278 | _TESTS = [{ |
4f1e02ad | 279 | 'url': 'https://www.history.com/topics/valentines-day/history-of-valentines-day-video', |
42362fdb RA |
280 | 'info_dict': { |
281 | 'id': '40700995724', | |
282 | 'ext': 'mp4', | |
4f1e02ad | 283 | 'title': "History of Valentine’s Day", |
42362fdb RA |
284 | 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7', |
285 | 'timestamp': 1375819729, | |
286 | 'upload_date': '20130806', | |
29f7c58a | 287 | 'uploader': 'AENE-NEW', |
42362fdb RA |
288 | }, |
289 | 'params': { | |
290 | # m3u8 download | |
291 | 'skip_download': True, | |
292 | }, | |
293 | 'add_ie': ['ThePlatform'], | |
42362fdb RA |
294 | }] |
295 | ||
29f7c58a | 296 | def _real_extract(self, url): |
297 | display_id = self._match_id(url) | |
298 | return self.url_result( | |
299 | 'http://www.history.com/videos/' + display_id, | |
300 | AENetworksIE.ie_key()) | |
301 | ||
302 | ||
303 | class HistoryPlayerIE(AENetworksBaseIE): | |
304 | IE_NAME = 'history:player' | |
305 | _VALID_URL = r'https?://(?:www\.)?(?P<domain>(?:history|biography)\.com)/player/(?P<id>\d+)' | |
29f7c58a | 306 | |
307 | def _real_extract(self, url): | |
5ad28e7f | 308 | domain, video_id = self._match_valid_url(url).groups() |
29f7c58a | 309 | return self._extract_aetn_info(domain, 'id', video_id, url) |
310 | ||
311 | ||
312 | class BiographyIE(AENetworksBaseIE): | |
313 | _VALID_URL = r'https?://(?:www\.)?biography\.com/video/(?P<id>[^/?#&]+)' | |
314 | _TESTS = [{ | |
315 | 'url': 'https://www.biography.com/video/vincent-van-gogh-full-episode-2075049808', | |
316 | 'info_dict': { | |
317 | 'id': '30322987', | |
318 | 'ext': 'mp4', | |
319 | 'title': 'Vincent Van Gogh - Full Episode', | |
320 | 'description': 'A full biography about the most influential 20th century painter, Vincent Van Gogh.', | |
321 | 'timestamp': 1311970571, | |
322 | 'upload_date': '20110729', | |
323 | 'uploader': 'AENE-NEW', | |
324 | }, | |
325 | 'params': { | |
326 | # m3u8 download | |
327 | 'skip_download': True, | |
328 | }, | |
329 | 'add_ie': ['ThePlatform'], | |
330 | }] | |
05c7feec | 331 | |
42362fdb | 332 | def _real_extract(self, url): |
4f1e02ad RA |
333 | display_id = self._match_id(url) |
334 | webpage = self._download_webpage(url, display_id) | |
29f7c58a | 335 | player_url = self._search_regex( |
336 | r'<phoenix-iframe[^>]+src="(%s)' % HistoryPlayerIE._VALID_URL, | |
337 | webpage, 'player URL') | |
338 | return self.url_result(player_url, HistoryPlayerIE.ie_key()) |