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.

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