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.

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