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