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.

337 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. )
  11. class NBCIE(InfoExtractor):
  12. _VALID_URL = r'https?://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.nbc.com/the-tonight-show/segments/112966',
  16. 'info_dict': {
  17. 'id': '112966',
  18. 'ext': 'mp4',
  19. 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
  20. 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
  21. 'timestamp': 1424246400,
  22. 'upload_date': '20150218',
  23. 'uploader': 'NBCU-COM',
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. },
  29. },
  30. {
  31. 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
  32. 'info_dict': {
  33. 'id': '176',
  34. 'ext': 'flv',
  35. 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
  36. 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
  37. },
  38. 'skip': '404 Not Found',
  39. },
  40. {
  41. 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
  42. 'info_dict': {
  43. 'id': '2832821',
  44. 'ext': 'mp4',
  45. 'title': 'Star Wars Teaser',
  46. 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
  47. 'timestamp': 1417852800,
  48. 'upload_date': '20141206',
  49. 'uploader': 'NBCU-COM',
  50. },
  51. 'params': {
  52. # m3u8 download
  53. 'skip_download': True,
  54. },
  55. 'skip': 'Only works from US',
  56. },
  57. {
  58. # This video has expired but with an escaped embedURL
  59. 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
  60. 'only_matching': True,
  61. },
  62. {
  63. # HLS streams requires the 'hdnea3' cookie
  64. 'url': 'http://www.nbc.com/Kings/video/goliath/n1806',
  65. 'info_dict': {
  66. 'id': 'n1806',
  67. 'ext': 'mp4',
  68. 'title': 'Goliath',
  69. '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.',
  70. 'timestamp': 1237100400,
  71. 'upload_date': '20090315',
  72. 'uploader': 'NBCU-COM',
  73. },
  74. 'params': {
  75. 'skip_download': True,
  76. },
  77. 'skip': 'Only works from US',
  78. }
  79. ]
  80. def _real_extract(self, url):
  81. video_id = self._match_id(url)
  82. webpage = self._download_webpage(url, video_id)
  83. theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
  84. [
  85. r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
  86. r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
  87. r'"embedURL"\s*:\s*"([^"]+)"'
  88. ],
  89. webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
  90. if theplatform_url.startswith('//'):
  91. theplatform_url = 'http:' + theplatform_url
  92. return {
  93. '_type': 'url_transparent',
  94. 'ie_key': 'ThePlatform',
  95. 'url': smuggle_url(theplatform_url, {'source_url': url}),
  96. 'id': video_id,
  97. }
  98. class NBCSportsVPlayerIE(InfoExtractor):
  99. _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
  100. _TESTS = [{
  101. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
  102. 'info_dict': {
  103. 'id': '9CsDKds0kvHI',
  104. 'ext': 'flv',
  105. 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
  106. 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
  107. 'timestamp': 1426270238,
  108. 'upload_date': '20150313',
  109. 'uploader': 'NBCU-SPORTS',
  110. }
  111. }, {
  112. 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
  113. 'only_matching': True,
  114. }]
  115. @staticmethod
  116. def _extract_url(webpage):
  117. iframe_m = re.search(
  118. r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
  119. if iframe_m:
  120. return iframe_m.group('url')
  121. def _real_extract(self, url):
  122. video_id = self._match_id(url)
  123. webpage = self._download_webpage(url, video_id)
  124. theplatform_url = self._og_search_video_url(webpage)
  125. return self.url_result(theplatform_url, 'ThePlatform')
  126. class NBCSportsIE(InfoExtractor):
  127. # Does not include https because its certificate is invalid
  128. _VALID_URL = r'https?://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
  129. _TEST = {
  130. 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
  131. 'info_dict': {
  132. 'id': 'PHJSaFWbrTY9',
  133. 'ext': 'flv',
  134. 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
  135. 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
  136. 'uploader': 'NBCU-SPORTS',
  137. 'upload_date': '20150330',
  138. 'timestamp': 1427726529,
  139. }
  140. }
  141. def _real_extract(self, url):
  142. video_id = self._match_id(url)
  143. webpage = self._download_webpage(url, video_id)
  144. return self.url_result(
  145. NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
  146. class CSNNEIE(InfoExtractor):
  147. _VALID_URL = r'https?://www\.csnne\.com/video/(?P<id>[0-9a-z-]+)'
  148. _TEST = {
  149. 'url': 'http://www.csnne.com/video/snc-evening-update-wright-named-red-sox-no-5-starter',
  150. 'info_dict': {
  151. 'id': 'yvBLLUgQ8WU0',
  152. 'ext': 'mp4',
  153. 'title': 'SNC evening update: Wright named Red Sox\' No. 5 starter.',
  154. 'description': 'md5:1753cfee40d9352b19b4c9b3e589b9e3',
  155. 'timestamp': 1459369979,
  156. 'upload_date': '20160330',
  157. 'uploader': 'NBCU-SPORTS',
  158. }
  159. }
  160. def _real_extract(self, url):
  161. display_id = self._match_id(url)
  162. webpage = self._download_webpage(url, display_id)
  163. return {
  164. '_type': 'url_transparent',
  165. 'ie_key': 'ThePlatform',
  166. 'url': self._html_search_meta('twitter:player:stream', webpage),
  167. 'display_id': display_id,
  168. }
  169. class NBCNewsIE(ThePlatformIE):
  170. _VALID_URL = r'''(?x)https?://(?:www\.)?(?:nbcnews|today|msnbc)\.com/
  171. (?:video/.+?/(?P<id>\d+)|
  172. ([^/]+/)*(?:.*-)?(?P<mpx_id>[^/?]+))
  173. '''
  174. _TESTS = [
  175. {
  176. 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
  177. 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
  178. 'info_dict': {
  179. 'id': '52753292',
  180. 'ext': 'flv',
  181. 'title': 'Crew emerges after four-month Mars food study',
  182. 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  183. },
  184. },
  185. {
  186. 'url': 'http://www.nbcnews.com/watch/nbcnews-com/how-twitter-reacted-to-the-snowden-interview-269389891880',
  187. 'md5': 'af1adfa51312291a017720403826bb64',
  188. 'info_dict': {
  189. 'id': '269389891880',
  190. 'ext': 'mp4',
  191. 'title': 'How Twitter Reacted To The Snowden Interview',
  192. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  193. 'uploader': 'NBCU-NEWS',
  194. 'timestamp': 1401363060,
  195. 'upload_date': '20140529',
  196. },
  197. },
  198. {
  199. 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
  200. 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
  201. 'info_dict': {
  202. 'id': '529953347624',
  203. 'ext': 'mp4',
  204. 'title': 'FULL EPISODE: Family Business',
  205. 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
  206. },
  207. 'skip': 'This page is unavailable.',
  208. },
  209. {
  210. 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
  211. 'md5': '73135a2e0ef819107bbb55a5a9b2a802',
  212. 'info_dict': {
  213. 'id': '394064451844',
  214. 'ext': 'mp4',
  215. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  216. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  217. 'timestamp': 1423104900,
  218. 'uploader': 'NBCU-NEWS',
  219. 'upload_date': '20150205',
  220. },
  221. },
  222. {
  223. 'url': 'http://www.nbcnews.com/business/autos/volkswagen-11-million-vehicles-could-have-suspect-software-emissions-scandal-n431456',
  224. 'md5': 'a49e173825e5fcd15c13fc297fced39d',
  225. 'info_dict': {
  226. 'id': '529953347624',
  227. 'ext': 'mp4',
  228. 'title': 'Volkswagen U.S. Chief:\xa0 We Have Totally Screwed Up',
  229. 'description': 'md5:c8be487b2d80ff0594c005add88d8351',
  230. 'upload_date': '20150922',
  231. 'timestamp': 1442917800,
  232. 'uploader': 'NBCU-NEWS',
  233. },
  234. },
  235. {
  236. 'url': 'http://www.today.com/video/see-the-aurora-borealis-from-space-in-stunning-new-nasa-video-669831235788',
  237. 'md5': '118d7ca3f0bea6534f119c68ef539f71',
  238. 'info_dict': {
  239. 'id': '669831235788',
  240. 'ext': 'mp4',
  241. 'title': 'See the aurora borealis from space in stunning new NASA video',
  242. 'description': 'md5:74752b7358afb99939c5f8bb2d1d04b1',
  243. 'upload_date': '20160420',
  244. 'timestamp': 1461152093,
  245. 'uploader': 'NBCU-NEWS',
  246. },
  247. },
  248. {
  249. 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
  250. 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
  251. 'info_dict': {
  252. 'id': '314487875924',
  253. 'ext': 'mp4',
  254. 'title': 'The chaotic GOP immigration vote',
  255. '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.',
  256. 'thumbnail': 're:^https?://.*\.jpg$',
  257. 'timestamp': 1406937606,
  258. 'upload_date': '20140802',
  259. 'uploader': 'NBCU-NEWS',
  260. 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
  261. },
  262. },
  263. {
  264. 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
  265. 'only_matching': True,
  266. },
  267. {
  268. # From http://www.vulture.com/2016/06/letterman-couldnt-care-less-about-late-night.html
  269. 'url': 'http://www.nbcnews.com/widget/video-embed/701714499682',
  270. 'only_matching': True,
  271. },
  272. ]
  273. def _real_extract(self, url):
  274. mobj = re.match(self._VALID_URL, url)
  275. video_id = mobj.group('id')
  276. if video_id is not None:
  277. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  278. info = all_info.find('video')
  279. return {
  280. 'id': video_id,
  281. 'title': info.find('headline').text,
  282. 'ext': 'flv',
  283. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  284. 'description': info.find('caption').text,
  285. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  286. }
  287. else:
  288. # "feature" and "nightly-news" pages use theplatform.com
  289. video_id = mobj.group('mpx_id')
  290. if not video_id.isdigit():
  291. webpage = self._download_webpage(url, video_id)
  292. info = None
  293. bootstrap_json = self._search_regex(
  294. [r'(?m)(?:var\s+(?:bootstrapJson|playlistData)|NEWS\.videoObj)\s*=\s*({.+});?\s*$',
  295. r'videoObj\s*:\s*({.+})', r'data-video="([^"]+)"'],
  296. webpage, 'bootstrap json', default=None)
  297. bootstrap = self._parse_json(
  298. bootstrap_json, video_id, transform_source=unescapeHTML)
  299. if 'results' in bootstrap:
  300. info = bootstrap['results'][0]['video']
  301. elif 'video' in bootstrap:
  302. info = bootstrap['video']
  303. else:
  304. info = bootstrap
  305. video_id = info['mpxId']
  306. return {
  307. '_type': 'url_transparent',
  308. 'id': video_id,
  309. # http://feed.theplatform.com/f/2E2eJC/nbcnews also works
  310. 'url': 'http://feed.theplatform.com/f/2E2eJC/nnd_NBCNews?byId=%s' % video_id,
  311. 'ie_key': 'ThePlatformFeed',
  312. }