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.

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