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.

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