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.

373 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. 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. def _real_extract(self, url):
  68. video_id = self._match_id(url)
  69. webpage = self._download_webpage(url, video_id)
  70. theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
  71. [
  72. r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
  73. r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
  74. r'"embedURL"\s*:\s*"([^"]+)"'
  75. ],
  76. webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
  77. if theplatform_url.startswith('//'):
  78. theplatform_url = 'http:' + theplatform_url
  79. return {
  80. '_type': 'url_transparent',
  81. 'ie_key': 'ThePlatform',
  82. 'url': smuggle_url(theplatform_url, {'source_url': url}),
  83. 'id': video_id,
  84. }
  85. class NBCSportsVPlayerIE(InfoExtractor):
  86. _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
  87. _TESTS = [{
  88. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
  89. 'info_dict': {
  90. 'id': '9CsDKds0kvHI',
  91. 'ext': 'flv',
  92. 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
  93. 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
  94. 'timestamp': 1426270238,
  95. 'upload_date': '20150313',
  96. 'uploader': 'NBCU-SPORTS',
  97. }
  98. }, {
  99. 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
  100. 'only_matching': True,
  101. }]
  102. @staticmethod
  103. def _extract_url(webpage):
  104. iframe_m = re.search(
  105. r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
  106. if iframe_m:
  107. return iframe_m.group('url')
  108. def _real_extract(self, url):
  109. video_id = self._match_id(url)
  110. webpage = self._download_webpage(url, video_id)
  111. theplatform_url = self._og_search_video_url(webpage)
  112. return self.url_result(theplatform_url, 'ThePlatform')
  113. class NBCSportsIE(InfoExtractor):
  114. # Does not include https because its certificate is invalid
  115. _VALID_URL = r'https?://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
  116. _TEST = {
  117. 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
  118. 'info_dict': {
  119. 'id': 'PHJSaFWbrTY9',
  120. 'ext': 'flv',
  121. 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
  122. 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
  123. 'uploader': 'NBCU-SPORTS',
  124. 'upload_date': '20150330',
  125. 'timestamp': 1427726529,
  126. }
  127. }
  128. def _real_extract(self, url):
  129. video_id = self._match_id(url)
  130. webpage = self._download_webpage(url, video_id)
  131. return self.url_result(
  132. NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
  133. class CSNNEIE(InfoExtractor):
  134. _VALID_URL = r'https?://www\.csnne\.com/video/(?P<id>[0-9a-z-]+)'
  135. _TEST = {
  136. 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
  137. 'info_dict': {
  138. 'id': 'yvBLLUgQ8WU0',
  139. 'ext': 'mp4',
  140. 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
  141. 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
  142. 'timestamp': 1459369979,
  143. 'upload_date': '20160330',
  144. 'uploader': 'NBCU-SPORTS',
  145. }
  146. }
  147. def _real_extract(self, url):
  148. display_id = self._match_id(url)
  149. webpage = self._download_webpage(url, display_id)
  150. return {
  151. '_type': 'url_transparent',
  152. 'ie_key': 'ThePlatform',
  153. 'url': self._html_search_meta('twitter:player:stream', webpage),
  154. 'display_id': display_id,
  155. }
  156. class NBCNewsIE(ThePlatformIE):
  157. _VALID_URL = r'''(?x)https?://(?:www\.)?(?:nbcnews|today)\.com/
  158. (?:video/.+?/(?P<id>\d+)|
  159. ([^/]+/)*(?P<display_id>[^/?]+))
  160. '''
  161. _TESTS = [
  162. {
  163. 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
  164. 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
  165. 'info_dict': {
  166. 'id': '52753292',
  167. 'ext': 'flv',
  168. 'title': 'Crew emerges after four-month Mars food study',
  169. 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  170. },
  171. },
  172. {
  173. 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
  174. 'md5': 'af1adfa51312291a017720403826bb64',
  175. 'info_dict': {
  176. 'id': '269389891880',
  177. 'ext': 'mp4',
  178. 'title': 'How Twitter Reacted To The Snowden Interview',
  179. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  180. },
  181. },
  182. {
  183. 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
  184. 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
  185. 'info_dict': {
  186. 'id': 'Wjf9EDR3A_60',
  187. 'ext': 'mp4',
  188. 'title': 'FULL EPISODE: Family Business',
  189. 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
  190. },
  191. 'skip': 'This page is unavailable.',
  192. },
  193. {
  194. 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
  195. 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
  196. 'info_dict': {
  197. 'id': '394064451844',
  198. 'ext': 'mp4',
  199. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  200. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  201. },
  202. },
  203. {
  204. 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
  205. 'md5': 'a49e173825e5fcd15c13fc297fced39d',
  206. 'info_dict': {
  207. 'id': '529953347624',
  208. 'ext': 'mp4',
  209. 'title': 'Volkswagen U.S. Chief: We \'Totally Screwed Up\'',
  210. 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
  211. },
  212. 'expected_warnings': ['http-6000 is not available']
  213. },
  214. {
  215. 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
  216. 'md5': '118d7ca3f0bea6534f119c68ef539f71',
  217. 'info_dict': {
  218. 'id': '669831235788',
  219. 'ext': 'mp4',
  220. 'title': 'See the aurora borealis from space in stunning new NASA video',
  221. 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
  222. 'upload_date': '20160420',
  223. 'timestamp': 1461152093,
  224. },
  225. },
  226. {
  227. 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
  228. 'only_matching': True,
  229. },
  230. ]
  231. def _real_extract(self, url):
  232. mobj = re.match(self._VALID_URL, url)
  233. video_id = mobj.group('id')
  234. if video_id is not None:
  235. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  236. info = all_info.find('video')
  237. return {
  238. 'id': video_id,
  239. 'title': info.find('headline').text,
  240. 'ext': 'flv',
  241. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  242. 'description': info.find('caption').text,
  243. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  244. }
  245. else:
  246. # "feature" and "nightly-news" pages use theplatform.com
  247. display_id = mobj.group('display_id')
  248. webpage = self._download_webpage(url, display_id)
  249. info = None
  250. bootstrap_json = self._search_regex(
  251. r'(?m)var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
  252. webpage, 'bootstrap json', default=None)
  253. if bootstrap_json:
  254. bootstrap = self._parse_json(bootstrap_json, display_id)
  255. info = bootstrap['results'][0]['video']
  256. else:
  257. player_instance_json = self._search_regex(
  258. r'videoObj\s*:\s*({.+})', webpage, 'player instance', default=None)
  259. if not player_instance_json:
  260. player_instance_json = self._html_search_regex(
  261. r'data-video="([^"]+)"', webpage, 'video json')
  262. info = self._parse_json(player_instance_json, display_id)
  263. video_id = info['mpxId']
  264. title = info['title']
  265. subtitles = {}
  266. caption_links = info.get('captionLinks')
  267. if caption_links:
  268. for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
  269. sub_url = caption_links.get(sub_key)
  270. if sub_url:
  271. subtitles.setdefault('en', []).append({
  272. 'url': sub_url,
  273. 'ext': sub_ext,
  274. })
  275. formats = []
  276. for video_asset in info['videoAssets']:
  277. video_url = video_asset.get('publicUrl')
  278. if not video_url:
  279. continue
  280. container = video_asset.get('format')
  281. asset_type = video_asset.get('assetType') or ''
  282. if container == 'ISM' or asset_type == 'FireTV-Once':
  283. continue
  284. elif asset_type == 'OnceURL':
  285. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  286. video_url, video_id)
  287. formats.extend(tp_formats)
  288. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  289. else:
  290. tbr = int_or_none(video_asset.get('bitRate') or video_asset.get('bitrate'), 1000)
  291. format_id = 'http%s' % ('-%d' % tbr if tbr else '')
  292. video_url = update_url_query(
  293. video_url, {'format': 'redirect'})
  294. # resolve the url so that we can check availability and detect the correct extension
  295. head = self._request_webpage(
  296. HEADRequest(video_url), video_id,
  297. 'Checking %s url' % format_id,
  298. '%s is not available' % format_id,
  299. fatal=False)
  300. if head:
  301. video_url = head.geturl()
  302. formats.append({
  303. 'format_id': format_id,
  304. 'url': video_url,
  305. 'width': int_or_none(video_asset.get('width')),
  306. 'height': int_or_none(video_asset.get('height')),
  307. 'tbr': tbr,
  308. 'container': video_asset.get('format'),
  309. })
  310. self._sort_formats(formats)
  311. return {
  312. 'id': video_id,
  313. 'title': title,
  314. 'description': info.get('description'),
  315. 'thumbnail': info.get('thumbnail'),
  316. 'duration': int_or_none(info.get('duration')),
  317. 'timestamp': parse_iso8601(info.get('pubDate') or info.get('pub_date')),
  318. 'formats': formats,
  319. 'subtitles': subtitles,
  320. }
  321. class MSNBCIE(InfoExtractor):
  322. # https URLs redirect to corresponding http ones
  323. _VALID_URL = r'https?://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
  324. _TEST = {
  325. 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
  326. 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
  327. 'info_dict': {
  328. 'id': 'n_hayes_Aimm_140801_272214',
  329. 'ext': 'mp4',
  330. 'title': 'The chaotic GOP immigration vote',
  331. '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.',
  332. 'thumbnail': 're:^https?://.*\.jpg$',
  333. 'timestamp': 1406937606,
  334. 'upload_date': '20140802',
  335. 'uploader': 'NBCU-NEWS',
  336. 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
  337. },
  338. }
  339. def _real_extract(self, url):
  340. video_id = self._match_id(url)
  341. webpage = self._download_webpage(url, video_id)
  342. embed_url = self._html_search_meta('embedURL', webpage)
  343. return self.url_result(embed_url)