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.

394 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 ..utils import (
  6. find_xpath_attr,
  7. lowercase_escape,
  8. smuggle_url,
  9. unescapeHTML,
  10. update_url_query,
  11. int_or_none,
  12. HEADRequest,
  13. parse_iso8601,
  14. )
  15. class NBCIE(InfoExtractor):
  16. _VALID_URL = r'https?://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
  17. _TESTS = [
  18. {
  19. 'url': 'http://www.nbc.com/the-tonight-show/segments/112966',
  20. 'info_dict': {
  21. 'id': '112966',
  22. 'ext': 'mp4',
  23. 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
  24. 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
  25. 'timestamp': 1424246400,
  26. 'upload_date': '20150218',
  27. 'uploader': 'NBCU-COM',
  28. },
  29. 'params': {
  30. # m3u8 download
  31. 'skip_download': True,
  32. },
  33. },
  34. {
  35. 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
  36. 'info_dict': {
  37. 'id': '176',
  38. 'ext': 'flv',
  39. 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
  40. 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
  41. },
  42. 'skip': '404 Not Found',
  43. },
  44. {
  45. 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
  46. 'info_dict': {
  47. 'id': '2832821',
  48. 'ext': 'mp4',
  49. 'title': 'Star Wars Teaser',
  50. 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
  51. 'timestamp': 1417852800,
  52. 'upload_date': '20141206',
  53. 'uploader': 'NBCU-COM',
  54. },
  55. 'params': {
  56. # m3u8 download
  57. 'skip_download': True,
  58. },
  59. 'skip': 'Only works from US',
  60. },
  61. {
  62. # This video has expired but with an escaped embedURL
  63. 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
  64. 'only_matching': True,
  65. },
  66. {
  67. # HLS streams requires the 'hdnea3' cookie
  68. 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
  69. 'info_dict': {
  70. 'id': 'n1806',
  71. 'ext': 'mp4',
  72. 'title': 'Goliath',
  73. '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.',
  74. 'timestamp': 1237100400,
  75. 'upload_date': '20090315',
  76. 'uploader': 'NBCU-COM',
  77. },
  78. 'params': {
  79. 'skip_download': True,
  80. },
  81. 'skip': 'Only works from US',
  82. }
  83. ]
  84. def _real_extract(self, url):
  85. video_id = self._match_id(url)
  86. webpage = self._download_webpage(url, video_id)
  87. theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
  88. [
  89. r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
  90. r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
  91. r'"embedURL"\s*:\s*"([^"]+)"'
  92. ],
  93. webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
  94. if theplatform_url.startswith('//'):
  95. theplatform_url = 'http:' + theplatform_url
  96. return {
  97. '_type': 'url_transparent',
  98. 'ie_key': 'ThePlatform',
  99. 'url': smuggle_url(theplatform_url, {'source_url': url}),
  100. 'id': video_id,
  101. }
  102. class NBCSportsVPlayerIE(InfoExtractor):
  103. _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
  104. _TESTS = [{
  105. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
  106. 'info_dict': {
  107. 'id': '9CsDKds0kvHI',
  108. 'ext': 'flv',
  109. 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
  110. 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
  111. 'timestamp': 1426270238,
  112. 'upload_date': '20150313',
  113. 'uploader': 'NBCU-SPORTS',
  114. }
  115. }, {
  116. 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
  117. 'only_matching': True,
  118. }]
  119. @staticmethod
  120. def _extract_url(webpage):
  121. iframe_m = re.search(
  122. r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
  123. if iframe_m:
  124. return iframe_m.group('url')
  125. def _real_extract(self, url):
  126. video_id = self._match_id(url)
  127. webpage = self._download_webpage(url, video_id)
  128. theplatform_url = self._og_search_video_url(webpage)
  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)\.com/
  175. (?:video/.+?/(?P<id>\d+)|
  176. ([^/]+/)*(?P<display_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': '269389891880',
  194. 'ext': 'mp4',
  195. 'title': 'How Twitter Reacted To The Snowden Interview',
  196. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  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': 'Wjf9EDR3A_60',
  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': '394064451844',
  215. 'ext': 'mp4',
  216. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  217. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  218. },
  219. },
  220. {
  221. 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
  222. 'md5': 'a49e173825e5fcd15c13fc297fced39d',
  223. 'info_dict': {
  224. 'id': '529953347624',
  225. 'ext': 'mp4',
  226. 'title': 'Volkswagen U.S. Chief: We \'Totally Screwed Up\'',
  227. 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
  228. },
  229. 'expected_warnings': ['http-6000 is not available']
  230. },
  231. {
  232. 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
  233. 'md5': '118d7ca3f0bea6534f119c68ef539f71',
  234. 'info_dict': {
  235. 'id': '669831235788',
  236. 'ext': 'mp4',
  237. 'title': 'See the aurora borealis from space in stunning new NASA video',
  238. 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
  239. 'upload_date': '20160420',
  240. 'timestamp': 1461152093,
  241. },
  242. },
  243. {
  244. 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
  245. 'only_matching': True,
  246. },
  247. {
  248. # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
  249. 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
  250. 'only_matching': True,
  251. },
  252. ]
  253. def _real_extract(self, url):
  254. mobj = re.match(self._VALID_URL, url)
  255. video_id = mobj.group('id')
  256. if video_id is not None:
  257. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  258. info = all_info.find('video')
  259. return {
  260. 'id': video_id,
  261. 'title': info.find('headline').text,
  262. 'ext': 'flv',
  263. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  264. 'description': info.find('caption').text,
  265. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  266. }
  267. else:
  268. # "feature" and "nightly-news" pages use theplatform.com
  269. display_id = mobj.group('display_id')
  270. webpage = self._download_webpage(url, display_id)
  271. info = None
  272. bootstrap_json = self._search_regex(
  273. [r'(?m)(?:var\s+(?:bootstrapJson|playlistData)|NEWS\.videoObj)\s*=\s*({.+});?\s*$',
  274. r'videoObj\s*:\s*({.+})', r'data-video="([^"]+)"'],
  275. webpage, 'bootstrap json', default=None)
  276. bootstrap = self._parse_json(
  277. bootstrap_json, display_id, transform_source=unescapeHTML)
  278. if 'results' in bootstrap:
  279. info = bootstrap['results'][0]['video']
  280. elif 'video' in bootstrap:
  281. info = bootstrap['video']
  282. else:
  283. info = bootstrap
  284. video_id = info['mpxId']
  285. title = info['title']
  286. subtitles = {}
  287. caption_links = info.get('captionLinks')
  288. if caption_links:
  289. for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
  290. sub_url = caption_links.get(sub_key)
  291. if sub_url:
  292. subtitles.setdefault('en', []).append({
  293. 'url': sub_url,
  294. 'ext': sub_ext,
  295. })
  296. formats = []
  297. for video_asset in info['videoAssets']:
  298. video_url = video_asset.get('publicUrl')
  299. if not video_url:
  300. continue
  301. container = video_asset.get('format')
  302. asset_type = video_asset.get('assetType') or ''
  303. if container == 'ISM' or asset_type == 'FireTV-Once':
  304. continue
  305. elif asset_type == 'OnceURL':
  306. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  307. video_url, video_id)
  308. formats.extend(tp_formats)
  309. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  310. else:
  311. tbr = int_or_none(video_asset.get('bitRate') or video_asset.get('bitrate'), 1000)
  312. format_id = 'http%s' % ('-%d' % tbr if tbr else '')
  313. video_url = update_url_query(
  314. video_url, {'format': 'redirect'})
  315. # resolve the url so that we can check availability and detect the correct extension
  316. head = self._request_webpage(
  317. HEADRequest(video_url), video_id,
  318. 'Checking %s url' % format_id,
  319. '%s is not available' % format_id,
  320. fatal=False)
  321. if head:
  322. video_url = head.geturl()
  323. formats.append({
  324. 'format_id': format_id,
  325. 'url': video_url,
  326. 'width': int_or_none(video_asset.get('width')),
  327. 'height': int_or_none(video_asset.get('height')),
  328. 'tbr': tbr,
  329. 'container': video_asset.get('format'),
  330. })
  331. self._sort_formats(formats)
  332. return {
  333. 'id': video_id,
  334. 'title': title,
  335. 'description': info.get('description'),
  336. 'thumbnail': info.get('thumbnail'),
  337. 'duration': int_or_none(info.get('duration')),
  338. 'timestamp': parse_iso8601(info.get('pubDate') or info.get('pub_date')),
  339. 'formats': formats,
  340. 'subtitles': subtitles,
  341. }
  342. class MSNBCIE(InfoExtractor):
  343. # https URLs redirect to corresponding http ones
  344. _VALID_URL = r'https?://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
  345. _TEST = {
  346. 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
  347. 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
  348. 'info_dict': {
  349. 'id': 'n_hayes_Aimm_140801_272214',
  350. 'ext': 'mp4',
  351. 'title': 'The chaotic GOP immigration vote',
  352. '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.',
  353. 'thumbnail': 're:^https?://.*\.jpg$',
  354. 'timestamp': 1406937606,
  355. 'upload_date': '20140802',
  356. 'uploader': 'NBCU-NEWS',
  357. 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
  358. },
  359. }
  360. def _real_extract(self, url):
  361. video_id = self._match_id(url)
  362. webpage = self._download_webpage(url, video_id)
  363. embed_url = self._html_search_meta('embedURL', webpage)
  364. return self.url_result(embed_url)