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.

273 lines
10 KiB

11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_HTTPError
  5. from ..utils import (
  6. ExtractorError,
  7. find_xpath_attr,
  8. lowercase_escape,
  9. smuggle_url,
  10. unescapeHTML,
  11. )
  12. class NBCIE(InfoExtractor):
  13. _VALID_URL = r'https?://www\.nbc\.com/(?:[^/]+/)+(?P<id>n?\d+)'
  14. _TESTS = [
  15. {
  16. 'url': 'http://www.nbc.com/the-tonight-show/segments/112966',
  17. 'info_dict': {
  18. 'id': '112966',
  19. 'ext': 'mp4',
  20. 'title': 'Jimmy Fallon Surprises Fans at Ben & Jerry\'s',
  21. 'description': 'Jimmy gives out free scoops of his new "Tonight Dough" ice cream flavor by surprising customers at the Ben & Jerry\'s scoop shop.',
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. },
  27. },
  28. {
  29. 'url': 'http://www.nbc.com/the-tonight-show/episodes/176',
  30. 'info_dict': {
  31. 'id': '176',
  32. 'ext': 'flv',
  33. 'title': 'Ricky Gervais, Steven Van Zandt, ILoveMakonnen',
  34. 'description': 'A brand new episode of The Tonight Show welcomes Ricky Gervais, Steven Van Zandt and ILoveMakonnen.',
  35. },
  36. 'skip': '404 Not Found',
  37. },
  38. {
  39. 'url': 'http://www.nbc.com/saturday-night-live/video/star-wars-teaser/2832821',
  40. 'info_dict': {
  41. 'id': '2832821',
  42. 'ext': 'mp4',
  43. 'title': 'Star Wars Teaser',
  44. 'description': 'md5:0b40f9cbde5b671a7ff62fceccc4f442',
  45. },
  46. 'params': {
  47. # m3u8 download
  48. 'skip_download': True,
  49. },
  50. 'skip': 'Only works from US',
  51. },
  52. {
  53. # This video has expired but with an escaped embedURL
  54. 'url': 'http://www.nbc.com/parenthood/episode-guide/season-5/just-like-at-home/515',
  55. 'only_matching': True,
  56. }
  57. ]
  58. def _real_extract(self, url):
  59. video_id = self._match_id(url)
  60. webpage = self._download_webpage(url, video_id)
  61. theplatform_url = unescapeHTML(lowercase_escape(self._html_search_regex(
  62. [
  63. r'(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
  64. r'<iframe[^>]+src="((?:https?:)?//player\.theplatform\.com/[^"]+)"',
  65. r'"embedURL"\s*:\s*"([^"]+)"'
  66. ],
  67. webpage, 'theplatform url').replace('_no_endcard', '').replace('\\/', '/')))
  68. if theplatform_url.startswith('//'):
  69. theplatform_url = 'http:' + theplatform_url
  70. return {
  71. '_type': 'url_transparent',
  72. 'url': smuggle_url(theplatform_url, {'source_url': url}),
  73. 'id': video_id,
  74. }
  75. class NBCSportsVPlayerIE(InfoExtractor):
  76. _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
  77. _TESTS = [{
  78. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
  79. 'info_dict': {
  80. 'id': '9CsDKds0kvHI',
  81. 'ext': 'flv',
  82. 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
  83. 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
  84. }
  85. }, {
  86. 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
  87. 'only_matching': True,
  88. }]
  89. @staticmethod
  90. def _extract_url(webpage):
  91. iframe_m = re.search(
  92. r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
  93. if iframe_m:
  94. return iframe_m.group('url')
  95. def _real_extract(self, url):
  96. video_id = self._match_id(url)
  97. webpage = self._download_webpage(url, video_id)
  98. theplatform_url = self._og_search_video_url(webpage)
  99. return self.url_result(theplatform_url, 'ThePlatform')
  100. class NBCSportsIE(InfoExtractor):
  101. # Does not include https because its certificate is invalid
  102. _VALID_URL = r'http://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
  103. _TEST = {
  104. 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
  105. 'info_dict': {
  106. 'id': 'PHJSaFWbrTY9',
  107. 'ext': 'flv',
  108. 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
  109. 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
  110. }
  111. }
  112. def _real_extract(self, url):
  113. video_id = self._match_id(url)
  114. webpage = self._download_webpage(url, video_id)
  115. return self.url_result(
  116. NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
  117. class NBCNewsIE(InfoExtractor):
  118. _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
  119. (?:video/.+?/(?P<id>\d+)|
  120. (?:watch|feature|nightly-news)/[^/]+/(?P<title>.+))
  121. '''
  122. _TESTS = [
  123. {
  124. 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
  125. 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
  126. 'info_dict': {
  127. 'id': '52753292',
  128. 'ext': 'flv',
  129. 'title': 'Crew emerges after four-month Mars food study',
  130. 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  131. },
  132. },
  133. {
  134. 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
  135. 'md5': 'b2421750c9f260783721d898f4c42063',
  136. 'info_dict': {
  137. 'id': 'I1wpAI_zmhsQ',
  138. 'ext': 'mp4',
  139. 'title': 'How Twitter Reacted To The Snowden Interview',
  140. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  141. },
  142. 'add_ie': ['ThePlatform'],
  143. },
  144. {
  145. 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
  146. 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
  147. 'info_dict': {
  148. 'id': 'Wjf9EDR3A_60',
  149. 'ext': 'mp4',
  150. 'title': 'FULL EPISODE: Family Business',
  151. 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
  152. },
  153. },
  154. {
  155. 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
  156. 'md5': 'b5dda8cddd8650baa0dcb616dd2cf60d',
  157. 'info_dict': {
  158. 'id': 'sekXqyTVnmN3',
  159. 'ext': 'mp4',
  160. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  161. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  162. },
  163. },
  164. {
  165. 'url': 'http://www.nbcnews.com/watch/dateline/full-episode--deadly-betrayal-386250819952',
  166. 'only_matching': True,
  167. },
  168. ]
  169. def _real_extract(self, url):
  170. mobj = re.match(self._VALID_URL, url)
  171. video_id = mobj.group('id')
  172. if video_id is not None:
  173. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  174. info = all_info.find('video')
  175. return {
  176. 'id': video_id,
  177. 'title': info.find('headline').text,
  178. 'ext': 'flv',
  179. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  180. 'description': info.find('caption').text,
  181. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  182. }
  183. else:
  184. # "feature" and "nightly-news" pages use theplatform.com
  185. title = mobj.group('title')
  186. webpage = self._download_webpage(url, title)
  187. bootstrap_json = self._search_regex(
  188. r'var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
  189. webpage, 'bootstrap json', flags=re.MULTILINE)
  190. bootstrap = self._parse_json(bootstrap_json, video_id)
  191. info = bootstrap['results'][0]['video']
  192. mpxid = info['mpxId']
  193. base_urls = [
  194. info['fallbackPlaylistUrl'],
  195. info['associatedPlaylistUrl'],
  196. ]
  197. for base_url in base_urls:
  198. if not base_url:
  199. continue
  200. playlist_url = base_url + '?form=MPXNBCNewsAPI'
  201. try:
  202. all_videos = self._download_json(playlist_url, title)
  203. except ExtractorError as ee:
  204. if isinstance(ee.cause, compat_HTTPError):
  205. continue
  206. raise
  207. if not all_videos or 'videos' not in all_videos:
  208. continue
  209. try:
  210. info = next(v for v in all_videos['videos'] if v['mpxId'] == mpxid)
  211. break
  212. except StopIteration:
  213. continue
  214. if info is None:
  215. raise ExtractorError('Could not find video in playlists')
  216. return {
  217. '_type': 'url',
  218. # We get the best quality video
  219. 'url': info['videoAssets'][-1]['publicUrl'],
  220. 'ie_key': 'ThePlatform',
  221. }
  222. class MSNBCIE(InfoExtractor):
  223. # https URLs redirect to corresponding http ones
  224. _VALID_URL = r'http://www\.msnbc\.com/[^/]+/watch/(?P<id>[^/]+)'
  225. _TEST = {
  226. 'url': 'http://www.msnbc.com/all-in-with-chris-hayes/watch/the-chaotic-gop-immigration-vote-314487875924',
  227. 'md5': '6d236bf4f3dddc226633ce6e2c3f814d',
  228. 'info_dict': {
  229. 'id': 'n_hayes_Aimm_140801_272214',
  230. 'ext': 'mp4',
  231. 'title': 'The chaotic GOP immigration vote',
  232. '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.',
  233. 'thumbnail': 're:^https?://.*\.jpg$',
  234. 'timestamp': 1406937606,
  235. 'upload_date': '20140802',
  236. 'categories': ['MSNBC/Topics/Franchise/Best of last night', 'MSNBC/Topics/General/Congress'],
  237. },
  238. }
  239. def _real_extract(self, url):
  240. video_id = self._match_id(url)
  241. webpage = self._download_webpage(url, video_id)
  242. embed_url = self._html_search_meta('embedURL', webpage)
  243. return self.url_result(embed_url)