]>
Commit | Line | Data |
---|---|---|
b9c7a973 S |
1 | from __future__ import unicode_literals |
2 | ||
d8873d4d | 3 | import re |
4 | ||
05c7feec | 5 | from .theplatform import ThePlatformIE |
d8873d4d | 6 | from ..utils import ( |
7 | smuggle_url, | |
8 | update_url_query, | |
9 | unescapeHTML, | |
42362fdb | 10 | extract_attributes, |
c58ed856 | 11 | get_element_by_attribute, |
d8873d4d | 12 | ) |
42362fdb RA |
13 | from ..compat import ( |
14 | compat_urlparse, | |
15 | ) | |
16 | ||
17 | ||
05c7feec RA |
18 | class AENetworksBaseIE(ThePlatformIE): |
19 | _THEPLATFORM_KEY = 'crazyjava' | |
20 | _THEPLATFORM_SECRET = 's3cr3t' | |
b9c7a973 S |
21 | |
22 | ||
42362fdb | 23 | class AENetworksIE(AENetworksBaseIE): |
855f90fa S |
24 | IE_NAME = 'aenetworks' |
25 | IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network' | |
95728fda S |
26 | _VALID_URL = r'''(?x) |
27 | https?:// | |
28 | (?:www\.)? | |
29 | (?P<domain> | |
30 | (?:history|aetv|mylifetime|lifetimemovieclub)\.com| | |
31 | fyi\.tv | |
32 | )/ | |
33 | (?: | |
34 | shows/(?P<show_path>[^/]+(?:/[^/]+){0,2})| | |
35 | movies/(?P<movie_display_id>[^/]+)(?:/full-movie)?| | |
36 | specials/(?P<special_display_id>[^/]+)/full-special | |
37 | ) | |
38 | ''' | |
b9c7a973 | 39 | _TESTS = [{ |
52767c1b | 40 | 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1', |
a94e7f4a | 41 | 'md5': 'a97a65f7e823ae10e9244bc5433d5fe6', |
52767c1b | 42 | 'info_dict': { |
42362fdb | 43 | 'id': '22253814', |
52767c1b | 44 | 'ext': 'mp4', |
611c1dd9 | 45 | 'title': 'Winter Is Coming', |
1358b941 | 46 | 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74', |
79ba9140 | 47 | 'timestamp': 1338306241, |
48 | 'upload_date': '20120529', | |
49 | 'uploader': 'AENE-NEW', | |
52767c1b | 50 | }, |
b9c7a973 | 51 | 'add_ie': ['ThePlatform'], |
587dfd44 | 52 | }, { |
42362fdb RA |
53 | 'url': 'http://www.history.com/shows/ancient-aliens/season-1', |
54 | 'info_dict': { | |
55 | 'id': '71889446852', | |
56 | }, | |
57 | 'playlist_mincount': 5, | |
58 | }, { | |
59 | 'url': 'http://www.mylifetime.com/shows/atlanta-plastic', | |
60 | 'info_dict': { | |
61 | 'id': 'SERIES4317', | |
62 | 'title': 'Atlanta Plastic', | |
63 | }, | |
64 | 'playlist_mincount': 2, | |
65 | }, { | |
66 | 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1', | |
587dfd44 | 67 | 'only_matching': True |
68 | }, { | |
42362fdb | 69 | 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8', |
587dfd44 | 70 | 'only_matching': True |
71 | }, { | |
42362fdb | 72 | 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6', |
587dfd44 | 73 | 'only_matching': True |
70157c2c RA |
74 | }, { |
75 | 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie', | |
76 | 'only_matching': True | |
459818e2 A |
77 | }, { |
78 | 'url': 'https://www.lifetimemovieclub.com/movies/a-killer-among-us', | |
79 | 'only_matching': True | |
95728fda S |
80 | }, { |
81 | 'url': 'http://www.history.com/specials/sniper-into-the-kill-zone/full-special', | |
82 | 'only_matching': True | |
b9c7a973 | 83 | }] |
05c7feec RA |
84 | _DOMAIN_TO_REQUESTOR_ID = { |
85 | 'history.com': 'HISTORY', | |
86 | 'aetv.com': 'AETV', | |
87 | 'mylifetime.com': 'LIFETIME', | |
459818e2 | 88 | 'lifetimemovieclub.com': 'LIFETIMEMOVIECLUB', |
05c7feec RA |
89 | 'fyi.tv': 'FYI', |
90 | } | |
b9c7a973 S |
91 | |
92 | def _real_extract(self, url): | |
95728fda S |
93 | domain, show_path, movie_display_id, special_display_id = re.match(self._VALID_URL, url).groups() |
94 | display_id = show_path or movie_display_id or special_display_id | |
42362fdb | 95 | webpage = self._download_webpage(url, display_id) |
70157c2c RA |
96 | if show_path: |
97 | url_parts = show_path.split('/') | |
98 | url_parts_len = len(url_parts) | |
99 | if url_parts_len == 1: | |
100 | entries = [] | |
101 | for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage): | |
102 | entries.append(self.url_result( | |
103 | compat_urlparse.urljoin(url, season_url_path), 'AENetworks')) | |
20783b8b RA |
104 | if entries: |
105 | return self.playlist_result( | |
106 | entries, self._html_search_meta('aetn:SeriesId', webpage), | |
107 | self._html_search_meta('aetn:SeriesTitle', webpage)) | |
108 | else: | |
109 | # single season | |
110 | url_parts_len = 2 | |
111 | if url_parts_len == 2: | |
70157c2c | 112 | entries = [] |
b51a4ebe | 113 | for episode_item in re.findall(r'(?s)<[^>]+class="[^"]*(?:episode|program)-item[^"]*"[^>]*>', webpage): |
70157c2c RA |
114 | episode_attributes = extract_attributes(episode_item) |
115 | episode_url = compat_urlparse.urljoin( | |
116 | url, episode_attributes['data-canonical']) | |
117 | entries.append(self.url_result( | |
118 | episode_url, 'AENetworks', | |
20783b8b | 119 | episode_attributes.get('data-videoid') or episode_attributes.get('data-video-id'))) |
70157c2c RA |
120 | return self.playlist_result( |
121 | entries, self._html_search_meta('aetn:SeasonId', webpage)) | |
05c7feec RA |
122 | |
123 | query = { | |
124 | 'mbr': 'true', | |
a94e7f4a | 125 | 'assetTypes': 'high_video_s3' |
05c7feec | 126 | } |
70157c2c RA |
127 | video_id = self._html_search_meta('aetn:VideoID', webpage) |
128 | media_url = self._search_regex( | |
7f04386b S |
129 | [r"media_url\s*=\s*'(?P<url>[^']+)'", |
130 | r'data-media-url=(?P<url>(?:https?:)?//[^\s>]+)', | |
131 | r'data-media-url=(["\'])(?P<url>(?:(?!\1).)+?)\1'], | |
132 | webpage, 'video url', group='url') | |
05c7feec | 133 | theplatform_metadata = self._download_theplatform_metadata(self._search_regex( |
197224b7 | 134 | r'https?://link\.theplatform\.com/s/([^?]+)', media_url, 'theplatform_path'), video_id) |
05c7feec RA |
135 | info = self._parse_theplatform_metadata(theplatform_metadata) |
136 | if theplatform_metadata.get('AETN$isBehindWall'): | |
137 | requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain] | |
1fd6e309 RA |
138 | resource = self._get_mvpd_resource( |
139 | requestor_id, theplatform_metadata['title'], | |
140 | theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'), | |
141 | theplatform_metadata['ratings'][0]['rating']) | |
05c7feec RA |
142 | query['auth'] = self._extract_mvpd_auth( |
143 | url, video_id, requestor_id, resource) | |
144 | info.update(self._search_json_ld(webpage, video_id, fatal=False)) | |
145 | media_url = update_url_query(media_url, query) | |
146 | media_url = self._sign_url(media_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET) | |
147 | formats, subtitles = self._extract_theplatform_smil(media_url, video_id) | |
148 | self._sort_formats(formats) | |
149 | info.update({ | |
150 | 'id': video_id, | |
151 | 'formats': formats, | |
152 | 'subtitles': subtitles, | |
153 | }) | |
70157c2c | 154 | return info |
b9c7a973 | 155 | |
b9c7a973 | 156 | |
42362fdb RA |
157 | class HistoryTopicIE(AENetworksBaseIE): |
158 | IE_NAME = 'history:topic' | |
159 | IE_DESC = 'History.com Topic' | |
2cb31d28 | 160 | _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)(?:/[^/]+(?:/(?P<video_display_id>[^/?#]+))?)?' |
42362fdb RA |
161 | _TESTS = [{ |
162 | 'url': 'http://www.history.com/topics/valentines-day/history-of-valentines-day/videos/bet-you-didnt-know-valentines-day?m=528e394da93ae&s=undefined&f=1&free=false', | |
163 | 'info_dict': { | |
164 | 'id': '40700995724', | |
165 | 'ext': 'mp4', | |
166 | 'title': "Bet You Didn't Know: Valentine's Day", | |
167 | 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7', | |
168 | 'timestamp': 1375819729, | |
169 | 'upload_date': '20130806', | |
170 | 'uploader': 'AENE-NEW', | |
171 | }, | |
172 | 'params': { | |
173 | # m3u8 download | |
174 | 'skip_download': True, | |
175 | }, | |
176 | 'add_ie': ['ThePlatform'], | |
177 | }, { | |
178 | 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos', | |
179 | 'info_dict': | |
180 | { | |
181 | 'id': 'world-war-i-history', | |
c58ed856 | 182 | 'title': 'World War I History', |
42362fdb | 183 | }, |
a94e7f4a | 184 | 'playlist_mincount': 23, |
42362fdb RA |
185 | }, { |
186 | 'url': 'http://www.history.com/topics/world-war-i-history/videos', | |
187 | 'only_matching': True, | |
2cb31d28 S |
188 | }, { |
189 | 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history', | |
190 | 'only_matching': True, | |
191 | }, { | |
192 | 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/speeches', | |
193 | 'only_matching': True, | |
42362fdb RA |
194 | }] |
195 | ||
05c7feec RA |
196 | def theplatform_url_result(self, theplatform_url, video_id, query): |
197 | return { | |
198 | '_type': 'url_transparent', | |
199 | 'id': video_id, | |
200 | 'url': smuggle_url( | |
201 | update_url_query(theplatform_url, query), | |
202 | { | |
203 | 'sig': { | |
204 | 'key': self._THEPLATFORM_KEY, | |
205 | 'secret': self._THEPLATFORM_SECRET, | |
206 | }, | |
207 | 'force_smil_url': True | |
208 | }), | |
209 | 'ie_key': 'ThePlatform', | |
210 | } | |
211 | ||
42362fdb | 212 | def _real_extract(self, url): |
70157c2c RA |
213 | topic_id, video_display_id = re.match(self._VALID_URL, url).groups() |
214 | if video_display_id: | |
215 | webpage = self._download_webpage(url, video_display_id) | |
42362fdb RA |
216 | release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups() |
217 | release_url = unescapeHTML(release_url) | |
218 | ||
219 | return self.theplatform_url_result( | |
220 | release_url, video_id, { | |
221 | 'mbr': 'true', | |
a94e7f4a RA |
222 | 'switch': 'hls', |
223 | 'assetTypes': 'high_video_ak', | |
42362fdb RA |
224 | }) |
225 | else: | |
226 | webpage = self._download_webpage(url, topic_id) | |
227 | entries = [] | |
228 | for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage): | |
229 | video_attributes = extract_attributes(episode_item) | |
230 | entries.append(self.theplatform_url_result( | |
4c782122 | 231 | video_attributes['data-release-url'], video_attributes['data-id'], { |
42362fdb | 232 | 'mbr': 'true', |
a94e7f4a RA |
233 | 'switch': 'hls', |
234 | 'assetTypes': 'high_video_ak', | |
42362fdb | 235 | })) |
c58ed856 | 236 | return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage)) |