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.

429 lines
17 KiB

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