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.

246 lines
9.7 KiB

9 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .theplatform import ThePlatformIE
  4. from ..utils import (
  5. extract_attributes,
  6. ExtractorError,
  7. int_or_none,
  8. smuggle_url,
  9. update_url_query,
  10. )
  11. from ..compat import (
  12. compat_urlparse,
  13. )
  14. class AENetworksBaseIE(ThePlatformIE):
  15. _THEPLATFORM_KEY = 'crazyjava'
  16. _THEPLATFORM_SECRET = 's3cr3t'
  17. def _extract_aen_smil(self, smil_url, video_id, auth=None):
  18. query = {'mbr': 'true'}
  19. if auth:
  20. query['auth'] = auth
  21. TP_SMIL_QUERY = [{
  22. 'assetTypes': 'high_video_ak',
  23. 'switch': 'hls_high_ak'
  24. }, {
  25. 'assetTypes': 'high_video_s3'
  26. }, {
  27. 'assetTypes': 'high_video_s3',
  28. 'switch': 'hls_ingest_fastly'
  29. }]
  30. formats = []
  31. subtitles = {}
  32. last_e = None
  33. for q in TP_SMIL_QUERY:
  34. q.update(query)
  35. m_url = update_url_query(smil_url, q)
  36. m_url = self._sign_url(m_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
  37. try:
  38. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  39. m_url, video_id, 'Downloading %s SMIL data' % (q.get('switch') or q['assetTypes']))
  40. except ExtractorError as e:
  41. last_e = e
  42. continue
  43. formats.extend(tp_formats)
  44. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  45. if last_e and not formats:
  46. raise last_e
  47. self._sort_formats(formats)
  48. return {
  49. 'id': video_id,
  50. 'formats': formats,
  51. 'subtitles': subtitles,
  52. }
  53. class AENetworksIE(AENetworksBaseIE):
  54. IE_NAME = 'aenetworks'
  55. IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network and History Vault'
  56. _VALID_URL = r'''(?x)
  57. https?://
  58. (?:www\.)?
  59. (?P<domain>
  60. (?:history(?:vault)?|aetv|mylifetime|lifetimemovieclub)\.com|
  61. fyi\.tv
  62. )/
  63. (?:
  64. shows/(?P<show_path>[^/]+(?:/[^/]+){0,2})|
  65. movies/(?P<movie_display_id>[^/]+)(?:/full-movie)?|
  66. specials/(?P<special_display_id>[^/]+)/(?:full-special|preview-)|
  67. collections/[^/]+/(?P<collection_display_id>[^/]+)
  68. )
  69. '''
  70. _TESTS = [{
  71. 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
  72. 'info_dict': {
  73. 'id': '22253814',
  74. 'ext': 'mp4',
  75. 'title': 'Winter is Coming',
  76. 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74',
  77. 'timestamp': 1338306241,
  78. 'upload_date': '20120529',
  79. 'uploader': 'AENE-NEW',
  80. },
  81. 'params': {
  82. # m3u8 download
  83. 'skip_download': True,
  84. },
  85. 'add_ie': ['ThePlatform'],
  86. }, {
  87. 'url': 'http://www.history.com/shows/ancient-aliens/season-1',
  88. 'info_dict': {
  89. 'id': '71889446852',
  90. },
  91. 'playlist_mincount': 5,
  92. }, {
  93. 'url': 'http://www.mylifetime.com/shows/atlanta-plastic',
  94. 'info_dict': {
  95. 'id': 'SERIES4317',
  96. 'title': 'Atlanta Plastic',
  97. },
  98. 'playlist_mincount': 2,
  99. }, {
  100. 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1',
  101. 'only_matching': True
  102. }, {
  103. 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8',
  104. 'only_matching': True
  105. }, {
  106. 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6',
  107. 'only_matching': True
  108. }, {
  109. 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie',
  110. 'only_matching': True
  111. }, {
  112. 'url': 'https://www.lifetimemovieclub.com/movies/a-killer-among-us',
  113. 'only_matching': True
  114. }, {
  115. 'url': 'http://www.history.com/specials/sniper-into-the-kill-zone/full-special',
  116. 'only_matching': True
  117. }, {
  118. 'url': 'https://www.historyvault.com/collections/america-the-story-of-us/westward',
  119. 'only_matching': True
  120. }, {
  121. 'url': 'https://www.aetv.com/specials/hunting-jonbenets-killer-the-untold-story/preview-hunting-jonbenets-killer-the-untold-story',
  122. 'only_matching': True
  123. }]
  124. _DOMAIN_TO_REQUESTOR_ID = {
  125. 'history.com': 'HISTORY',
  126. 'aetv.com': 'AETV',
  127. 'mylifetime.com': 'LIFETIME',
  128. 'lifetimemovieclub.com': 'LIFETIMEMOVIECLUB',
  129. 'fyi.tv': 'FYI',
  130. }
  131. def _real_extract(self, url):
  132. domain, show_path, movie_display_id, special_display_id, collection_display_id = re.match(self._VALID_URL, url).groups()
  133. display_id = show_path or movie_display_id or special_display_id or collection_display_id
  134. webpage = self._download_webpage(url, display_id, headers=self.geo_verification_headers())
  135. if show_path:
  136. url_parts = show_path.split('/')
  137. url_parts_len = len(url_parts)
  138. if url_parts_len == 1:
  139. entries = []
  140. for season_url_path in re.findall(r'(?s)<li[^>]+data-href="(/shows/%s/season-\d+)"' % url_parts[0], webpage):
  141. entries.append(self.url_result(
  142. compat_urlparse.urljoin(url, season_url_path), 'AENetworks'))
  143. if entries:
  144. return self.playlist_result(
  145. entries, self._html_search_meta('aetn:SeriesId', webpage),
  146. self._html_search_meta('aetn:SeriesTitle', webpage))
  147. else:
  148. # single season
  149. url_parts_len = 2
  150. if url_parts_len == 2:
  151. entries = []
  152. for episode_item in re.findall(r'(?s)<[^>]+class="[^"]*(?:episode|program)-item[^"]*"[^>]*>', webpage):
  153. episode_attributes = extract_attributes(episode_item)
  154. episode_url = compat_urlparse.urljoin(
  155. url, episode_attributes['data-canonical'])
  156. entries.append(self.url_result(
  157. episode_url, 'AENetworks',
  158. episode_attributes.get('data-videoid') or episode_attributes.get('data-video-id')))
  159. return self.playlist_result(
  160. entries, self._html_search_meta('aetn:SeasonId', webpage))
  161. video_id = self._html_search_meta('aetn:VideoID', webpage)
  162. media_url = self._search_regex(
  163. [r"media_url\s*=\s*'(?P<url>[^']+)'",
  164. r'data-media-url=(?P<url>(?:https?:)?//[^\s>]+)',
  165. r'data-media-url=(["\'])(?P<url>(?:(?!\1).)+?)\1'],
  166. webpage, 'video url', group='url')
  167. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  168. r'https?://link\.theplatform\.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
  169. info = self._parse_theplatform_metadata(theplatform_metadata)
  170. auth = None
  171. if theplatform_metadata.get('AETN$isBehindWall'):
  172. requestor_id = self._DOMAIN_TO_REQUESTOR_ID[domain]
  173. resource = self._get_mvpd_resource(
  174. requestor_id, theplatform_metadata['title'],
  175. theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'),
  176. theplatform_metadata['ratings'][0]['rating'])
  177. auth = self._extract_mvpd_auth(
  178. url, video_id, requestor_id, resource)
  179. info.update(self._search_json_ld(webpage, video_id, fatal=False))
  180. info.update(self._extract_aen_smil(media_url, video_id, auth))
  181. return info
  182. class HistoryTopicIE(AENetworksBaseIE):
  183. IE_NAME = 'history:topic'
  184. IE_DESC = 'History.com Topic'
  185. _VALID_URL = r'https?://(?:www\.)?history\.com/topics/[^/]+/(?P<id>[\w+-]+?)-video'
  186. _TESTS = [{
  187. 'url': 'https://www.history.com/topics/valentines-day/history-of-valentines-day-video',
  188. 'info_dict': {
  189. 'id': '40700995724',
  190. 'ext': 'mp4',
  191. 'title': "History of Valentine’s Day",
  192. 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
  193. 'timestamp': 1375819729,
  194. 'upload_date': '20130806',
  195. },
  196. 'params': {
  197. # m3u8 download
  198. 'skip_download': True,
  199. },
  200. 'add_ie': ['ThePlatform'],
  201. }]
  202. def theplatform_url_result(self, theplatform_url, video_id, query):
  203. return {
  204. '_type': 'url_transparent',
  205. 'id': video_id,
  206. 'url': smuggle_url(
  207. update_url_query(theplatform_url, query),
  208. {
  209. 'sig': {
  210. 'key': self._THEPLATFORM_KEY,
  211. 'secret': self._THEPLATFORM_SECRET,
  212. },
  213. 'force_smil_url': True
  214. }),
  215. 'ie_key': 'ThePlatform',
  216. }
  217. def _real_extract(self, url):
  218. display_id = self._match_id(url)
  219. webpage = self._download_webpage(url, display_id)
  220. video_id = self._search_regex(
  221. r'<phoenix-iframe[^>]+src="[^"]+\btpid=(\d+)', webpage, 'tpid')
  222. result = self._download_json(
  223. 'https://feeds.video.aetnd.com/api/v2/history/videos',
  224. video_id, query={'filter[id]': video_id})['results'][0]
  225. title = result['title']
  226. info = self._extract_aen_smil(result['publicUrl'], video_id)
  227. info.update({
  228. 'title': title,
  229. 'description': result.get('description'),
  230. 'duration': int_or_none(result.get('duration')),
  231. 'timestamp': int_or_none(result.get('added'), 1000),
  232. })
  233. return info