1 from __future__ import unicode_literals
5 from .theplatform import ThePlatformIE
11 get_element_by_attribute,
13 from ..compat import (
18 class AENetworksBaseIE(ThePlatformIE):
19 _THEPLATFORM_KEY = 'crazyjava'
20 _THEPLATFORM_SECRET = 's3cr3t'
23 class AENetworksIE(AENetworksBaseIE):
24 IE_NAME = 'aenetworks'
25 IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network and History Vault'
30 (?:history(?:vault)?|aetv|mylifetime|lifetimemovieclub)\.com|
34 shows/(?P<show_path>[^/]+(?:/[^/]+){0,2})|
35 movies/(?P<movie_display_id>[^/]+)(?:/full-movie)?|
36 specials/(?P<special_display_id>[^/]+)/full-special|
37 collections/[^/]+/(?P<collection_display_id>[^/]+)
41 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
42 'md5': 'a97a65f7e823ae10e9244bc5433d5fe6',
46 'title': 'Winter Is Coming',
47 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74',
48 'timestamp': 1338306241,
49 'upload_date': '20120529',
50 'uploader': 'AENE-NEW',
52 'add_ie': ['ThePlatform'],
54 'url': 'http://www.history.com/shows/ancient-aliens/season-1',
58 'playlist_mincount': 5,
60 'url': 'http://www.mylifetime.com/shows/atlanta-plastic',
63 'title': 'Atlanta Plastic',
65 'playlist_mincount': 2,
67 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1',
70 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8',
73 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6',
76 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie',
79 'url': 'https://www.lifetimemovieclub.com/movies/a-killer-among-us',
82 'url': 'http://www.history.com/specials/sniper-into-the-kill-zone/full-special',
85 'url': 'https://www.historyvault.com/collections/america-the-story-of-us/westward',
88 _DOMAIN_TO_REQUESTOR_ID = {
89 'history.com': 'HISTORY',
91 'mylifetime.com': 'LIFETIME',
92 'lifetimemovieclub.com': 'LIFETIMEMOVIECLUB',
96 def _real_extract(self, url):
97 domain, show_path, movie_display_id, special_display_id, collection_display_id = re.match(self._VALID_URL, url).groups()
98 display_id = show_path or movie_display_id or special_display_id or collection_display_id
99 webpage = self._download_webpage(url, display_id, headers=self.geo_verification_headers())
101 url_parts = show_path.split('/')
102 url_parts_len = len(url_parts)
103 if url_parts_len == 1:
105 for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
106 entries.append(self.url_result(
107 compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
109 return self.playlist_result(
110 entries, self._html_search_meta('aetn:SeriesId', webpage),
111 self._html_search_meta('aetn:SeriesTitle', webpage))
115 if url_parts_len == 2:
117 for episode_item in re.findall(r'(?s)<[^>]+class="[^"]*(?:episode|program)-item[^"]*"[^>]*>', webpage):
118 episode_attributes = extract_attributes(episode_item)
119 episode_url = compat_urlparse.urljoin(
120 url, episode_attributes['data-canonical'])
121 entries.append(self.url_result(
122 episode_url, 'AENetworks',
123 episode_attributes.get('data-videoid') or episode_attributes.get('data-video-id')))
124 return self.playlist_result(
125 entries, self._html_search_meta('aetn:SeasonId', webpage))
129 'assetTypes': 'high_video_ak',
130 'switch': 'hls_high_ak',
132 video_id = self._html_search_meta('aetn:VideoID', webpage)
133 media_url = self._search_regex(
134 [r"media_url\s*=\s*'(?P<url>[^']+)'",
135 r'data-media-url=(?P<url>(?:https?:)?//[^\s>]+)',
136 r'data-media-url=(["\'])(?P<url>(?:(?!\1).)+?)\1'],
137 webpage, 'video url', group='url')
138 theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
139 r'https?://link\.theplatform\.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
140 info = self._parse_theplatform_metadata(theplatform_metadata)
141 if theplatform_metadata.get('AETN$isBehindWall'):
142 requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain]
143 resource = self._get_mvpd_resource(
144 requestor_id, theplatform_metadata['title'],
145 theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'),
146 theplatform_metadata['ratings'][0]['rating'])
147 query['auth'] = self._extract_mvpd_auth(
148 url, video_id, requestor_id, resource)
149 info.update(self._search_json_ld(webpage, video_id, fatal=False))
150 media_url = update_url_query(media_url, query)
151 media_url = self._sign_url(media_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
152 formats, subtitles = self._extract_theplatform_smil(media_url, video_id)
153 self._sort_formats(formats)
157 'subtitles': subtitles,
162 class HistoryTopicIE(AENetworksBaseIE):
163 IE_NAME = 'history:topic'
164 IE_DESC = 'History.com Topic'
165 _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)(?:/[^/]+(?:/(?P<video_display_id>[^/?#]+))?)?'
167 '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',
171 'title': "Bet You Didn't Know: Valentine's Day",
172 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
173 'timestamp': 1375819729,
174 'upload_date': '20130806',
175 'uploader': 'AENE-NEW',
179 'skip_download': True,
181 'add_ie': ['ThePlatform'],
183 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
186 'id': 'world-war-i-history',
187 'title': 'World War I History',
189 'playlist_mincount': 23,
191 'url': 'http://www.history.com/topics/world-war-i-history/videos',
192 'only_matching': True,
194 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history',
195 'only_matching': True,
197 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/speeches',
198 'only_matching': True,
201 def theplatform_url_result(self, theplatform_url, video_id, query):
203 '_type': 'url_transparent',
206 update_url_query(theplatform_url, query),
209 'key': self._THEPLATFORM_KEY,
210 'secret': self._THEPLATFORM_SECRET,
212 'force_smil_url': True
214 'ie_key': 'ThePlatform',
217 def _real_extract(self, url):
218 topic_id, video_display_id = re.match(self._VALID_URL, url).groups()
220 webpage = self._download_webpage(url, video_display_id)
221 release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
222 release_url = unescapeHTML(release_url)
224 return self.theplatform_url_result(
225 release_url, video_id, {
228 'assetTypes': 'high_video_ak',
231 webpage = self._download_webpage(url, topic_id)
233 for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
234 video_attributes = extract_attributes(episode_item)
235 entries.append(self.theplatform_url_result(
236 video_attributes['data-release-url'], video_attributes['data-id'], {
239 'assetTypes': 'high_video_ak',
241 return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))