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.

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