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.

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