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.

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