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.

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