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.

236 lines
9.5 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. if entries:
  98. return self.playlist_result(
  99. entries, self._html_search_meta('aetn:SeriesId', webpage),
  100. self._html_search_meta('aetn:SeriesTitle', webpage))
  101. else:
  102. # single season
  103. url_parts_len = 2
  104. if url_parts_len == 2:
  105. entries = []
  106. for episode_item in re.findall(r'(?s)<[^>]+class="[^"]*(?:episode|program)-item[^"]*"[^>]*>', webpage):
  107. episode_attributes = extract_attributes(episode_item)
  108. episode_url = compat_urlparse.urljoin(
  109. url, episode_attributes['data-canonical'])
  110. entries.append(self.url_result(
  111. episode_url, 'AENetworks',
  112. episode_attributes.get('data-videoid') or episode_attributes.get('data-video-id')))
  113. return self.playlist_result(
  114. entries, self._html_search_meta('aetn:SeasonId', webpage))
  115. query = {
  116. 'mbr': 'true',
  117. 'assetTypes': 'high_video_s3'
  118. }
  119. video_id = self._html_search_meta('aetn:VideoID', webpage)
  120. media_url = self._search_regex(
  121. [r"media_url\s*=\s*'(?P<url>[^']+)'",
  122. r'data-media-url=(?P<url>(?:https?:)?//[^\s>]+)',
  123. r'data-media-url=(["\'])(?P<url>(?:(?!\1).)+?)\1'],
  124. webpage, 'video url', group='url')
  125. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  126. r'https?://link.theplatform.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
  127. info = self._parse_theplatform_metadata(theplatform_metadata)
  128. if theplatform_metadata.get('AETN$isBehindWall'):
  129. requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain]
  130. resource = self._get_mvpd_resource(
  131. requestor_id, theplatform_metadata['title'],
  132. theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'),
  133. theplatform_metadata['ratings'][0]['rating'])
  134. query['auth'] = self._extract_mvpd_auth(
  135. url, video_id, requestor_id, resource)
  136. info.update(self._search_json_ld(webpage, video_id, fatal=False))
  137. media_url = update_url_query(media_url, query)
  138. media_url = self._sign_url(media_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
  139. formats, subtitles = self._extract_theplatform_smil(media_url, video_id)
  140. self._sort_formats(formats)
  141. info.update({
  142. 'id': video_id,
  143. 'formats': formats,
  144. 'subtitles': subtitles,
  145. })
  146. return info
  147. class HistoryTopicIE(AENetworksBaseIE):
  148. IE_NAME = 'history:topic'
  149. IE_DESC = 'History.com Topic'
  150. _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)(?:/[^/]+(?:/(?P<video_display_id>[^/?#]+))?)?'
  151. _TESTS = [{
  152. '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',
  153. 'info_dict': {
  154. 'id': '40700995724',
  155. 'ext': 'mp4',
  156. 'title': "Bet You Didn't Know: Valentine's Day",
  157. 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
  158. 'timestamp': 1375819729,
  159. 'upload_date': '20130806',
  160. 'uploader': 'AENE-NEW',
  161. },
  162. 'params': {
  163. # m3u8 download
  164. 'skip_download': True,
  165. },
  166. 'add_ie': ['ThePlatform'],
  167. }, {
  168. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
  169. 'info_dict':
  170. {
  171. 'id': 'world-war-i-history',
  172. 'title': 'World War I History',
  173. },
  174. 'playlist_mincount': 23,
  175. }, {
  176. 'url': 'http://www.history.com/topics/world-war-i-history/videos',
  177. 'only_matching': True,
  178. }, {
  179. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history',
  180. 'only_matching': True,
  181. }, {
  182. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/speeches',
  183. 'only_matching': True,
  184. }]
  185. def theplatform_url_result(self, theplatform_url, video_id, query):
  186. return {
  187. '_type': 'url_transparent',
  188. 'id': video_id,
  189. 'url': smuggle_url(
  190. update_url_query(theplatform_url, query),
  191. {
  192. 'sig': {
  193. 'key': self._THEPLATFORM_KEY,
  194. 'secret': self._THEPLATFORM_SECRET,
  195. },
  196. 'force_smil_url': True
  197. }),
  198. 'ie_key': 'ThePlatform',
  199. }
  200. def _real_extract(self, url):
  201. topic_id, video_display_id = re.match(self._VALID_URL, url).groups()
  202. if video_display_id:
  203. webpage = self._download_webpage(url, video_display_id)
  204. release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
  205. release_url = unescapeHTML(release_url)
  206. return self.theplatform_url_result(
  207. release_url, video_id, {
  208. 'mbr': 'true',
  209. 'switch': 'hls',
  210. 'assetTypes': 'high_video_ak',
  211. })
  212. else:
  213. webpage = self._download_webpage(url, topic_id)
  214. entries = []
  215. for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
  216. video_attributes = extract_attributes(episode_item)
  217. entries.append(self.theplatform_url_result(
  218. video_attributes['data-release-url'], video_attributes['data-id'], {
  219. 'mbr': 'true',
  220. 'switch': 'hls',
  221. 'assetTypes': 'high_video_ak',
  222. }))
  223. return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))