logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

aenetworks.py (12634B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .theplatform import ThePlatformIE
  5. from ..utils import (
  6. ExtractorError,
  7. GeoRestrictedError,
  8. int_or_none,
  9. remove_start,
  10. traverse_obj,
  11. update_url_query,
  12. urlencode_postdata,
  13. )
  14. class AENetworksBaseIE(ThePlatformIE):
  15. _BASE_URL_REGEX = r'''(?x)https?://
  16. (?:(?:www|play|watch)\.)?
  17. (?P<domain>
  18. (?:history(?:vault)?|aetv|mylifetime|lifetimemovieclub)\.com|
  19. fyi\.tv
  20. )/'''
  21. _THEPLATFORM_KEY = '43jXaGRQud'
  22. _THEPLATFORM_SECRET = 'S10BPXHMlb'
  23. _DOMAIN_MAP = {
  24. 'history.com': ('HISTORY', 'history'),
  25. 'aetv.com': ('AETV', 'aetv'),
  26. 'mylifetime.com': ('LIFETIME', 'lifetime'),
  27. 'lifetimemovieclub.com': ('LIFETIMEMOVIECLUB', 'lmc'),
  28. 'fyi.tv': ('FYI', 'fyi'),
  29. 'historyvault.com': (None, 'historyvault'),
  30. 'biography.com': (None, 'biography'),
  31. }
  32. def _extract_aen_smil(self, smil_url, video_id, auth=None):
  33. query = {
  34. 'mbr': 'true',
  35. 'formats': 'M3U+none,MPEG-DASH+none,MPEG4,MP3',
  36. }
  37. if auth:
  38. query['auth'] = auth
  39. TP_SMIL_QUERY = [{
  40. 'assetTypes': 'high_video_ak',
  41. 'switch': 'hls_high_ak',
  42. }, {
  43. 'assetTypes': 'high_video_s3',
  44. }, {
  45. 'assetTypes': 'high_video_s3',
  46. 'switch': 'hls_high_fastly',
  47. }]
  48. formats = []
  49. subtitles = {}
  50. last_e = None
  51. for q in TP_SMIL_QUERY:
  52. q.update(query)
  53. m_url = update_url_query(smil_url, q)
  54. m_url = self._sign_url(m_url, self._THEPLATFORM_KEY, self._THEPLATFORM_SECRET)
  55. try:
  56. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  57. m_url, video_id, 'Downloading %s SMIL data' % (q.get('switch') or q['assetTypes']))
  58. except ExtractorError as e:
  59. if isinstance(e, GeoRestrictedError):
  60. raise
  61. last_e = e
  62. continue
  63. formats.extend(tp_formats)
  64. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  65. if last_e and not formats:
  66. raise last_e
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_id,
  70. 'formats': formats,
  71. 'subtitles': subtitles,
  72. }
  73. def _extract_aetn_info(self, domain, filter_key, filter_value, url):
  74. requestor_id, brand = self._DOMAIN_MAP[domain]
  75. result = self._download_json(
  76. 'https://feeds.video.aetnd.com/api/v2/%s/videos' % brand,
  77. filter_value, query={'filter[%s]' % filter_key: filter_value})
  78. result = traverse_obj(
  79. result, ('results',
  80. lambda k, v: k == 0 and v[filter_key] == filter_value),
  81. get_all=False)
  82. if not result:
  83. raise ExtractorError('Show not found in A&E feed (too new?)', expected=True,
  84. video_id=remove_start(filter_value, '/'))
  85. title = result['title']
  86. video_id = result['id']
  87. media_url = result['publicUrl']
  88. theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
  89. r'https?://link\.theplatform\.com/s/([^?]+)', media_url, 'theplatform_path'), video_id)
  90. info = self._parse_theplatform_metadata(theplatform_metadata)
  91. auth = None
  92. if theplatform_metadata.get('AETN$isBehindWall'):
  93. resource = self._get_mvpd_resource(
  94. requestor_id, theplatform_metadata['title'],
  95. theplatform_metadata.get('AETN$PPL_pplProgramId') or theplatform_metadata.get('AETN$PPL_pplProgramId_OLD'),
  96. theplatform_metadata['ratings'][0]['rating'])
  97. auth = self._extract_mvpd_auth(
  98. url, video_id, requestor_id, resource)
  99. info.update(self._extract_aen_smil(media_url, video_id, auth))
  100. info.update({
  101. 'title': title,
  102. 'series': result.get('seriesName'),
  103. 'season_number': int_or_none(result.get('tvSeasonNumber')),
  104. 'episode_number': int_or_none(result.get('tvSeasonEpisodeNumber')),
  105. })
  106. return info
  107. class AENetworksIE(AENetworksBaseIE):
  108. IE_NAME = 'aenetworks'
  109. IE_DESC = 'A+E Networks: A&E, Lifetime, History.com, FYI Network and History Vault'
  110. _VALID_URL = AENetworksBaseIE._BASE_URL_REGEX + r'''(?P<id>
  111. shows/[^/]+/season-\d+/episode-\d+|
  112. (?:
  113. (?:movie|special)s/[^/]+|
  114. (?:shows/[^/]+/)?videos
  115. )/[^/?#&]+
  116. )'''
  117. _TESTS = [{
  118. 'url': 'http://www.history.com/shows/mountain-men/season-1/episode-1',
  119. 'info_dict': {
  120. 'id': '22253814',
  121. 'ext': 'mp4',
  122. 'title': 'Winter is Coming',
  123. 'description': 'md5:641f424b7a19d8e24f26dea22cf59d74',
  124. 'timestamp': 1338306241,
  125. 'upload_date': '20120529',
  126. 'uploader': 'AENE-NEW',
  127. },
  128. 'params': {
  129. # m3u8 download
  130. 'skip_download': True,
  131. },
  132. 'add_ie': ['ThePlatform'],
  133. 'skip': 'Geo-restricted - This content is not available in your location.'
  134. }, {
  135. 'url': 'http://www.aetv.com/shows/duck-dynasty/season-9/episode-1',
  136. 'info_dict': {
  137. 'id': '600587331957',
  138. 'ext': 'mp4',
  139. 'title': 'Inlawful Entry',
  140. 'description': 'md5:57c12115a2b384d883fe64ca50529e08',
  141. 'timestamp': 1452634428,
  142. 'upload_date': '20160112',
  143. 'uploader': 'AENE-NEW',
  144. },
  145. 'params': {
  146. # m3u8 download
  147. 'skip_download': True,
  148. },
  149. 'add_ie': ['ThePlatform'],
  150. 'skip': 'This video is only available for users of participating TV providers.',
  151. }, {
  152. 'url': 'http://www.fyi.tv/shows/tiny-house-nation/season-1/episode-8',
  153. 'only_matching': True
  154. }, {
  155. 'url': 'http://www.mylifetime.com/shows/project-runway-junior/season-1/episode-6',
  156. 'only_matching': True
  157. }, {
  158. 'url': 'http://www.mylifetime.com/movies/center-stage-on-pointe/full-movie',
  159. 'only_matching': True
  160. }, {
  161. 'url': 'https://watch.lifetimemovieclub.com/movies/10-year-reunion/full-movie',
  162. 'only_matching': True
  163. }, {
  164. 'url': 'http://www.history.com/specials/sniper-into-the-kill-zone/full-special',
  165. 'only_matching': True
  166. }, {
  167. 'url': 'https://www.aetv.com/specials/hunting-jonbenets-killer-the-untold-story/preview-hunting-jonbenets-killer-the-untold-story',
  168. 'only_matching': True
  169. }, {
  170. 'url': 'http://www.history.com/videos/history-of-valentines-day',
  171. 'only_matching': True
  172. }, {
  173. 'url': 'https://play.aetv.com/shows/duck-dynasty/videos/best-of-duck-dynasty-getting-quack-in-shape',
  174. 'only_matching': True
  175. }]
  176. def _real_extract(self, url):
  177. domain, canonical = re.match(self._VALID_URL, url).groups()
  178. return self._extract_aetn_info(domain, 'canonical', '/' + canonical, url)
  179. class AENetworksListBaseIE(AENetworksBaseIE):
  180. def _call_api(self, resource, slug, brand, fields):
  181. return self._download_json(
  182. 'https://yoga.appsvcs.aetnd.com/graphql',
  183. slug, query={'brand': brand}, data=urlencode_postdata({
  184. 'query': '''{
  185. %s(slug: "%s") {
  186. %s
  187. }
  188. }''' % (resource, slug, fields),
  189. }))['data'][resource]
  190. def _real_extract(self, url):
  191. domain, slug = re.match(self._VALID_URL, url).groups()
  192. _, brand = self._DOMAIN_MAP[domain]
  193. playlist = self._call_api(self._RESOURCE, slug, brand, self._FIELDS)
  194. base_url = 'http://watch.%s' % domain
  195. entries = []
  196. for item in (playlist.get(self._ITEMS_KEY) or []):
  197. doc = self._get_doc(item)
  198. canonical = doc.get('canonical')
  199. if not canonical:
  200. continue
  201. entries.append(self.url_result(
  202. base_url + canonical, AENetworksIE.ie_key(), doc.get('id')))
  203. description = None
  204. if self._PLAYLIST_DESCRIPTION_KEY:
  205. description = playlist.get(self._PLAYLIST_DESCRIPTION_KEY)
  206. return self.playlist_result(
  207. entries, playlist.get('id'),
  208. playlist.get(self._PLAYLIST_TITLE_KEY), description)
  209. class AENetworksCollectionIE(AENetworksListBaseIE):
  210. IE_NAME = 'aenetworks:collection'
  211. _VALID_URL = AENetworksBaseIE._BASE_URL_REGEX + r'(?:[^/]+/)*(?:list|collections)/(?P<id>[^/?#&]+)/?(?:[?#&]|$)'
  212. _TESTS = [{
  213. 'url': 'https://watch.historyvault.com/list/america-the-story-of-us',
  214. 'info_dict': {
  215. 'id': '282',
  216. 'title': 'America The Story of Us',
  217. },
  218. 'playlist_mincount': 12,
  219. }, {
  220. 'url': 'https://watch.historyvault.com/shows/america-the-story-of-us-2/season-1/list/america-the-story-of-us',
  221. 'only_matching': True
  222. }, {
  223. 'url': 'https://www.historyvault.com/collections/mysteryquest',
  224. 'only_matching': True
  225. }]
  226. _RESOURCE = 'list'
  227. _ITEMS_KEY = 'items'
  228. _PLAYLIST_TITLE_KEY = 'display_title'
  229. _PLAYLIST_DESCRIPTION_KEY = None
  230. _FIELDS = '''id
  231. display_title
  232. items {
  233. ... on ListVideoItem {
  234. doc {
  235. canonical
  236. id
  237. }
  238. }
  239. }'''
  240. def _get_doc(self, item):
  241. return item.get('doc') or {}
  242. class AENetworksShowIE(AENetworksListBaseIE):
  243. IE_NAME = 'aenetworks:show'
  244. _VALID_URL = AENetworksBaseIE._BASE_URL_REGEX + r'shows/(?P<id>[^/?#&]+)/?(?:[?#&]|$)'
  245. _TESTS = [{
  246. 'url': 'http://www.history.com/shows/ancient-aliens',
  247. 'info_dict': {
  248. 'id': 'SERIES1574',
  249. 'title': 'Ancient Aliens',
  250. 'description': 'md5:3f6d74daf2672ff3ae29ed732e37ea7f',
  251. },
  252. 'playlist_mincount': 150,
  253. }]
  254. _RESOURCE = 'series'
  255. _ITEMS_KEY = 'episodes'
  256. _PLAYLIST_TITLE_KEY = 'title'
  257. _PLAYLIST_DESCRIPTION_KEY = 'description'
  258. _FIELDS = '''description
  259. id
  260. title
  261. episodes {
  262. canonical
  263. id
  264. }'''
  265. def _get_doc(self, item):
  266. return item
  267. class HistoryTopicIE(AENetworksBaseIE):
  268. IE_NAME = 'history:topic'
  269. IE_DESC = 'History.com Topic'
  270. _VALID_URL = r'https?://(?:www\.)?history\.com/topics/[^/]+/(?P<id>[\w+-]+?)-video'
  271. _TESTS = [{
  272. 'url': 'https://www.history.com/topics/valentines-day/history-of-valentines-day-video',
  273. 'info_dict': {
  274. 'id': '40700995724',
  275. 'ext': 'mp4',
  276. 'title': "History of Valentine’s Day",
  277. 'description': 'md5:7b57ea4829b391995b405fa60bd7b5f7',
  278. 'timestamp': 1375819729,
  279. 'upload_date': '20130806',
  280. 'uploader': 'AENE-NEW',
  281. },
  282. 'params': {
  283. # m3u8 download
  284. 'skip_download': True,
  285. },
  286. 'add_ie': ['ThePlatform'],
  287. }]
  288. def _real_extract(self, url):
  289. display_id = self._match_id(url)
  290. return self.url_result(
  291. 'http://www.history.com/videos/' + display_id,
  292. AENetworksIE.ie_key())
  293. class HistoryPlayerIE(AENetworksBaseIE):
  294. IE_NAME = 'history:player'
  295. _VALID_URL = r'https?://(?:www\.)?(?P<domain>(?:history|biography)\.com)/player/(?P<id>\d+)'
  296. _TESTS = []
  297. def _real_extract(self, url):
  298. domain, video_id = re.match(self._VALID_URL, url).groups()
  299. return self._extract_aetn_info(domain, 'id', video_id, url)
  300. class BiographyIE(AENetworksBaseIE):
  301. _VALID_URL = r'https?://(?:www\.)?biography\.com/video/(?P<id>[^/?#&]+)'
  302. _TESTS = [{
  303. 'url': 'https://www.biography.com/video/vincent-van-gogh-full-episode-2075049808',
  304. 'info_dict': {
  305. 'id': '30322987',
  306. 'ext': 'mp4',
  307. 'title': 'Vincent Van Gogh - Full Episode',
  308. 'description': 'A full biography about the most influential 20th century painter, Vincent Van Gogh.',
  309. 'timestamp': 1311970571,
  310. 'upload_date': '20110729',
  311. 'uploader': 'AENE-NEW',
  312. },
  313. 'params': {
  314. # m3u8 download
  315. 'skip_download': True,
  316. },
  317. 'add_ie': ['ThePlatform'],
  318. }]
  319. def _real_extract(self, url):
  320. display_id = self._match_id(url)
  321. webpage = self._download_webpage(url, display_id)
  322. player_url = self._search_regex(
  323. r'<phoenix-iframe[^>]+src="(%s)' % HistoryPlayerIE._VALID_URL,
  324. webpage, 'player URL')
  325. return self.url_result(player_url, HistoryPlayerIE.ie_key())