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.

214 lines
7.9 KiB

10 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. )
  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. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. webpage = self._download_webpage(url, video_id)
  39. theplatform_url = self._search_regex(
  40. '(?:class="video-player video-player-full" data-mpx-url|class="player" src)="(.*?)"',
  41. webpage, 'theplatform url').replace('_no_endcard', '')
  42. if theplatform_url.startswith('//'):
  43. theplatform_url = 'http:' + theplatform_url
  44. return self.url_result(theplatform_url)
  45. class NBCSportsVPlayerIE(InfoExtractor):
  46. _VALID_URL = r'https?://vplayer\.nbcsports\.com/(?:[^/]+/)+(?P<id>[0-9a-zA-Z_]+)'
  47. _TESTS = [{
  48. 'url': 'https://vplayer.nbcsports.com/p/BxmELC/nbcsports_share/select/9CsDKds0kvHI',
  49. 'info_dict': {
  50. 'id': '9CsDKds0kvHI',
  51. 'ext': 'flv',
  52. 'description': 'md5:df390f70a9ba7c95ff1daace988f0d8d',
  53. 'title': 'Tyler Kalinoski hits buzzer-beater to lift Davidson',
  54. }
  55. }, {
  56. 'url': 'http://vplayer.nbcsports.com/p/BxmELC/nbc_embedshare/select/_hqLjQ95yx8Z',
  57. 'only_matching': True,
  58. }]
  59. @staticmethod
  60. def _extract_url(webpage):
  61. iframe_m = re.search(
  62. r'<iframe[^>]+src="(?P<url>https?://vplayer\.nbcsports\.com/[^"]+)"', webpage)
  63. if iframe_m:
  64. return iframe_m.group('url')
  65. def _real_extract(self, url):
  66. video_id = self._match_id(url)
  67. webpage = self._download_webpage(url, video_id)
  68. theplatform_url = self._og_search_video_url(webpage)
  69. return self.url_result(theplatform_url, 'ThePlatform')
  70. class NBCSportsIE(InfoExtractor):
  71. # Does not include https becuase its certificate is invalid
  72. _VALID_URL = r'http://www\.nbcsports\.com//?(?:[^/]+/)+(?P<id>[0-9a-z-]+)'
  73. _TEST = {
  74. 'url': 'http://www.nbcsports.com//college-basketball/ncaab/tom-izzo-michigan-st-has-so-much-respect-duke',
  75. 'info_dict': {
  76. 'id': 'PHJSaFWbrTY9',
  77. 'ext': 'flv',
  78. 'title': 'Tom Izzo, Michigan St. has \'so much respect\' for Duke',
  79. 'description': 'md5:ecb459c9d59e0766ac9c7d5d0eda8113',
  80. }
  81. }
  82. def _real_extract(self, url):
  83. video_id = self._match_id(url)
  84. webpage = self._download_webpage(url, video_id)
  85. return self.url_result(
  86. NBCSportsVPlayerIE._extract_url(webpage), 'NBCSportsVPlayer')
  87. class NBCNewsIE(InfoExtractor):
  88. _VALID_URL = r'''(?x)https?://(?:www\.)?nbcnews\.com/
  89. (?:video/.+?/(?P<id>\d+)|
  90. (?:feature|nightly-news)/[^/]+/(?P<title>.+))
  91. '''
  92. _TESTS = [
  93. {
  94. 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
  95. 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
  96. 'info_dict': {
  97. 'id': '52753292',
  98. 'ext': 'flv',
  99. 'title': 'Crew emerges after four-month Mars food study',
  100. 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  101. },
  102. },
  103. {
  104. 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
  105. 'md5': 'b2421750c9f260783721d898f4c42063',
  106. 'info_dict': {
  107. 'id': 'I1wpAI_zmhsQ',
  108. 'ext': 'mp4',
  109. 'title': 'How Twitter Reacted To The Snowden Interview',
  110. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  111. },
  112. 'add_ie': ['ThePlatform'],
  113. },
  114. {
  115. 'url': 'http://www.nbcnews.com/feature/dateline-full-episodes/full-episode-family-business-n285156',
  116. 'md5': 'fdbf39ab73a72df5896b6234ff98518a',
  117. 'info_dict': {
  118. 'id': 'Wjf9EDR3A_60',
  119. 'ext': 'mp4',
  120. 'title': 'FULL EPISODE: Family Business',
  121. 'description': 'md5:757988edbaae9d7be1d585eb5d55cc04',
  122. },
  123. },
  124. {
  125. 'url': 'http://www.nbcnews.com/nightly-news/video/nightly-news-with-brian-williams-full-broadcast-february-4-394064451844',
  126. 'md5': 'b5dda8cddd8650baa0dcb616dd2cf60d',
  127. 'info_dict': {
  128. 'id': 'sekXqyTVnmN3',
  129. 'ext': 'mp4',
  130. 'title': 'Nightly News with Brian Williams Full Broadcast (February 4)',
  131. 'description': 'md5:1c10c1eccbe84a26e5debb4381e2d3c5',
  132. },
  133. },
  134. ]
  135. def _real_extract(self, url):
  136. mobj = re.match(self._VALID_URL, url)
  137. video_id = mobj.group('id')
  138. if video_id is not None:
  139. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  140. info = all_info.find('video')
  141. return {
  142. 'id': video_id,
  143. 'title': info.find('headline').text,
  144. 'ext': 'flv',
  145. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  146. 'description': compat_str(info.find('caption').text),
  147. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  148. }
  149. else:
  150. # "feature" and "nightly-news" pages use theplatform.com
  151. title = mobj.group('title')
  152. webpage = self._download_webpage(url, title)
  153. bootstrap_json = self._search_regex(
  154. r'var\s+(?:bootstrapJson|playlistData)\s*=\s*({.+});?\s*$',
  155. webpage, 'bootstrap json', flags=re.MULTILINE)
  156. bootstrap = self._parse_json(bootstrap_json, video_id)
  157. info = bootstrap['results'][0]['video']
  158. mpxid = info['mpxId']
  159. base_urls = [
  160. info['fallbackPlaylistUrl'],
  161. info['associatedPlaylistUrl'],
  162. ]
  163. for base_url in base_urls:
  164. if not base_url:
  165. continue
  166. playlist_url = base_url + '?form=MPXNBCNewsAPI'
  167. try:
  168. all_videos = self._download_json(playlist_url, title)
  169. except ExtractorError as ee:
  170. if isinstance(ee.cause, compat_HTTPError):
  171. continue
  172. raise
  173. if not all_videos or 'videos' not in all_videos:
  174. continue
  175. try:
  176. info = next(v for v in all_videos['videos'] if v['mpxId'] == mpxid)
  177. break
  178. except StopIteration:
  179. continue
  180. if info is None:
  181. raise ExtractorError('Could not find video in playlists')
  182. return {
  183. '_type': 'url',
  184. # We get the best quality video
  185. 'url': info['videoAssets'][-1]['publicUrl'],
  186. 'ie_key': 'ThePlatform',
  187. }