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