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.

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