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'
30 (?:history|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
40 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
41 'md5': 'a97a65f7e823ae10e9244bc5433d5fe6',
45 'title': 'Winter Is Coming',
46 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74',
47 'timestamp': 1338306241,
48 'upload_date': '20120529',
49 'uploader': 'AENE-NEW',
51 'add_ie': ['ThePlatform'],
53 'url': 'http://www.history.com/shows/ancient-aliens/season-1',
57 'playlist_mincount': 5,
59 'url': 'http://www.mylifetime.com/shows/atlanta-plastic',
62 'title': 'Atlanta Plastic',
64 'playlist_mincount': 2,
66 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1',
69 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8',
72 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6',
75 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie',
78 'url': 'https://www.lifetimemovieclub.com/movies/a-killer-among-us',
81 'url': 'http://www.history.com/specials/sniper-into-the-kill-zone/full-special',
84 _DOMAIN_TO_REQUESTOR_ID = {
85 'history.com': 'HISTORY',
87 'mylifetime.com': 'LIFETIME',
88 'lifetimemovieclub.com': 'LIFETIMEMOVIECLUB',
92 def _real_extract(self, url):
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
95 webpage = self._download_webpage(url, display_id)
97 url_parts = show_path.split('/')
98 url_parts_len = len(url_parts)
99 if url_parts_len == 1:
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'))
105 return self.playlist_result(
106 entries, self._html_search_meta('aetn:SeriesId', webpage),
107 self._html_search_meta('aetn:SeriesTitle', webpage))
111 if url_parts_len == 2:
113 for episode_item in re.findall(r'(?s)<[^>]+class="[^"]*(?:episode|program)-item[^"]*"[^>]*>', webpage):
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',
119 episode_attributes.get('data-videoid') or episode_attributes.get('data-video-id')))
120 return self.playlist_result(
121 entries, self._html_search_meta('aetn:SeasonId', webpage))
125 'assetTypes': 'high_video_s3'
127 video_id = self._html_search_meta('aetn:VideoID', webpage)
128 media_url = self._search_regex(
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')
133 theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
134 r'https?://link.theplatform.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
135 info = self._parse_theplatform_metadata(theplatform_metadata)
136 if theplatform_metadata.get('AETN$isBehindWall'):
137 requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain]
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'])
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)
152 'subtitles': subtitles,
157 class HistoryTopicIE(AENetworksBaseIE):
158 IE_NAME = 'history:topic'
159 IE_DESC = 'History.com Topic'
160 _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)(?:/[^/]+(?:/(?P<video_display_id>[^/?#]+))?)?'
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',
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',
174 'skip_download': True,
176 'add_ie': ['ThePlatform'],
178 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
181 'id': 'world-war-i-history',
182 'title': 'World War I History',
184 'playlist_mincount': 23,
186 'url': 'http://www.history.com/topics/world-war-i-history/videos',
187 'only_matching': True,
189 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history',
190 'only_matching': True,
192 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/speeches',
193 'only_matching': True,
196 def theplatform_url_result(self, theplatform_url, video_id, query):
198 '_type': 'url_transparent',
201 update_url_query(theplatform_url, query),
204 'key': self._THEPLATFORM_KEY,
205 'secret': self._THEPLATFORM_SECRET,
207 'force_smil_url': True
209 'ie_key': 'ThePlatform',
212 def _real_extract(self, url):
213 topic_id, video_display_id = re.match(self._VALID_URL, url).groups()
215 webpage = self._download_webpage(url, video_display_id)
216 release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
217 release_url = unescapeHTML(release_url)
219 return self.theplatform_url_result(
220 release_url, video_id, {
223 'assetTypes': 'high_video_ak',
226 webpage = self._download_webpage(url, topic_id)
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(
231 video_attributes['data-release-url'], video_attributes['data-id'], {
234 'assetTypes': 'high_video_ak',
236 return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))