]>
Commit | Line | Data |
---|---|---|
6140baf4 JMF |
1 | from __future__ import unicode_literals |
2 | ||
1891ea2d RA |
3 | import re |
4 | ||
6140baf4 | 5 | from .common import InfoExtractor |
818ac213 | 6 | from .adobepass import AdobePassIE |
6140baf4 JMF |
7 | from ..utils import ( |
8 | smuggle_url, | |
9 | url_basename, | |
c9c39c22 | 10 | update_url_query, |
1891ea2d | 11 | get_element_by_class, |
6140baf4 JMF |
12 | ) |
13 | ||
14 | ||
1891ea2d RA |
15 | class NationalGeographicVideoIE(InfoExtractor): |
16 | IE_NAME = 'natgeo:video' | |
5886b38d | 17 | _VALID_URL = r'https?://video\.nationalgeographic\.com/.*?' |
53b8247c | 18 | |
19 | _TESTS = [ | |
20 | { | |
21 | 'url': 'http://video.nationalgeographic.com/video/news/150210-news-crab-mating-vin?source=featuredvideo', | |
d84b48e3 | 22 | 'md5': '730855d559abbad6b42c2be1fa584917', |
53b8247c | 23 | 'info_dict': { |
d84b48e3 | 24 | 'id': '0000014b-70a1-dd8c-af7f-f7b559330001', |
25 | 'ext': 'mp4', | |
53b8247c | 26 | 'title': 'Mating Crabs Busted by Sharks', |
27 | 'description': 'md5:16f25aeffdeba55aaa8ec37e093ad8b3', | |
79ba9140 | 28 | 'timestamp': 1423523799, |
29 | 'upload_date': '20150209', | |
30 | 'uploader': 'NAGS', | |
53b8247c | 31 | }, |
32 | 'add_ie': ['ThePlatform'], | |
6140baf4 | 33 | }, |
53b8247c | 34 | { |
35 | 'url': 'http://video.nationalgeographic.com/wild/when-sharks-attack/the-real-jaws', | |
d84b48e3 | 36 | 'md5': '6a3105eb448c070503b3105fb9b320b5', |
53b8247c | 37 | 'info_dict': { |
d84b48e3 | 38 | 'id': 'ngc-I0IauNSWznb_UV008GxSbwY35BZvgi2e', |
39 | 'ext': 'mp4', | |
53b8247c | 40 | 'title': 'The Real Jaws', |
41 | 'description': 'md5:8d3e09d9d53a85cd397b4b21b2c77be6', | |
79ba9140 | 42 | 'timestamp': 1433772632, |
43 | 'upload_date': '20150608', | |
44 | 'uploader': 'NAGS', | |
53b8247c | 45 | }, |
46 | 'add_ie': ['ThePlatform'], | |
47 | }, | |
48 | ] | |
6140baf4 JMF |
49 | |
50 | def _real_extract(self, url): | |
51 | name = url_basename(url) | |
52 | ||
53 | webpage = self._download_webpage(url, name) | |
f29ac588 S |
54 | guid = self._search_regex( |
55 | r'id="(?:videoPlayer|player-container)"[^>]+data-guid="([^"]+)"', | |
56 | webpage, 'guid') | |
6140baf4 | 57 | |
d84b48e3 | 58 | return { |
59 | '_type': 'url_transparent', | |
60 | 'ie_key': 'ThePlatform', | |
61 | 'url': smuggle_url( | |
62 | 'http://link.theplatform.com/s/ngs/media/guid/2423130747/%s?mbr=true' % guid, | |
63 | {'force_smil_url': True}), | |
64 | 'id': guid, | |
65 | } | |
c9c39c22 | 66 | |
67 | ||
818ac213 | 68 | class NationalGeographicIE(AdobePassIE): |
1891ea2d RA |
69 | IE_NAME = 'natgeo' |
70 | _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?[^/]+/(?:videos|episodes)/(?P<id>[^/?]+)' | |
c9c39c22 | 71 | |
72 | _TESTS = [ | |
73 | { | |
74 | 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/videos/uncovering-a-universal-knowledge/', | |
75 | 'md5': '518c9aa655686cf81493af5cc21e2a04', | |
76 | 'info_dict': { | |
5a993e16 | 77 | 'id': 'vKInpacll2pC', |
c9c39c22 | 78 | 'ext': 'mp4', |
79 | 'title': 'Uncovering a Universal Knowledge', | |
80 | 'description': 'md5:1a89148475bf931b3661fcd6ddb2ae3a', | |
79ba9140 | 81 | 'timestamp': 1458680907, |
82 | 'upload_date': '20160322', | |
83 | 'uploader': 'NEWA-FNG-NGTV', | |
c9c39c22 | 84 | }, |
85 | 'add_ie': ['ThePlatform'], | |
86 | }, | |
87 | { | |
88 | 'url': 'http://channel.nationalgeographic.com/wild/destination-wild/videos/the-stunning-red-bird-of-paradise/', | |
89 | 'md5': 'c4912f656b4cbe58f3e000c489360989', | |
90 | 'info_dict': { | |
5a993e16 | 91 | 'id': 'Pok5lWCkiEFA', |
c9c39c22 | 92 | 'ext': 'mp4', |
93 | 'title': 'The Stunning Red Bird of Paradise', | |
94 | 'description': 'md5:7bc8cd1da29686be4d17ad1230f0140c', | |
79ba9140 | 95 | 'timestamp': 1459362152, |
96 | 'upload_date': '20160330', | |
97 | 'uploader': 'NEWA-FNG-NGTV', | |
c9c39c22 | 98 | }, |
99 | 'add_ie': ['ThePlatform'], | |
100 | }, | |
1891ea2d RA |
101 | { |
102 | 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/episodes/the-power-of-miracles/', | |
103 | 'only_matching': True, | |
104 | } | |
c9c39c22 | 105 | ] |
106 | ||
107 | def _real_extract(self, url): | |
108 | display_id = self._match_id(url) | |
109 | webpage = self._download_webpage(url, display_id) | |
110 | release_url = self._search_regex( | |
111 | r'video_auth_playlist_url\s*=\s*"([^"]+)"', | |
112 | webpage, 'release url') | |
a1f6f5c7 RA |
113 | query = { |
114 | 'mbr': 'true', | |
a5f67895 | 115 | 'switch': 'http', |
a1f6f5c7 RA |
116 | } |
117 | is_auth = self._search_regex(r'video_is_auth\s*=\s*"([^"]+)"', webpage, 'is auth', fatal=False) | |
118 | if is_auth == 'auth': | |
119 | auth_resource_id = self._search_regex( | |
120 | r"video_auth_resourceId\s*=\s*'([^']+)'", | |
121 | webpage, 'auth resource id') | |
1fd6e309 | 122 | query['auth'] = self._extract_mvpd_auth(url, display_id, 'natgeo', auth_resource_id) |
c9c39c22 | 123 | |
124 | return { | |
125 | '_type': 'url_transparent', | |
126 | 'ie_key': 'ThePlatform', | |
127 | 'url': smuggle_url( | |
a1f6f5c7 | 128 | update_url_query(release_url, query), |
c9c39c22 | 129 | {'force_smil_url': True}), |
130 | 'display_id': display_id, | |
131 | } | |
1891ea2d RA |
132 | |
133 | ||
818ac213 | 134 | class NationalGeographicEpisodeGuideIE(InfoExtractor): |
1891ea2d RA |
135 | IE_NAME = 'natgeo:episodeguide' |
136 | _VALID_URL = r'https?://channel\.nationalgeographic\.com/(?:wild/)?(?P<id>[^/]+)/episode-guide' | |
137 | _TESTS = [ | |
138 | { | |
139 | 'url': 'http://channel.nationalgeographic.com/the-story-of-god-with-morgan-freeman/episode-guide/', | |
140 | 'info_dict': { | |
141 | 'id': 'the-story-of-god-with-morgan-freeman-season-1', | |
142 | 'title': 'The Story of God with Morgan Freeman - Season 1', | |
143 | }, | |
144 | 'playlist_mincount': 6, | |
145 | }, | |
146 | { | |
147 | 'url': 'http://channel.nationalgeographic.com/underworld-inc/episode-guide/?s=2', | |
148 | 'info_dict': { | |
149 | 'id': 'underworld-inc-season-2', | |
150 | 'title': 'Underworld, Inc. - Season 2', | |
151 | }, | |
152 | 'playlist_mincount': 7, | |
153 | }, | |
154 | ] | |
155 | ||
156 | def _real_extract(self, url): | |
157 | display_id = self._match_id(url) | |
158 | webpage = self._download_webpage(url, display_id) | |
159 | show = get_element_by_class('show', webpage) | |
160 | selected_season = self._search_regex( | |
161 | r'<div[^>]+class="select-seasons[^"]*".*?<a[^>]*>(.*?)</a>', | |
162 | webpage, 'selected season') | |
163 | entries = [ | |
8a00ea56 S |
164 | self.url_result(self._proto_relative_url(entry_url), 'NationalGeographic') |
165 | for entry_url in re.findall('(?s)<div[^>]+class="col-inner"[^>]*?>.*?<a[^>]+href="([^"]+)"', webpage)] | |
1891ea2d RA |
166 | return self.playlist_result( |
167 | entries, '%s-%s' % (display_id, selected_season.lower().replace(' ', '-')), | |
168 | '%s - %s' % (show, selected_season)) |