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.

54 lines
1.9 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. smuggle_url,
  5. url_basename,
  6. )
  7. class NationalGeographicIE(InfoExtractor):
  8. _VALID_URL = r'http://video\.nationalgeographic\.com/.*?'
  9. _TESTS = [
  10. {
  11. 'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo',
  12. 'info_dict': {
  13. 'id': '4DmDACA6Qtk_',
  14. 'ext': 'flv',
  15. 'title': 'Mating Crabs Busted by Sharks',
  16. 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3',
  17. },
  18. 'add_ie': ['ThePlatform'],
  19. },
  20. {
  21. 'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws',
  22. 'info_dict': {
  23. 'id': '_JeBD_D7PlS5',
  24. 'ext': 'flv',
  25. 'title': 'The Real Jaws',
  26. 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6',
  27. },
  28. 'add_ie': ['ThePlatform'],
  29. },
  30. ]
  31. def _real_extract(self, url):
  32. name = url_basename(url)
  33. webpage = self._download_webpage(url, name)
  34. feed_url = self._search_regex(
  35. r'data-feed-url="([^"]+)"', webpage, 'feed url')
  36. guid = self._search_regex(
  37. r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"',
  38. webpage, 'guid')
  39. feed = self._download_xml('%s?byGuid=%s' % (feed_url, guid), name)
  40. content = feed.find('.//{http://search.yahoo.com/mrss/}content')
  41. theplatform_id = url_basename(content.attrib.get('url'))
  42. return self.url_result(smuggle_url(
  43. 'http://link.theplatform.com/s/ngs/%s?format=SMIL&formats=MPEG4&manifest=f4m' % theplatform_id,
  44. # For some reason, the normal links don't work and we must force
  45. # the use of f4m
  46. {'force_smil_url': True}))