You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
8.4 KiB

9 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .theplatform import ThePlatformIE
  4. from ..utils import (
  5. smuggle_url,
  6. update_url_query,
  7. unescapeHTML,
  8. extract_attributes,
  9. get_element_by_attribute,
  10. )
  11. from ..compat import (
  12. compat_urlparse,
  13. )
  14. class AENetworksBaseIE(ThePlatformIE):
  15. _THEPLATFORM_KEY = 'crazyjava'
  16. _THEPLATFORM_SECRET = 's3cr3t'
  17. class AENetworksIE(AENetworksBaseIE):
  18. IE_NAME = 'aenetworks'
  19. IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network'
  20. _VALID_URL = r'https?://(?:www\.)?(?P<domain>(?:history|aetv|mylifetime)\.com|fyi\.tv)/(?:shows/(?P<show_path>[^/]+(?:/[^/]+){0,2})|movies/(?P<movie_display_id>[^/]+)/full-movie)'
  21. _TESTS = [{
  22. 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
  23. 'md5': '8ff93eb073449f151d6b90c0ae1ef0c7',
  24. 'info_dict': {
  25. 'id': '22253814',
  26. 'ext': 'mp4',
  27. 'title': 'Winter Is Coming',
  28. 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74',
  29. 'timestamp': 1338306241,
  30. 'upload_date': '20120529',
  31. 'uploader': 'AENE-NEW',
  32. },
  33. 'add_ie': ['ThePlatform'],
  34. }, {
  35. 'url': 'http://www.history.com/shows/ancient-aliens/season-1',
  36. 'info_dict': {
  37. 'id': '71889446852',
  38. },
  39. 'playlist_mincount': 5,
  40. }, {
  41. 'url': 'http://www.mylifetime.com/shows/atlanta-plastic',
  42. 'info_dict': {
  43. 'id': 'SERIES4317',
  44. 'title': 'Atlanta Plastic',
  45. },
  46. 'playlist_mincount': 2,
  47. }, {
  48. 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1',
  49. 'only_matching': True
  50. }, {
  51. 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8',
  52. 'only_matching': True
  53. }, {
  54. 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6',
  55. 'only_matching': True
  56. }, {
  57. 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie',
  58. 'only_matching': True
  59. }]
  60. _DOMAIN_TO_REQUESTOR_ID = {
  61. 'history.com': 'HISTORY',
  62. 'aetv.com': 'AETV',
  63. 'mylifetime.com': 'LIFETIME',
  64. 'fyi.tv': 'FYI',
  65. }
  66. def _real_extract(self, url):
  67. domain, show_path, movie_display_id = re.match(self._VALID_URL, url).groups()
  68. display_id = show_path or movie_display_id
  69. webpage = self._download_webpage(url, display_id)
  70. if show_path:
  71. url_parts = show_path.split('/')
  72. url_parts_len = len(url_parts)
  73. if url_parts_len == 1:
  74. entries = []
  75. for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
  76. entries.append(self.url_result(
  77. compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
  78. return self.playlist_result(
  79. entries, self._html_search_meta('aetn:SeriesId', webpage),
  80. self._html_search_meta('aetn:SeriesTitle', webpage))
  81. elif url_parts_len == 2:
  82. entries = []
  83. for episode_item in re.findall(r'(?s)<div[^>]+class="[^"]*episode-item[^"]*"[^>]*>', webpage):
  84. episode_attributes = extract_attributes(episode_item)
  85. episode_url = compat_urlparse.urljoin(
  86. url, episode_attributes['data-canonical'])
  87. entries.append(self.url_result(
  88. episode_url, 'AENetworks',
  89. episode_attributes['data-videoid']))
  90. return self.playlist_result(
  91. entries, self._html_search_meta('aetn:SeasonId', webpage))
  92. query = {
  93. 'mbr': 'true',
  94. 'assetTypes': 'medium_video_s3'
  95. }
  96. video_id = self._html_search_meta('aetn:VideoID', webpage)
  97. media_url = self._search_regex(
  98. r"media_url\s*=\s*'([^']+)'", webpage, 'video url')
  99. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  100. r'https?://link.theplatform.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
  101. info = self._parse_theplatform_metadata(theplatform_metadata)
  102. if theplatform_metadata.get('AETN$isBehindWall'):
  103. requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain]
  104. resource = '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>%s</title><item><title>%s</title><guid>%s</guid><media:rating scheme="urn:v-chip">%s</media:rating></item></channel></rss>' % (requestor_id, theplatform_metadata['title'], theplatform_metadata['AETN$PPL_pplProgramId'], theplatform_metadata['ratings'][0]['rating'])
  105. query['auth'] = self._extract_mvpd_auth(
  106. url, video_id, requestor_id, resource)
  107. info.update(self._search_json_ld(webpage, video_id, fatal=False))
  108. media_url = update_url_query(media_url, query)
  109. media_url = self._sign_url(media_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
  110. formats, subtitles = self._extract_theplatform_smil(media_url, video_id)
  111. self._sort_formats(formats)
  112. info.update({
  113. 'id': video_id,
  114. 'formats': formats,
  115. 'subtitles': subtitles,
  116. })
  117. return info
  118. class HistoryTopicIE(AENetworksBaseIE):
  119. IE_NAME = 'history:topic'
  120. IE_DESC = 'History.com Topic'
  121. _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)(?:/[^/]+(?:/(?P<video_display_id>[^/?#]+))?)?'
  122. _TESTS = [{
  123. '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. 'info_dict': {
  125. 'id': '40700995724',
  126. 'ext': 'mp4',
  127. 'title': "Bet You Didn't Know: Valentine's Day",
  128. 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
  129. 'timestamp': 1375819729,
  130. 'upload_date': '20130806',
  131. 'uploader': 'AENE-NEW',
  132. },
  133. 'params': {
  134. # m3u8 download
  135. 'skip_download': True,
  136. },
  137. 'add_ie': ['ThePlatform'],
  138. }, {
  139. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
  140. 'info_dict':
  141. {
  142. 'id': 'world-war-i-history',
  143. 'title': 'World War I History',
  144. },
  145. 'playlist_mincount': 24,
  146. }, {
  147. 'url': 'http://www.history.com/topics/world-war-i-history/videos',
  148. 'only_matching': True,
  149. }, {
  150. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history',
  151. 'only_matching': True,
  152. }, {
  153. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/speeches',
  154. 'only_matching': True,
  155. }]
  156. def theplatform_url_result(self, theplatform_url, video_id, query):
  157. return {
  158. '_type': 'url_transparent',
  159. 'id': video_id,
  160. 'url': smuggle_url(
  161. update_url_query(theplatform_url, query),
  162. {
  163. 'sig': {
  164. 'key': self._THEPLATFORM_KEY,
  165. 'secret': self._THEPLATFORM_SECRET,
  166. },
  167. 'force_smil_url': True
  168. }),
  169. 'ie_key': 'ThePlatform',
  170. }
  171. def _real_extract(self, url):
  172. topic_id, video_display_id = re.match(self._VALID_URL, url).groups()
  173. if video_display_id:
  174. webpage = self._download_webpage(url, video_display_id)
  175. release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
  176. release_url = unescapeHTML(release_url)
  177. return self.theplatform_url_result(
  178. release_url, video_id, {
  179. 'mbr': 'true',
  180. 'switch': 'hls'
  181. })
  182. else:
  183. webpage = self._download_webpage(url, topic_id)
  184. entries = []
  185. for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
  186. video_attributes = extract_attributes(episode_item)
  187. entries.append(self.theplatform_url_result(
  188. video_attributes['data-release-url'], video_attributes['data-id'], {
  189. 'mbr': 'true',
  190. 'switch': 'hls'
  191. }))
  192. return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))