[nationalgeographic] add support for channel.nationalgeographic.com urls
[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     update_url_query,
8 )
9
10
11 class NationalGeographicIE(InfoExtractor):
12     IE_NAME = 'natgeo'
13     _VALID_URL = r'https?://video\.nationalgeographic\.com/.*?'
14
15     _TESTS = [
16         {
17             'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo',
18             'md5': '730855d559abbad6b42c2be1fa584917',
19             'info_dict': {
20                 'id': '0000014b-70a1-dd8c-af7f-f7b559330001',
21                 'ext': 'mp4',
22                 'title': 'Mating Crabs Busted by Sharks',
23                 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3',
24             },
25             'add_ie': ['ThePlatform'],
26         },
27         {
28             'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws',
29             'md5': '6a3105eb448c070503b3105fb9b320b5',
30             'info_dict': {
31                 'id': 'ngc-I0IauNSWznb_UV008GxSbwY35BZvgi2e',
32                 'ext': 'mp4',
33                 'title': 'The Real Jaws',
34                 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6',
35             },
36             'add_ie': ['ThePlatform'],
37         },
38     ]
39
40     def _real_extract(self, url):
41         name = url_basename(url)
42
43         webpage = self._download_webpage(url, name)
44         guid = self._search_regex(
45             r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"',
46             webpage, 'guid')
47
48         return {
49             '_type': 'url_transparent',
50             'ie_key': 'ThePlatform',
51             'url': smuggle_url(
52                 'http://link.theplatform.com/s/ngs/media/guid/2423130747/%s?mbr=true' % guid,
53                 {'force_smil_url': True}),
54             'id': guid,
55         }
56
57
58 class NationalGeographicChannelIE(InfoExtractor):
59     IE_NAME = 'natgeo:channel'
60     _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?[^/]+/videos/(?P<id>[^/?]+)'
61
62     _TESTS = [
63         {
64             'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/videos/uncovering-a-universal-knowledge/',
65             'md5': '518c9aa655686cf81493af5cc21e2a04',
66             'info_dict': {
67                 'id': 'nB5vIAfmyllm',
68                 'ext': 'mp4',
69                 'title': 'Uncovering a Universal Knowledge',
70                 'description': 'md5:1a89148475bf931b3661fcd6ddb2ae3a',
71             },
72             'add_ie': ['ThePlatform'],
73         },
74         {
75             'url': 'http://channel.nationalgeographic.com/wild/destination-wild/videos/the-stunning-red-bird-of-paradise/',
76             'md5': 'c4912f656b4cbe58f3e000c489360989',
77             'info_dict': {
78                 'id': '3TmMv9OvGwIR',
79                 'ext': 'mp4',
80                 'title': 'The Stunning Red Bird of Paradise',
81                 'description': 'md5:7bc8cd1da29686be4d17ad1230f0140c',
82             },
83             'add_ie': ['ThePlatform'],
84         },
85     ]
86
87     def _real_extract(self, url):
88         display_id = self._match_id(url)
89         webpage = self._download_webpage(url, display_id)
90         release_url = self._search_regex(
91             r'video_auth_playlist_url\s*=\s*"([^"]+)"',
92             webpage, 'release url')
93
94         return {
95             '_type': 'url_transparent',
96             'ie_key': 'ThePlatform',
97             'url': smuggle_url(
98                 update_url_query(release_url, {'mbr': 'true', 'switch': 'http'}),
99                 {'force_smil_url': True}),
100             'display_id': display_id,
101         }