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.

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