1 from __future__ import unicode_literals
5 from .common import InfoExtractor
11 get_element_by_attribute,
13 from ..compat import (
18 class AENetworksBaseIE(InfoExtractor):
19 def theplatform_url_result(self, theplatform_url, video_id, query):
21 '_type': 'url_transparent',
24 update_url_query(theplatform_url, query),
30 'force_smil_url': True
32 'ie_key': 'ThePlatform',
36 class AENetworksIE(AENetworksBaseIE):
37 IE_NAME = 'aenetworks'
38 IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network'
39 _VALID_URL = r'https?://(?:www\.)?(?:(?:history|aetv|mylifetime)\.com|fyi\.tv)/shows/(?P<id>[^/]+(?:/[^/]+){0,2})'
41 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
42 'md5': '8ff93eb073449f151d6b90c0ae1ef0c7',
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',
77 def _real_extract(self, url):
78 display_id = self._match_id(url)
79 webpage = self._download_webpage(url, display_id)
80 url_parts = display_id.split('/')
81 url_parts_len = len(url_parts)
82 if url_parts_len == 1:
84 for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
85 entries.append(self.url_result(
86 compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
87 return self.playlist_result(
88 entries, self._html_search_meta('aetn:SeriesId', webpage),
89 self._html_search_meta('aetn:SeriesTitle', webpage))
90 elif url_parts_len == 2:
92 for episode_item in re.findall(r'(?s)<div[^>]+class="[^"]*episode-item[^"]*"[^>]*>', webpage):
93 episode_attributes = extract_attributes(episode_item)
94 episode_url = compat_urlparse.urljoin(
95 url, episode_attributes['data-canonical'])
96 entries.append(self.url_result(
97 episode_url, 'AENetworks',
98 episode_attributes['data-videoid']))
99 return self.playlist_result(
100 entries, self._html_search_meta('aetn:SeasonId', webpage))
102 video_id = self._html_search_meta('aetn:VideoID', webpage)
103 media_url = self._search_regex(
104 r"media_url\s*=\s*'([^']+)'", webpage, 'video url')
106 info = self._search_json_ld(webpage, video_id, fatal=False)
107 info.update(self.theplatform_url_result(
108 media_url, video_id, {
110 'assetTypes': 'medium_video_s3'
115 class HistoryTopicIE(AENetworksBaseIE):
116 IE_NAME = 'history:topic'
117 IE_DESC = 'History.com Topic'
118 _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)/videos(?:/(?P<display_id>[^/?#]+))?'
120 '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',
124 'title': "Bet You Didn't Know: Valentine's Day",
125 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
126 'timestamp': 1375819729,
127 'upload_date': '20130806',
128 'uploader': 'AENE-NEW',
132 'skip_download': True,
134 'add_ie': ['ThePlatform'],
136 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
139 'id': 'world-war-i-history',
140 'title': 'World War I History',
142 'playlist_mincount': 24,
144 'url': 'http://www.history.com/topics/world-war-i-history/videos',
145 'only_matching': True,
148 def _real_extract(self, url):
149 topic_id, display_id = re.match(self._VALID_URL, url).groups()
151 webpage = self._download_webpage(url, display_id)
152 release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
153 release_url = unescapeHTML(release_url)
155 return self.theplatform_url_result(
156 release_url, video_id, {
161 webpage = self._download_webpage(url, topic_id)
163 for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
164 video_attributes = extract_attributes(episode_item)
165 entries.append(self.theplatform_url_result(
166 video_attributes['data-release-url'], video_attributes['data-id'], {
170 return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))