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.

33 lines
1.2 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import find_xpath_attr, compat_str
  5. class NBCNewsIE(InfoExtractor):
  6. _VALID_URL = r'https?://www\.nbcnews\.com/video/.+?/(?P<id>\d+)'
  7. _TEST = {
  8. u'url': u'http://www.nbcnews.com/video/nbc-news/52753292',
  9. u'file': u'52753292.flv',
  10. u'md5': u'47abaac93c6eaf9ad37ee6c4463a5179',
  11. u'info_dict': {
  12. u'title': u'Crew emerges after four-month Mars food study',
  13. u'description': u'md5:24e632ffac72b35f8b67a12d1b6ddfc1',
  14. },
  15. }
  16. def _real_extract(self, url):
  17. mobj = re.match(self._VALID_URL, url)
  18. video_id = mobj.group('id')
  19. info_xml = self._download_webpage('http://www.nbcnews.com/id/%s/displaymode/1219' % video_id, video_id)
  20. info = xml.etree.ElementTree.fromstring(info_xml.encode('utf-8')).find('video')
  21. return {'id': video_id,
  22. 'title': info.find('headline').text,
  23. 'ext': 'flv',
  24. 'url': find_xpath_attr(info, 'media', 'type', 'flashVideo').text,
  25. 'description': compat_str(info.find('caption').text),
  26. 'thumbnail': find_xpath_attr(info, 'media', 'type', 'thumbnail').text,
  27. }