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.

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