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.

522 lines
20 KiB

11 years ago
  1. from __future__ import unicode_literals
  2. import base64
  3. import json
  4. import re
  5. from .common import InfoExtractor
  6. from .theplatform import ThePlatformIE
  7. from .adobepass import AdobePassIE
  8. from ..compat import compat_urllib_parse_unquote
  9. from ..utils import (
  10. int_or_none,
  11. js_to_json,
  12. parse_duration,
  13. smuggle_url,
  14. try_get,
  15. unified_timestamp,
  16. update_url_query,
  17. )
  18. class NBCIE(AdobePassIE):
  19. _VALID_URL = r'https?(?P<permalink>://(?:www\.)?nbc\.com/(?:classic-tv/)?[^/]+/video/[^/]+/(?P<id>n?\d+))'
  20. _TESTS = [
  21. {
  22. 'url': 'http://www.nbc.com/the-tonight-show/video/jimmy-fallon-surprises-fans-at-ben-jerrys/2848237',
  23. 'info_dict': {
  24. 'id': '2848237',
  25. 'ext': 'mp4',
  26. 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
  27. 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
  28. 'timestamp': 1424246400,
  29. 'upload_date': '20150218',
  30. 'uploader': 'NBCU-COM',
  31. },
  32. 'params': {
  33. # m3u8 download
  34. 'skip_download': True,
  35. },
  36. },
  37. {
  38. 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
  39. 'info_dict': {
  40. 'id': '2832821',
  41. 'ext': 'mp4',
  42. 'title': 'Star Wars Teaser',
  43. 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
  44. 'timestamp': 1417852800,
  45. 'upload_date': '20141206',
  46. 'uploader': 'NBCU-COM',
  47. },
  48. 'params': {
  49. # m3u8 download
  50. 'skip_download': True,
  51. },
  52. 'skip': 'Only works from US',
  53. },
  54. {
  55. # HLS streams requires the 'hdnea3' cookie
  56. 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
  57. 'info_dict': {
  58. 'id': '101528f5a9e8127b107e98c5e6ce4638',
  59. 'ext': 'mp4',
  60. 'title': 'Goliath',
  61. 'description': 'When an unknown soldier saves the life of the King\'s son in battle, he\'s thrust into the limelight and politics of the kingdom.',
  62. 'timestamp': 1237100400,
  63. 'upload_date': '20090315',
  64. 'uploader': 'NBCU-COM',
  65. },
  66. 'params': {
  67. 'skip_download': True,
  68. },
  69. 'skip': 'Only works from US',
  70. },
  71. {
  72. 'url': 'https://www.nbc.com/classic-tv/charles-in-charge/video/charles-in-charge-pilot/n3310',
  73. 'only_matching': True,
  74. },
  75. {
  76. # Percent escaped url
  77. 'url': 'https://www.nbc.com/up-all-night/video/day-after-valentine%27s-day/n2189',
  78. 'only_matching': True,
  79. }
  80. ]
  81. def _real_extract(self, url):
  82. permalink, video_id = re.match(self._VALID_URL, url).groups()
  83. permalink = 'http' + compat_urllib_parse_unquote(permalink)
  84. response = self._download_json(
  85. 'https://friendship.nbc.co/v2/graphql', video_id, query={
  86. 'query': '''{
  87. page(name: "%s", platform: web, type: VIDEO, userId: "0") {
  88. data {
  89. ... on VideoPageData {
  90. description
  91. episodeNumber
  92. keywords
  93. locked
  94. mpxAccountId
  95. mpxGuid
  96. rating
  97. seasonNumber
  98. secondaryTitle
  99. seriesShortTitle
  100. }
  101. }
  102. }
  103. }''' % permalink,
  104. })
  105. video_data = response['data']['page']['data']
  106. query = {
  107. 'mbr': 'true',
  108. 'manifest': 'm3u',
  109. }
  110. video_id = video_data['mpxGuid']
  111. title = video_data['secondaryTitle']
  112. if video_data.get('locked'):
  113. resource = self._get_mvpd_resource(
  114. 'nbcentertainment', title, video_id,
  115. video_data.get('rating'))
  116. query['auth'] = self._extract_mvpd_auth(
  117. url, video_id, 'nbcentertainment', resource)
  118. theplatform_url = smuggle_url(update_url_query(
  119. 'http://link.theplatform.com/s/NnzsPC/media/guid/%s/%s' % (video_data.get('mpxAccountId') or '2410887629', video_id),
  120. query), {'force_smil_url': True})
  121. return {
  122. '_type': 'url_transparent',
  123. 'id': video_id,
  124. 'title': title,
  125. 'url': theplatform_url,
  126. 'description': video_data.get('description'),
  127. 'tags': video_data.get('keywords'),
  128. 'season_number': int_or_none(video_data.get('seasonNumber')),
  129. 'episode_number': int_or_none(video_data.get('episodeNumber')),
  130. 'episode': title,
  131. 'series': video_data.get('seriesShortTitle'),
  132. 'ie_key': 'ThePlatform',
  133. }
  134. class NBCSportsVPlayerIE(InfoExtractor):
  135. _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
  136. _TESTS = [{
  137. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/9CsDKds0kvHI',
  138. 'info_dict': {
  139. 'id': '9CsDKds0kvHI',
  140. 'ext': 'mp4',
  141. 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
  142. 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
  143. 'timestamp': 1426270238,
  144. 'upload_date': '20150313',
  145. 'uploader': 'NBCU-SPORTS',
  146. }
  147. }, {
  148. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_embed/select/media/_hqLjQ95yx8Z',
  149. 'only_matching': True,
  150. }]
  151. @staticmethod
  152. def _extract_url(webpage):
  153. iframe_m = re.search(
  154. r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
  155. if iframe_m:
  156. return iframe_m.group('url')
  157. def _real_extract(self, url):
  158. video_id = self._match_id(url)
  159. webpage = self._download_webpage(url, video_id)
  160. theplatform_url = self._og_search_video_url(webpage).replace(
  161. 'vplayer.nbcsports.com', 'player.theplatform.com')
  162. return self.url_result(theplatform_url, 'ThePlatform')
  163. class NBCSportsIE(InfoExtractor):
  164. # Does not include https because its certificate is invalid
  165. _VALID_URL = r'https?://(?:www\.)?nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
  166. _TEST = {
  167. 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
  168. 'info_dict': {
  169. 'id': 'PHJSaFWbrTY9',
  170. 'ext': 'flv',
  171. 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
  172. 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
  173. 'uploader': 'NBCU-SPORTS',
  174. 'upload_date': '20150330',
  175. 'timestamp': 1427726529,
  176. }
  177. }
  178. def _real_extract(self, url):
  179. video_id = self._match_id(url)
  180. webpage = self._download_webpage(url, video_id)
  181. return self.url_result(
  182. NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
  183. class NBCSportsStreamIE(AdobePassIE):
  184. _VALID_URL = r'https?://stream\.nbcsports\.com/.+?\bpid=(?P<id>\d+)'
  185. _TEST = {
  186. 'url': 'http://stream.nbcsports.com/nbcsn/generic?pid=206559',
  187. 'info_dict': {
  188. 'id': '206559',
  189. 'ext': 'mp4',
  190. 'title': 'Amgen Tour of California Women\'s Recap',
  191. 'description': 'md5:66520066b3b5281ada7698d0ea2aa894',
  192. },
  193. 'params': {
  194. # m3u8 download
  195. 'skip_download': True,
  196. },
  197. 'skip': 'Requires Adobe Pass Authentication',
  198. }
  199. def _real_extract(self, url):
  200. video_id = self._match_id(url)
  201. live_source = self._download_json(
  202. 'http://stream.nbcsports.com/data/live_sources_%s.json' % video_id,
  203. video_id)
  204. video_source = live_source['videoSources'][0]
  205. title = video_source['title']
  206. source_url = None
  207. for k in ('source', 'msl4source', 'iossource', 'hlsv4'):
  208. sk = k + 'Url'
  209. source_url = video_source.get(sk) or video_source.get(sk + 'Alt')
  210. if source_url:
  211. break
  212. else:
  213. source_url = video_source['ottStreamUrl']
  214. is_live = video_source.get('type') == 'live' or video_source.get('status') == 'Live'
  215. resource = self._get_mvpd_resource('nbcsports', title, video_id, '')
  216. token = self._extract_mvpd_auth(url, video_id, 'nbcsports', resource)
  217. tokenized_url = self._download_json(
  218. 'https://token.playmakerservices.com/cdn',
  219. video_id, data=json.dumps({
  220. 'requestorId': 'nbcsports',
  221. 'pid': video_id,
  222. 'application': 'NBCSports',
  223. 'version': 'v1',
  224. 'platform': 'desktop',
  225. 'cdn': 'akamai',
  226. 'url': video_source['sourceUrl'],
  227. 'token': base64.b64encode(token.encode()).decode(),
  228. 'resourceId': base64.b64encode(resource.encode()).decode(),
  229. }).encode())['tokenizedUrl']
  230. formats = self._extract_m3u8_formats(tokenized_url, video_id, 'mp4')
  231. self._sort_formats(formats)
  232. return {
  233. 'id': video_id,
  234. 'title': self._live_title(title) if is_live else title,
  235. 'description': live_source.get('description'),
  236. 'formats': formats,
  237. 'is_live': is_live,
  238. }
  239. class CSNNEIE(InfoExtractor):
  240. _VALID_URL = r'https?://(?:www\.)?csnne\.com/video/(?P<id>[0-9a-z-]+)'
  241. _TEST = {
  242. 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
  243. 'info_dict': {
  244. 'id': 'yvBLLUgQ8WU0',
  245. 'ext': 'mp4',
  246. 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
  247. 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
  248. 'timestamp': 1459369979,
  249. 'upload_date': '20160330',
  250. 'uploader': 'NBCU-SPORTS',
  251. }
  252. }
  253. def _real_extract(self, url):
  254. display_id = self._match_id(url)
  255. webpage = self._download_webpage(url, display_id)
  256. return {
  257. '_type': 'url_transparent',
  258. 'ie_key': 'ThePlatform',
  259. 'url': self._html_search_meta('twitter:player:stream', webpage),
  260. 'display_id': display_id,
  261. }
  262. class NBCNewsIE(ThePlatformIE):
  263. _VALID_URL = r'(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/([^/]+/)*(?:.*-)?(?P<id>[^/?]+)'
  264. _TESTS = [
  265. {
  266. 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
  267. 'md5': 'cf4bc9e6ce0130f00f545d80ecedd4bf',
  268. 'info_dict': {
  269. 'id': '269389891880',
  270. 'ext': 'mp4',
  271. 'title': 'How Twitter Reacted To The Snowden Interview',
  272. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  273. 'timestamp': 1401363060,
  274. 'upload_date': '20140529',
  275. },
  276. },
  277. {
  278. 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
  279. 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
  280. 'info_dict': {
  281. 'id': '529953347624',
  282. 'ext': 'mp4',
  283. 'title': 'FULL EPISODE: Family Business',
  284. 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
  285. },
  286. 'skip': 'This page is unavailable.',
  287. },
  288. {
  289. 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
  290. 'md5': '8eb831eca25bfa7d25ddd83e85946548',
  291. 'info_dict': {
  292. 'id': '394064451844',
  293. 'ext': 'mp4',
  294. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  295. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  296. 'timestamp': 1423104900,
  297. 'upload_date': '20150205',
  298. },
  299. },
  300. {
  301. 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
  302. 'md5': '4a8c4cec9e1ded51060bdda36ff0a5c0',
  303. 'info_dict': {
  304. 'id': 'n431456',
  305. 'ext': 'mp4',
  306. 'title': "Volkswagen U.S. Chief: We 'Totally Screwed Up'",
  307. 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
  308. 'upload_date': '20150922',
  309. 'timestamp': 1442917800,
  310. },
  311. },
  312. {
  313. 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
  314. 'md5': '118d7ca3f0bea6534f119c68ef539f71',
  315. 'info_dict': {
  316. 'id': '669831235788',
  317. 'ext': 'mp4',
  318. 'title': 'See the aurora borealis from space in stunning new NASA video',
  319. 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
  320. 'upload_date': '20160420',
  321. 'timestamp': 1461152093,
  322. },
  323. },
  324. {
  325. 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
  326. 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
  327. 'info_dict': {
  328. 'id': '314487875924',
  329. 'ext': 'mp4',
  330. 'title': 'The chaotic GOP immigration vote',
  331. 'description': 'The Republican House votes on a border bill that has no chance of getting through the Senate or signed by the President and is drawing criticism from all sides.',
  332. 'thumbnail': r're:^https?://.*\.jpg$',
  333. 'timestamp': 1406937606,
  334. 'upload_date': '20140802',
  335. },
  336. },
  337. {
  338. 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
  339. 'only_matching': True,
  340. },
  341. {
  342. # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
  343. 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
  344. 'only_matching': True,
  345. },
  346. ]
  347. def _real_extract(self, url):
  348. video_id = self._match_id(url)
  349. webpage = self._download_webpage(url, video_id)
  350. data = self._parse_json(self._search_regex(
  351. r'window\.__data\s*=\s*({.+});', webpage,
  352. 'bootstrap json'), video_id, js_to_json)
  353. video_data = try_get(data, lambda x: x['video']['current'], dict)
  354. if not video_data:
  355. video_data = data['article']['content'][0]['primaryMedia']['video']
  356. title = video_data['headline']['primary']
  357. formats = []
  358. for va in video_data.get('videoAssets', []):
  359. public_url = va.get('publicUrl')
  360. if not public_url:
  361. continue
  362. if '://link.theplatform.com/' in public_url:
  363. public_url = update_url_query(public_url, {'format': 'redirect'})
  364. format_id = va.get('format')
  365. if format_id == 'M3U':
  366. formats.extend(self._extract_m3u8_formats(
  367. public_url, video_id, 'mp4', 'm3u8_native',
  368. m3u8_id=format_id, fatal=False))
  369. continue
  370. tbr = int_or_none(va.get('bitrate'), 1000)
  371. if tbr:
  372. format_id += '-%d' % tbr
  373. formats.append({
  374. 'format_id': format_id,
  375. 'url': public_url,
  376. 'width': int_or_none(va.get('width')),
  377. 'height': int_or_none(va.get('height')),
  378. 'tbr': tbr,
  379. 'ext': 'mp4',
  380. })
  381. self._sort_formats(formats)
  382. subtitles = {}
  383. closed_captioning = video_data.get('closedCaptioning')
  384. if closed_captioning:
  385. for cc_url in closed_captioning.values():
  386. if not cc_url:
  387. continue
  388. subtitles.setdefault('en', []).append({
  389. 'url': cc_url,
  390. })
  391. return {
  392. 'id': video_id,
  393. 'title': title,
  394. 'description': try_get(video_data, lambda x: x['description']['primary']),
  395. 'thumbnail': try_get(video_data, lambda x: x['primaryImage']['url']['primary']),
  396. 'duration': parse_duration(video_data.get('duration')),
  397. 'timestamp': unified_timestamp(video_data.get('datePublished')),
  398. 'formats': formats,
  399. 'subtitles': subtitles,
  400. }
  401. class NBCOlympicsIE(InfoExtractor):
  402. IE_NAME = 'nbcolympics'
  403. _VALID_URL = r'https?://www\.nbcolympics\.com/video/(?P<id>[a-z-]+)'
  404. _TEST = {
  405. # Geo-restricted to US
  406. 'url': 'http://www.nbcolympics.com/video/justin-roses-son-leo-was-tears-after-his-dad-won-gold',
  407. 'md5': '54fecf846d05429fbaa18af557ee523a',
  408. 'info_dict': {
  409. 'id': 'WjTBzDXx5AUq',
  410. 'display_id': 'justin-roses-son-leo-was-tears-after-his-dad-won-gold',
  411. 'ext': 'mp4',
  412. 'title': 'Rose\'s son Leo was in tears after his dad won gold',
  413. 'description': 'Olympic gold medalist Justin Rose gets emotional talking to the impact his win in men\'s golf has already had on his children.',
  414. 'timestamp': 1471274964,
  415. 'upload_date': '20160815',
  416. 'uploader': 'NBCU-SPORTS',
  417. },
  418. }
  419. def _real_extract(self, url):
  420. display_id = self._match_id(url)
  421. webpage = self._download_webpage(url, display_id)
  422. drupal_settings = self._parse_json(self._search_regex(
  423. r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
  424. webpage, 'drupal settings'), display_id)
  425. iframe_url = drupal_settings['vod']['iframe_url']
  426. theplatform_url = iframe_url.replace(
  427. 'vplayer.nbcolympics.com', 'player.theplatform.com')
  428. return {
  429. '_type': 'url_transparent',
  430. 'url': theplatform_url,
  431. 'ie_key': ThePlatformIE.ie_key(),
  432. 'display_id': display_id,
  433. }
  434. class NBCOlympicsStreamIE(AdobePassIE):
  435. IE_NAME = 'nbcolympics:stream'
  436. _VALID_URL = r'https?://stream\.nbcolympics\.com/(?P<id>[0-9a-z-]+)'
  437. _TEST = {
  438. 'url': 'http://stream.nbcolympics.com/2018-winter-olympics-nbcsn-evening-feb-8',
  439. 'info_dict': {
  440. 'id': '203493',
  441. 'ext': 'mp4',
  442. 'title': 're:Curling, Alpine, Luge [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  443. },
  444. 'params': {
  445. # m3u8 download
  446. 'skip_download': True,
  447. },
  448. }
  449. _DATA_URL_TEMPLATE = 'http://stream.nbcolympics.com/data/%s_%s.json'
  450. def _real_extract(self, url):
  451. display_id = self._match_id(url)
  452. webpage = self._download_webpage(url, display_id)
  453. pid = self._search_regex(r'pid\s*=\s*(\d+);', webpage, 'pid')
  454. resource = self._search_regex(
  455. r"resource\s*=\s*'(.+)';", webpage,
  456. 'resource').replace("' + pid + '", pid)
  457. event_config = self._download_json(
  458. self._DATA_URL_TEMPLATE % ('event_config', pid),
  459. pid)['eventConfig']
  460. title = self._live_title(event_config['eventTitle'])
  461. source_url = self._download_json(
  462. self._DATA_URL_TEMPLATE % ('live_sources', pid),
  463. pid)['videoSources'][0]['sourceUrl']
  464. media_token = self._extract_mvpd_auth(
  465. url, pid, event_config.get('requestorId', 'NBCOlympics'), resource)
  466. formats = self._extract_m3u8_formats(self._download_webpage(
  467. 'http://sp.auth.adobe.com/tvs/v1/sign', pid, query={
  468. 'cdn': 'akamai',
  469. 'mediaToken': base64.b64encode(media_token.encode()),
  470. 'resource': base64.b64encode(resource.encode()),
  471. 'url': source_url,
  472. }), pid, 'mp4')
  473. self._sort_formats(formats)
  474. return {
  475. 'id': pid,
  476. 'display_id': display_id,
  477. 'title': title,
  478. 'formats': formats,
  479. 'is_live': True,
  480. }