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.

214 lines
8.7 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|lifetimemovieclub)\.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': 'a97a65f7e823ae10e9244bc5433d5fe6',
  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. 'url': 'https://www.lifetimemovieclub.com/movies/a-killer-among-us',
  61. 'only_matching': True
  62. }]
  63. _DOMAIN_TO_REQUESTOR_ID = {
  64. 'history.com': 'HISTORY',
  65. 'aetv.com': 'AETV',
  66. 'mylifetime.com': 'LIFETIME',
  67. 'lifetimemovieclub.com': 'LIFETIMEMOVIECLUB',
  68. 'fyi.tv': 'FYI',
  69. }
  70. def _real_extract(self, url):
  71. domain, show_path, movie_display_id = re.match(self._VALID_URL, url).groups()
  72. display_id = show_path or movie_display_id
  73. webpage = self._download_webpage(url, display_id)
  74. if show_path:
  75. url_parts = show_path.split('/')
  76. url_parts_len = len(url_parts)
  77. if url_parts_len == 1:
  78. entries = []
  79. for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
  80. entries.append(self.url_result(
  81. compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
  82. return self.playlist_result(
  83. entries, self._html_search_meta('aetn:SeriesId', webpage),
  84. self._html_search_meta('aetn:SeriesTitle', webpage))
  85. elif url_parts_len == 2:
  86. entries = []
  87. for episode_item in re.findall(r'(?s)<[^>]+class="[^"]*(?:episode|program)-item[^"]*"[^>]*>', webpage):
  88. episode_attributes = extract_attributes(episode_item)
  89. episode_url = compat_urlparse.urljoin(
  90. url, episode_attributes['data-canonical'])
  91. entries.append(self.url_result(
  92. episode_url, 'AENetworks',
  93. episode_attributes['data-videoid']))
  94. return self.playlist_result(
  95. entries, self._html_search_meta('aetn:SeasonId', webpage))
  96. query = {
  97. 'mbr': 'true',
  98. 'assetTypes': 'high_video_s3'
  99. }
  100. video_id = self._html_search_meta('aetn:VideoID', webpage)
  101. media_url = self._search_regex(
  102. r"media_url\s*=\s*'([^']+)'", webpage, 'video url')
  103. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  104. r'https?://link.theplatform.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
  105. info = self._parse_theplatform_metadata(theplatform_metadata)
  106. if theplatform_metadata.get('AETN$isBehindWall'):
  107. requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain]
  108. resource = self._get_mvpd_resource(
  109. requestor_id, theplatform_metadata['title'],
  110. theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'),
  111. theplatform_metadata['ratings'][0]['rating'])
  112. query['auth'] = self._extract_mvpd_auth(
  113. url, video_id, requestor_id, resource)
  114. info.update(self._search_json_ld(webpage, video_id, fatal=False))
  115. media_url = update_url_query(media_url, query)
  116. media_url = self._sign_url(media_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
  117. formats, subtitles = self._extract_theplatform_smil(media_url, video_id)
  118. self._sort_formats(formats)
  119. info.update({
  120. 'id': video_id,
  121. 'formats': formats,
  122. 'subtitles': subtitles,
  123. })
  124. return info
  125. class HistoryTopicIE(AENetworksBaseIE):
  126. IE_NAME = 'history:topic'
  127. IE_DESC = 'History.com Topic'
  128. _VALID_URL = r'https?://(?:www\.)?history\.com/topics/(?:[^/]+/)?(?P<topic_id>[^/]+)(?:/[^/]+(?:/(?P<video_display_id>[^/?#]+))?)?'
  129. _TESTS = [{
  130. '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',
  131. 'info_dict': {
  132. 'id': '40700995724',
  133. 'ext': 'mp4',
  134. 'title': "Bet You Didn't Know: Valentine's Day",
  135. 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
  136. 'timestamp': 1375819729,
  137. 'upload_date': '20130806',
  138. 'uploader': 'AENE-NEW',
  139. },
  140. 'params': {
  141. # m3u8 download
  142. 'skip_download': True,
  143. },
  144. 'add_ie': ['ThePlatform'],
  145. }, {
  146. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/videos',
  147. 'info_dict':
  148. {
  149. 'id': 'world-war-i-history',
  150. 'title': 'World War I History',
  151. },
  152. 'playlist_mincount': 23,
  153. }, {
  154. 'url': 'http://www.history.com/topics/world-war-i-history/videos',
  155. 'only_matching': True,
  156. }, {
  157. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history',
  158. 'only_matching': True,
  159. }, {
  160. 'url': 'http://www.history.com/topics/world-war-i/world-war-i-history/speeches',
  161. 'only_matching': True,
  162. }]
  163. def theplatform_url_result(self, theplatform_url, video_id, query):
  164. return {
  165. '_type': 'url_transparent',
  166. 'id': video_id,
  167. 'url': smuggle_url(
  168. update_url_query(theplatform_url, query),
  169. {
  170. 'sig': {
  171. 'key': self._THEPLATFORM_KEY,
  172. 'secret': self._THEPLATFORM_SECRET,
  173. },
  174. 'force_smil_url': True
  175. }),
  176. 'ie_key': 'ThePlatform',
  177. }
  178. def _real_extract(self, url):
  179. topic_id, video_display_id = re.match(self._VALID_URL, url).groups()
  180. if video_display_id:
  181. webpage = self._download_webpage(url, video_display_id)
  182. release_url, video_id = re.search(r"_videoPlayer.play\('([^']+)'\s*,\s*'[^']+'\s*,\s*'(\d+)'\)", webpage).groups()
  183. release_url = unescapeHTML(release_url)
  184. return self.theplatform_url_result(
  185. release_url, video_id, {
  186. 'mbr': 'true',
  187. 'switch': 'hls',
  188. 'assetTypes': 'high_video_ak',
  189. })
  190. else:
  191. webpage = self._download_webpage(url, topic_id)
  192. entries = []
  193. for episode_item in re.findall(r'<a.+?data-release-url="[^"]+"[^>]*>', webpage):
  194. video_attributes = extract_attributes(episode_item)
  195. entries.append(self.theplatform_url_result(
  196. video_attributes['data-release-url'], video_attributes['data-id'], {
  197. 'mbr': 'true',
  198. 'switch': 'hls',
  199. 'assetTypes': 'high_video_ak',
  200. }))
  201. return self.playlist_result(entries, topic_id, get_element_by_attribute('class', 'show-title', webpage))