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