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.

247 lines
9.7 KiB

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