1 from __future__ import unicode_literals
5 from .common import InfoExtractor
15 class PBSIE(InfoExtractor):
16 _VALID_URL = r'''(?x)https?://
19 video\.pbs\.org/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
20 # Article with embedded player (or direct video)
21 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
23 video\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
29 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
30 'md5': 'ce1888486f0908d555a8093cac9a7362',
34 'title': 'A More Perfect Union',
35 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
39 'skip_download': True, # requires ffmpeg
43 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
44 'md5': '143c98aa54a346738a3d78f54c925321',
48 'title': 'Losing Iraq',
49 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
53 'skip_download': True, # requires ffmpeg
57 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
58 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
62 'title': 'Cyber Schools Gain Popularity, but Quality Questions Persist',
63 'description': 'md5:5871c15cba347c1b3d28ac47a73c7c28',
68 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
69 'md5': 'c62859342be2a0358d6c9eb306595978',
73 'description': 'md5:68d87ef760660eb564455eb30ca464fe',
74 'title': 'Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
76 'thumbnail': 're:^https?://.*\.jpg$',
79 'skip_download': True, # requires ffmpeg
83 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
84 'md5': '908f3e5473a693b266b84e25e1cf9703',
87 'display_id': 'killer-typhoon',
89 'description': 'md5:c741d14e979fc53228c575894094f157',
90 'title': 'Killer Typhoon',
92 'thumbnail': 're:^https?://.*\.jpg$',
93 'upload_date': '20140122',
96 'skip_download': True, # requires ffmpeg
100 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
102 'id': 'united-states-of-secrets',
107 'url': 'http://www.pbs.org/wgbh/americanexperience/films/death/player/',
110 'display_id': 'player',
112 'title': 'Death and the Civil War',
113 'description': 'American Experience, TV’s most-watched history series, brings to life the compelling stories from our past that inform our understanding of the world today.',
115 'thumbnail': 're:^https?://.*\.jpg$',
118 'skip_download': True, # requires ffmpeg
123 def _extract_webpage(self, url):
124 mobj = re.match(self._VALID_URL, url)
126 presumptive_id = mobj.group('presumptive_id')
127 display_id = presumptive_id
129 webpage = self._download_webpage(url, display_id)
131 upload_date = unified_strdate(self._search_regex(
132 r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
133 webpage, 'upload date', default=None))
135 # tabbed frontline videos
136 tabbed_videos = re.findall(
137 r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"', webpage)
139 return tabbed_videos, presumptive_id, upload_date
142 r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
143 r'class="coveplayerid">([^<]+)<', # coveplayer
144 r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
147 media_id = self._search_regex(
148 MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
150 return media_id, presumptive_id, upload_date
152 url = self._search_regex(
153 r'<iframe\s+[^>]*\s+src=["\']([^\'"]+partnerplayer[^\'"]+)["\']',
154 webpage, 'player URL')
155 mobj = re.match(self._VALID_URL, url)
157 player_id = mobj.group('player_id')
159 display_id = player_id
161 player_page = self._download_webpage(
162 url, display_id, note='Downloading player page',
163 errnote='Could not download player page')
164 video_id = self._search_regex(
165 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
167 video_id = mobj.group('id')
168 display_id = video_id
170 return video_id, display_id, None
172 def _real_extract(self, url):
173 video_id, display_id, upload_date = self._extract_webpage(url)
175 if isinstance(video_id, list):
176 entries = [self.url_result(
177 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
178 for vid_id in video_id]
179 return self.playlist_result(entries, display_id)
181 info = self._download_json(
182 'http://video.pbs.org/videoInfo/%s?format=json&type=partner' % video_id,
186 for encoding_name in ('recommended_encoding', 'alternate_encoding'):
187 redirect = info.get(encoding_name)
190 redirect_url = redirect.get('url')
194 redirect_info = self._download_json(
195 redirect_url + '?format=json', display_id,
196 'Downloading %s video url info' % encoding_name)
198 if redirect_info['status'] == 'error':
199 if redirect_info['http_code'] == 403:
201 'The video is not available in your region due to '
202 'right restrictions')
204 message = redirect_info['message']
205 raise ExtractorError(message, expected=True)
207 format_url = redirect_info.get('url')
211 if determine_ext(format_url) == 'm3u8':
212 formats.extend(self._extract_m3u8_formats(
213 format_url, display_id, 'mp4', preference=1, m3u8_id='hls'))
217 'format_id': redirect.get('eeid'),
219 self._sort_formats(formats)
221 rating_str = info.get('rating')
222 if rating_str is not None:
223 rating_str = rating_str.rpartition('-')[2]
224 age_limit = US_RATINGS.get(rating_str)
228 'display_id': display_id,
229 'title': info['title'],
230 'description': info['program'].get('description'),
231 'thumbnail': info.get('image_url'),
232 'duration': int_or_none(info.get('duration')),
233 'age_limit': age_limit,
234 'upload_date': upload_date,