1 from __future__ import unicode_literals
5 from .common import InfoExtractor
12 from ..compat import (
17 class AENetworksBaseIE(InfoExtractor):
18 def theplatform_url_result(self, theplatform_url, video_id, query):
20 '_type': 'url_transparent',
23 update_url_query(theplatform_url, query),
29 'force_smil_url': True
31 'ie_key': 'ThePlatform',
35 class AENetworksIE(AENetworksBaseIE):
36 IE_NAME = 'aenetworks'
37 IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network'
38 _VALID_URL = r'https?://(?:www\.)?(?:(?:history|aetv|mylifetime)\.com|fyi\.tv)/shows/(?P<id>[^/]+(?:/[^/]+){0,2})'
40 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
41 'md5': '8ff93eb073449f151d6b90c0ae1ef0c7',
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',
76 def _real_extract(self, url):
77 display_id = self._match_id(url)
78 webpage = self._download_webpage(url, display_id)
79 url_parts = display_id.split('/')
80 url_parts_len = len(url_parts)
81 if url_parts_len == 1:
83 for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
84 entries.append(self.url_result(
85 compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
86 return self.playlist_result(
87 entries, self._html_search_meta('aetn:SeriesId', webpage),
88 self._html_search_meta('aetn:SeriesTitle', webpage))
89 elif url_parts_len == 2:
91 for episode_item in re.findall(r'(?s)<div[^>]+class="[^"]*episode-item[^"]*"[^>]*>', webpage):
92 episode_attributes = extract_attributes(episode_item)
93 episode_url = compat_urlparse.urljoin(
94 url, episode_attributes['data-canonical'])
95 entries.append(self.url_result(
96 episode_url, 'AENetworks',
97 episode_attributes['data-videoid']))
98 return self.playlist_result(
99 entries, self._html_search_meta('aetn:SeasonId', webpage))
101 video_id = self._html_search_meta('aetn:VideoID', webpage)
102 media_url = self._search_regex(
103 r"media_url\s*=\s*'([^']+)'", webpage, 'video url')
105 info = self._search_json_ld(webpage, video_id, fatal=False)
106 info.update(self.theplatform_url_result(
107 media_url, video_id, {
109 'assetTypes': 'medium_video_s3'
114 class HistoryTopicIE(AENetworksBaseIE):
115 IE_NAME = 'history:topic'
116 IE_DESC = 'History.com Topic'
117 _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)/videos(?:/(?P<display_id>[^/?#]+))?'
119 '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',
123 'title': "Bet You Didn't Know: Valentine's Day",
124 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
125 'timestamp': 1375819729,
126 'upload_date': '20130806',
127 'uploader': 'AENE-NEW',
131 'skip_download': True,
133 'add_ie': ['ThePlatform'],
135 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
138 'id': 'world-war-i-history',
140 'playlist_mincount': 24,
142 'url': 'http://www.history.com/topics/world-war-i-history/videos',
143 'only_matching': True,
146 def _real_extract(self, url):
147 topic_id, display_id = re.match(self._VALID_URL, url).groups()
149 webpage = self._download_webpage(url, display_id)
150 release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
151 release_url = unescapeHTML(release_url)
153 return self.theplatform_url_result(
154 release_url, video_id, {
159 webpage = self._download_webpage(url, topic_id)
161 for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
162 video_attributes = extract_attributes(episode_item)
163 entries.append(self.theplatform_url_result(
164 video_attributes['data-href'], video_attributes['data-id'], {
168 return self.playlist_result(entries, topic_id)