]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nationalgeographic.py
Update changelog.
[youtubedl] / 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/.*?'
12
13 _TESTS = [
14 {
15 'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo',
16 'info_dict': {
17 'id': '4DmDACA6Qtk_',
18 'ext': 'flv',
19 'title': 'Mating Crabs Busted by Sharks',
20 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3',
21 },
22 'add_ie': ['ThePlatform'],
23 },
24 {
25 'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws',
26 'info_dict': {
27 'id': '_JeBD_D7PlS5',
28 'ext': 'flv',
29 'title': 'The Real Jaws',
30 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6',
31 },
32 'add_ie': ['ThePlatform'],
33 },
34 ]
35
36 def _real_extract(self, url):
37 name = url_basename(url)
38
39 webpage = self._download_webpage(url, name)
40 feed_url = self._search_regex(
41 r'data-feed-url="([^"]+)"', webpage, 'feed url')
42 guid = self._search_regex(
43 r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"',
44 webpage, 'guid')
45
46 feed = self._download_xml('%s?byGuid=%s' % (feed_url, guid), name)
47 content = feed.find('.//{http://search.yahoo.com/mrss/}content')
48 theplatform_id = url_basename(content.attrib.get('url'))
49
50 return self.url_result(smuggle_url(
51 'http://link.theplatform.com/s/ngs/%s?format=SMIL&formats=MPEG4&manifest=f4m' % theplatform_id,
52 # For some reason, the normal links don't work and we must force
53 # the use of f4m
54 {'force_smil_url': True}))