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.

265 lines
10 KiB

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