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.

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