nbc.py 15 KB

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