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.

356 lines
14 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. }
  124. }
  125. def _real_extract(self, url):
  126. video_id = self._match_id(url)
  127. webpage = self._download_webpage(url, video_id)
  128. return self.url_result(
  129. NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
  130. class CSNNEIE(InfoExtractor):
  131. _VALID_URL = r'https?://www\.csnne\.com/video/(?P<id>[0-9a-z-]+)'
  132. _TEST = {
  133. 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
  134. 'info_dict': {
  135. 'id': 'yvBLLUgQ8WU0',
  136. 'ext': 'mp4',
  137. 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
  138. 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
  139. 'timestamp': 1459369979,
  140. 'upload_date': '20160330',
  141. 'uploader': 'NBCU-SPORTS',
  142. }
  143. }
  144. def _real_extract(self, url):
  145. display_id = self._match_id(url)
  146. webpage = self._download_webpage(url, display_id)
  147. return {
  148. '_type': 'url_transparent',
  149. 'ie_key': 'ThePlatform',
  150. 'url': self._html_search_meta('twitter:player:stream', webpage),
  151. 'display_id': display_id,
  152. }
  153. class NBCNewsIE(ThePlatformIE):
  154. _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
  155. (?:video/.+?/(?P<id>\d+)|
  156. ([^/]+/)*(?P<display_id>[^/?]+))
  157. '''
  158. _TESTS = [
  159. {
  160. 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
  161. 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
  162. 'info_dict': {
  163. 'id': '52753292',
  164. 'ext': 'flv',
  165. 'title': 'Crew emerges after four-month Mars food study',
  166. 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  167. },
  168. },
  169. {
  170. 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
  171. 'md5': 'af1adfa51312291a017720403826bb64',
  172. 'info_dict': {
  173. 'id': '269389891880',
  174. 'ext': 'mp4',
  175. 'title': 'How Twitter Reacted To The Snowden Interview',
  176. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  177. },
  178. },
  179. {
  180. 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
  181. 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
  182. 'info_dict': {
  183. 'id': 'Wjf9EDR3A_60',
  184. 'ext': 'mp4',
  185. 'title': 'FULL EPISODE: Family Business',
  186. 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
  187. },
  188. 'skip': 'This page is unavailable.',
  189. },
  190. {
  191. 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
  192. 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
  193. 'info_dict': {
  194. 'id': '394064451844',
  195. 'ext': 'mp4',
  196. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  197. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  198. },
  199. },
  200. {
  201. 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
  202. 'md5': 'a49e173825e5fcd15c13fc297fced39d',
  203. 'info_dict': {
  204. 'id': '529953347624',
  205. 'ext': 'mp4',
  206. 'title': 'Volkswagen U.S. Chief: We \'Totally Screwed Up\'',
  207. 'description': 'md5:d22d1281a24f22ea0880741bb4dd6301',
  208. },
  209. 'expected_warnings': ['http-6000 is not available']
  210. },
  211. {
  212. 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
  213. 'only_matching': True,
  214. },
  215. ]
  216. def _real_extract(self, url):
  217. mobj = re.match(self._VALID_URL, url)
  218. video_id = mobj.group('id')
  219. if video_id is not None:
  220. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  221. info = all_info.find('video')
  222. return {
  223. 'id': video_id,
  224. 'title': info.find('headline').text,
  225. 'ext': 'flv',
  226. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  227. 'description': info.find('caption').text,
  228. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  229. }
  230. else:
  231. # "feature" and "nightly-news" pages use theplatform.com
  232. display_id = mobj.group('display_id')
  233. webpage = self._download_webpage(url, display_id)
  234. info = None
  235. bootstrap_json = self._search_regex(
  236. r'(?m)var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
  237. webpage, 'bootstrap json', default=None)
  238. if bootstrap_json:
  239. bootstrap = self._parse_json(bootstrap_json, display_id)
  240. info = bootstrap['results'][0]['video']
  241. else:
  242. player_instance_json = self._search_regex(
  243. r'videoObj\s*:\s*({.+})', webpage, 'player instance')
  244. info = self._parse_json(player_instance_json, display_id)
  245. video_id = info['mpxId']
  246. title = info['title']
  247. subtitles = {}
  248. caption_links = info.get('captionLinks')
  249. if caption_links:
  250. for (sub_key, sub_ext) in (('smpte-tt', 'ttml'), ('web-vtt', 'vtt'), ('srt', 'srt')):
  251. sub_url = caption_links.get(sub_key)
  252. if sub_url:
  253. subtitles.setdefault('en', []).append({
  254. 'url': sub_url,
  255. 'ext': sub_ext,
  256. })
  257. formats = []
  258. for video_asset in info['videoAssets']:
  259. video_url = video_asset.get('publicUrl')
  260. if not video_url:
  261. continue
  262. container = video_asset.get('format')
  263. asset_type = video_asset.get('assetType') or ''
  264. if container == 'ISM' or asset_type == 'FireTV-Once':
  265. continue
  266. elif asset_type == 'OnceURL':
  267. tp_formats, tp_subtitles = self._extract_theplatform_smil(
  268. video_url, video_id)
  269. formats.extend(tp_formats)
  270. subtitles = self._merge_subtitles(subtitles, tp_subtitles)
  271. else:
  272. tbr = int_or_none(video_asset.get('bitRate'), 1000)
  273. format_id = 'http%s' % ('-%d' % tbr if tbr else '')
  274. video_url = update_url_query(
  275. video_url, {'format': 'redirect'})
  276. # resolve the url so that we can check availability and detect the correct extension
  277. head = self._request_webpage(
  278. HEADRequest(video_url), video_id,
  279. 'Checking %s url' % format_id,
  280. '%s is not available' % format_id,
  281. fatal=False)
  282. if head:
  283. video_url = head.geturl()
  284. formats.append({
  285. 'format_id': format_id,
  286. 'url': video_url,
  287. 'width': int_or_none(video_asset.get('width')),
  288. 'height': int_or_none(video_asset.get('height')),
  289. 'tbr': tbr,
  290. 'container': video_asset.get('format'),
  291. })
  292. self._sort_formats(formats)
  293. return {
  294. 'id': video_id,
  295. 'title': title,
  296. 'description': info.get('description'),
  297. 'thumbnail': info.get('description'),
  298. 'thumbnail': info.get('thumbnail'),
  299. 'duration': int_or_none(info.get('duration')),
  300. 'timestamp': parse_iso8601(info.get('pubDate')),
  301. 'formats': formats,
  302. 'subtitles': subtitles,
  303. }
  304. class MSNBCIE(InfoExtractor):
  305. # https URLs redirect to corresponding http ones
  306. _VALID_URL = r'https?://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
  307. _TEST = {
  308. 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
  309. 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
  310. 'info_dict': {
  311. 'id': 'n_hayes_Aimm_140801_272214',
  312. 'ext': 'mp4',
  313. 'title': 'The chaotic GOP immigration vote',
  314. '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.',
  315. 'thumbnail': 're:^https?://.*\.jpg$',
  316. 'timestamp': 1406937606,
  317. 'upload_date': '20140802',
  318. 'uploader': 'NBCU-NEWS',
  319. 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
  320. },
  321. }
  322. def _real_extract(self, url):
  323. video_id = self._match_id(url)
  324. webpage = self._download_webpage(url, video_id)
  325. embed_url = self._html_search_meta('embedURL', webpage)
  326. return self.url_result(embed_url)