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.

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