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.

99 lines
3.8 KiB

11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import find_xpath_attr, compat_str
  6. class NBCIE(InfoExtractor):
  7. _VALID_URL = r'http://www\.nbc\.com/[^/]+/video/[^/]+/(?P<id>n?\d+)'
  8. _TEST = {
  9. 'url': 'http://www.nbc.com/chicago-fire/video/i-am-a-firefighter/2734188',
  10. 'md5': '54d0fbc33e0b853a65d7b4de5c06d64e',
  11. 'info_dict': {
  12. 'id': 'u1RInQZRN7QJ',
  13. 'ext': 'flv',
  14. 'title': 'I Am a Firefighter',
  15. 'description': 'An emergency puts Dawson\'sf irefighter skills to the ultimate test in this four-part digital series.',
  16. },
  17. }
  18. def _real_extract(self, url):
  19. mobj = re.match(self._VALID_URL, url)
  20. video_id = mobj.group('id')
  21. webpage = self._download_webpage(url, video_id)
  22. theplatform_url = self._search_regex('class="video-player video-player-full" data-mpx-url="(.*?)"', webpage, 'theplatform url')
  23. if theplatform_url.startswith('//'):
  24. theplatform_url = 'http:' + theplatform_url
  25. return self.url_result(theplatform_url)
  26. class NBCNewsIE(InfoExtractor):
  27. _VALID_URL = r'''(?x)https?://www\.nbcnews\.com/
  28. ((video/.+?/(?P<id>\d+))|
  29. (feature/[^/]+/(?P<title>.+)))
  30. '''
  31. _TESTS = [
  32. {
  33. 'url': 'http://www.nbcnews.com/video/nbc-news/52753292',
  34. 'md5': '47abaac93c6eaf9ad37ee6c4463a5179',
  35. 'info_dict': {
  36. 'id': '52753292',
  37. 'ext': 'flv',
  38. 'title': 'Crew emerges after four-month Mars food study',
  39. 'description': 'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  40. },
  41. },
  42. {
  43. 'url': 'http://www.nbcnews.com/feature/edward-snowden-interview/how-twitter-reacted-snowden-interview-n117236',
  44. 'md5': 'b2421750c9f260783721d898f4c42063',
  45. 'info_dict': {
  46. 'id': 'I1wpAI_zmhsQ',
  47. 'ext': 'flv',
  48. 'title': 'How Twitter Reacted To The Snowden Interview',
  49. 'description': 'md5:65a0bd5d76fe114f3c2727aa3a81fe64',
  50. },
  51. 'add_ie': ['ThePlatform'],
  52. },
  53. ]
  54. def _real_extract(self, url):
  55. mobj = re.match(self._VALID_URL, url)
  56. video_id = mobj.group('id')
  57. if video_id is not None:
  58. all_info = self._download_xml('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  59. info = all_info.find('video')
  60. return {
  61. 'id': video_id,
  62. 'title': info.find('headline').text,
  63. 'ext': 'flv',
  64. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  65. 'description': compat_str(info.find('caption').text),
  66. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  67. }
  68. else:
  69. # "feature" pages use theplatform.com
  70. title = mobj.group('title')
  71. webpage = self._download_webpage(url, title)
  72. bootstrap_json = self._search_regex(
  73. r'var bootstrapJson = ({.+})\s*$', webpage, 'bootstrap json',
  74. flags=re.MULTILINE)
  75. bootstrap = json.loads(bootstrap_json)
  76. info = bootstrap['results'][0]['video']
  77. playlist_url = info['fallbackPlaylistUrl'] + '?form=MPXNBCNewsAPI'
  78. mpxid = info['mpxId']
  79. all_videos = self._download_json(playlist_url, title)['videos']
  80. # The response contains additional videos
  81. info = next(v for v in all_videos if v['mpxId'] == mpxid)
  82. return {
  83. '_type': 'url',
  84. # We get the best quality video
  85. 'url': info['videoAssets'][-1]['publicUrl'],
  86. 'ie_key': 'ThePlatform',
  87. }