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.

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