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.

450 lines
18 KiB

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