]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/pbs.py
Initiate new release.
[youtubedl] / youtube_dl / extractor / pbs.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_HTTPError
8 from ..utils import (
9 ExtractorError,
10 determine_ext,
11 int_or_none,
12 js_to_json,
13 strip_jsonp,
14 unified_strdate,
15 US_RATINGS,
16 )
17
18
19 class PBSIE(InfoExtractor):
20 _STATIONS = (
21 (r'(?:video|www|player)\.pbs\.org', 'PBS: Public Broadcasting Service'), # http://www.pbs.org/
22 (r'video\.aptv\.org', 'APT - Alabama Public Television (WBIQ)'), # http://aptv.org/
23 (r'video\.gpb\.org', 'GPB/Georgia Public Broadcasting (WGTV)'), # http://www.gpb.org/
24 (r'video\.mpbonline\.org', 'Mississippi Public Broadcasting (WMPN)'), # http://www.mpbonline.org
25 (r'video\.wnpt\.org', 'Nashville Public Television (WNPT)'), # http://www.wnpt.org
26 (r'video\.wfsu\.org', 'WFSU-TV (WFSU)'), # http://wfsu.org/
27 (r'video\.wsre\.org', 'WSRE (WSRE)'), # http://www.wsre.org
28 (r'video\.wtcitv\.org', 'WTCI (WTCI)'), # http://www.wtcitv.org
29 (r'video\.pba\.org', 'WPBA/Channel 30 (WPBA)'), # http://pba.org/
30 (r'video\.alaskapublic\.org', 'Alaska Public Media (KAKM)'), # http://alaskapublic.org/kakm
31 # (r'kuac\.org', 'KUAC (KUAC)'), # http://kuac.org/kuac-tv/
32 # (r'ktoo\.org', '360 North (KTOO)'), # http://www.ktoo.org/
33 # (r'azpm\.org', 'KUAT 6 (KUAT)'), # http://www.azpm.org/
34 (r'video\.azpbs\.org', 'Arizona PBS (KAET)'), # http://www.azpbs.org
35 (r'portal\.knme\.org', 'KNME-TV/Channel 5 (KNME)'), # http://www.newmexicopbs.org/
36 (r'video\.vegaspbs\.org', 'Vegas PBS (KLVX)'), # http://vegaspbs.org/
37 (r'watch\.aetn\.org', 'AETN/ARKANSAS ETV NETWORK (KETS)'), # http://www.aetn.org/
38 (r'video\.ket\.org', 'KET (WKLE)'), # http://www.ket.org/
39 (r'video\.wkno\.org', 'WKNO/Channel 10 (WKNO)'), # http://www.wkno.org/
40 (r'video\.lpb\.org', 'LPB/LOUISIANA PUBLIC BROADCASTING (WLPB)'), # http://www.lpb.org/
41 (r'videos\.oeta\.tv', 'OETA (KETA)'), # http://www.oeta.tv
42 (r'video\.optv\.org', 'Ozarks Public Television (KOZK)'), # http://www.optv.org/
43 (r'watch\.wsiu\.org', 'WSIU Public Broadcasting (WSIU)'), # http://www.wsiu.org/
44 (r'video\.keet\.org', 'KEET TV (KEET)'), # http://www.keet.org
45 (r'pbs\.kixe\.org', 'KIXE/Channel 9 (KIXE)'), # http://kixe.org/
46 (r'video\.kpbs\.org', 'KPBS San Diego (KPBS)'), # http://www.kpbs.org/
47 (r'video\.kqed\.org', 'KQED (KQED)'), # http://www.kqed.org
48 (r'vids\.kvie\.org', 'KVIE Public Television (KVIE)'), # http://www.kvie.org
49 (r'video\.pbssocal\.org', 'PBS SoCal/KOCE (KOCE)'), # http://www.pbssocal.org/
50 (r'video\.valleypbs\.org', 'ValleyPBS (KVPT)'), # http://www.valleypbs.org/
51 (r'video\.cptv\.org', 'CONNECTICUT PUBLIC TELEVISION (WEDH)'), # http://cptv.org
52 (r'watch\.knpb\.org', 'KNPB Channel 5 (KNPB)'), # http://www.knpb.org/
53 (r'video\.soptv\.org', 'SOPTV (KSYS)'), # http://www.soptv.org
54 # (r'klcs\.org', 'KLCS/Channel 58 (KLCS)'), # http://www.klcs.org
55 # (r'krcb\.org', 'KRCB Television & Radio (KRCB)'), # http://www.krcb.org
56 # (r'kvcr\.org', 'KVCR TV/DT/FM :: Vision for the Future (KVCR)'), # http://kvcr.org
57 (r'video\.rmpbs\.org', 'Rocky Mountain PBS (KRMA)'), # http://www.rmpbs.org
58 (r'video\.kenw\.org', 'KENW-TV3 (KENW)'), # http://www.kenw.org
59 (r'video\.kued\.org', 'KUED Channel 7 (KUED)'), # http://www.kued.org
60 (r'video\.wyomingpbs\.org', 'Wyoming PBS (KCWC)'), # http://www.wyomingpbs.org
61 (r'video\.cpt12\.org', 'Colorado Public Television / KBDI 12 (KBDI)'), # http://www.cpt12.org/
62 (r'video\.kbyueleven\.org', 'KBYU-TV (KBYU)'), # http://www.kbyutv.org/
63 (r'video\.thirteen\.org', 'Thirteen/WNET New York (WNET)'), # http://www.thirteen.org
64 (r'video\.wgbh\.org', 'WGBH/Channel 2 (WGBH)'), # http://wgbh.org
65 (r'video\.wgby\.org', 'WGBY (WGBY)'), # http://www.wgby.org
66 (r'watch\.njtvonline\.org', 'NJTV Public Media NJ (WNJT)'), # http://www.njtvonline.org/
67 # (r'ripbs\.org', 'Rhode Island PBS (WSBE)'), # http://www.ripbs.org/home/
68 (r'watch\.wliw\.org', 'WLIW21 (WLIW)'), # http://www.wliw.org/
69 (r'video\.mpt\.tv', 'mpt/Maryland Public Television (WMPB)'), # http://www.mpt.org
70 (r'watch\.weta\.org', 'WETA Television and Radio (WETA)'), # http://www.weta.org
71 (r'video\.whyy\.org', 'WHYY (WHYY)'), # http://www.whyy.org
72 (r'video\.wlvt\.org', 'PBS 39 (WLVT)'), # http://www.wlvt.org/
73 (r'video\.wvpt\.net', 'WVPT - Your Source for PBS and More! (WVPT)'), # http://www.wvpt.net
74 (r'video\.whut\.org', 'Howard University Television (WHUT)'), # http://www.whut.org
75 (r'video\.wedu\.org', 'WEDU PBS (WEDU)'), # http://www.wedu.org
76 (r'video\.wgcu\.org', 'WGCU Public Media (WGCU)'), # http://www.wgcu.org/
77 # (r'wjct\.org', 'WJCT Public Broadcasting (WJCT)'), # http://www.wjct.org
78 (r'video\.wpbt2\.org', 'WPBT2 (WPBT)'), # http://www.wpbt2.org
79 (r'video\.wucftv\.org', 'WUCF TV (WUCF)'), # http://wucftv.org
80 (r'video\.wuft\.org', 'WUFT/Channel 5 (WUFT)'), # http://www.wuft.org
81 (r'watch\.wxel\.org', 'WXEL/Channel 42 (WXEL)'), # http://www.wxel.org/home/
82 (r'video\.wlrn\.org', 'WLRN/Channel 17 (WLRN)'), # http://www.wlrn.org/
83 (r'video\.wusf\.usf\.edu', 'WUSF Public Broadcasting (WUSF)'), # http://wusf.org/
84 (r'video\.scetv\.org', 'ETV (WRLK)'), # http://www.scetv.org
85 (r'video\.unctv\.org', 'UNC-TV (WUNC)'), # http://www.unctv.org/
86 # (r'pbsguam\.org', 'PBS Guam (KGTF)'), # http://www.pbsguam.org/
87 (r'video\.pbshawaii\.org', 'PBS Hawaii - Oceanic Cable Channel 10 (KHET)'), # http://www.pbshawaii.org/
88 (r'video\.idahoptv\.org', 'Idaho Public Television (KAID)'), # http://idahoptv.org
89 (r'video\.ksps\.org', 'KSPS (KSPS)'), # http://www.ksps.org/home/
90 (r'watch\.opb\.org', 'OPB (KOPB)'), # http://www.opb.org
91 (r'watch\.nwptv\.org', 'KWSU/Channel 10 & KTNW/Channel 31 (KWSU)'), # http://www.kwsu.org
92 (r'video\.will\.illinois\.edu', 'WILL-TV (WILL)'), # http://will.illinois.edu/
93 (r'video\.networkknowledge\.tv', 'Network Knowledge - WSEC/Springfield (WSEC)'), # http://www.wsec.tv
94 (r'video\.wttw\.com', 'WTTW11 (WTTW)'), # http://www.wttw.com/
95 # (r'wtvp\.org', 'WTVP & WTVP.org, Public Media for Central Illinois (WTVP)'), # http://www.wtvp.org/
96 (r'video\.iptv\.org', 'Iowa Public Television/IPTV (KDIN)'), # http://www.iptv.org/
97 (r'video\.ninenet\.org', 'Nine Network (KETC)'), # http://www.ninenet.org
98 (r'video\.wfwa\.org', 'PBS39 Fort Wayne (WFWA)'), # http://wfwa.org/
99 (r'video\.wfyi\.org', 'WFYI Indianapolis (WFYI)'), # http://www.wfyi.org
100 (r'video\.mptv\.org', 'Milwaukee Public Television (WMVS)'), # http://www.mptv.org
101 (r'video\.wnin\.org', 'WNIN (WNIN)'), # http://www.wnin.org/
102 (r'video\.wnit\.org', 'WNIT Public Television (WNIT)'), # http://www.wnit.org/
103 (r'video\.wpt\.org', 'WPT (WPNE)'), # http://www.wpt.org/
104 (r'video\.wvut\.org', 'WVUT/Channel 22 (WVUT)'), # http://wvut.org/
105 (r'video\.weiu\.net', 'WEIU/Channel 51 (WEIU)'), # http://www.weiu.net
106 (r'video\.wqpt\.org', 'WQPT-TV (WQPT)'), # http://www.wqpt.org
107 (r'video\.wycc\.org', 'WYCC PBS Chicago (WYCC)'), # http://www.wycc.org
108 # (r'lakeshorepublicmedia\.org', 'Lakeshore Public Television (WYIN)'), # http://lakeshorepublicmedia.org/
109 (r'video\.wipb\.org', 'WIPB-TV (WIPB)'), # http://wipb.org
110 (r'video\.indianapublicmedia\.org', 'WTIU (WTIU)'), # http://indianapublicmedia.org/tv/
111 (r'watch\.cetconnect\.org', 'CET (WCET)'), # http://www.cetconnect.org
112 (r'video\.thinktv\.org', 'ThinkTVNetwork (WPTD)'), # http://www.thinktv.org
113 (r'video\.wbgu\.org', 'WBGU-TV (WBGU)'), # http://wbgu.org
114 (r'video\.wgvu\.org', 'WGVU TV (WGVU)'), # http://www.wgvu.org/
115 (r'video\.netnebraska\.org', 'NET1 (KUON)'), # http://netnebraska.org
116 (r'video\.pioneer\.org', 'Pioneer Public Television (KWCM)'), # http://www.pioneer.org
117 (r'watch\.sdpb\.org', 'SDPB Television (KUSD)'), # http://www.sdpb.org
118 (r'video\.tpt\.org', 'TPT (KTCA)'), # http://www.tpt.org
119 (r'watch\.ksmq\.org', 'KSMQ (KSMQ)'), # http://www.ksmq.org/
120 (r'watch\.kpts\.org', 'KPTS/Channel 8 (KPTS)'), # http://www.kpts.org/
121 (r'watch\.ktwu\.org', 'KTWU/Channel 11 (KTWU)'), # http://ktwu.org
122 # (r'shptv\.org', 'Smoky Hills Public Television (KOOD)'), # http://www.shptv.org
123 # (r'kcpt\.org', 'KCPT Kansas City Public Television (KCPT)'), # http://kcpt.org/
124 # (r'blueridgepbs\.org', 'Blue Ridge PBS (WBRA)'), # http://www.blueridgepbs.org/
125 (r'watch\.easttennesseepbs\.org', 'East Tennessee PBS (WSJK)'), # http://easttennesseepbs.org
126 (r'video\.wcte\.tv', 'WCTE-TV (WCTE)'), # http://www.wcte.org
127 (r'video\.wljt\.org', 'WLJT, Channel 11 (WLJT)'), # http://wljt.org/
128 (r'video\.wosu\.org', 'WOSU TV (WOSU)'), # http://wosu.org/
129 (r'video\.woub\.org', 'WOUB/WOUC (WOUB)'), # http://woub.org/tv/index.php?section=5
130 (r'video\.wvpublic\.org', 'WVPB (WVPB)'), # http://wvpublic.org/
131 (r'video\.wkyupbs\.org', 'WKYU-PBS (WKYU)'), # http://www.wkyupbs.org
132 # (r'wyes\.org', 'WYES-TV/New Orleans (WYES)'), # http://www.wyes.org
133 (r'video\.kera\.org', 'KERA 13 (KERA)'), # http://www.kera.org/
134 (r'video\.mpbn\.net', 'MPBN (WCBB)'), # http://www.mpbn.net/
135 (r'video\.mountainlake\.org', 'Mountain Lake PBS (WCFE)'), # http://www.mountainlake.org/
136 (r'video\.nhptv\.org', 'NHPTV (WENH)'), # http://nhptv.org/
137 (r'video\.vpt\.org', 'Vermont PBS (WETK)'), # http://www.vpt.org
138 (r'video\.witf\.org', 'witf (WITF)'), # http://www.witf.org
139 (r'watch\.wqed\.org', 'WQED Multimedia (WQED)'), # http://www.wqed.org/
140 (r'video\.wmht\.org', 'WMHT Educational Telecommunications (WMHT)'), # http://www.wmht.org/home/
141 (r'video\.deltabroadcasting\.org', 'Q-TV (WDCQ)'), # http://www.deltabroadcasting.org
142 (r'video\.dptv\.org', 'WTVS Detroit Public TV (WTVS)'), # http://www.dptv.org/
143 (r'video\.wcmu\.org', 'CMU Public Television (WCMU)'), # http://www.wcmu.org
144 (r'video\.wkar\.org', 'WKAR-TV (WKAR)'), # http://wkar.org/
145 (r'wnmuvideo\.nmu\.edu', 'WNMU-TV Public TV 13 (WNMU)'), # http://wnmutv.nmu.edu
146 (r'video\.wdse\.org', 'WDSE - WRPT (WDSE)'), # http://www.wdse.org/
147 (r'video\.wgte\.org', 'WGTE TV (WGTE)'), # http://www.wgte.org
148 (r'video\.lptv\.org', 'Lakeland Public Television (KAWE)'), # http://www.lakelandptv.org
149 # (r'prairiepublic\.org', 'PRAIRIE PUBLIC (KFME)'), # http://www.prairiepublic.org/
150 (r'video\.kmos\.org', 'KMOS-TV - Channels 6.1, 6.2 and 6.3 (KMOS)'), # http://www.kmos.org/
151 (r'watch\.montanapbs\.org', 'MontanaPBS (KUSM)'), # http://montanapbs.org
152 (r'video\.krwg\.org', 'KRWG/Channel 22 (KRWG)'), # http://www.krwg.org
153 (r'video\.kacvtv\.org', 'KACV (KACV)'), # http://www.panhandlepbs.org/home/
154 (r'video\.kcostv\.org', 'KCOS/Channel 13 (KCOS)'), # www.kcostv.org
155 (r'video\.wcny\.org', 'WCNY/Channel 24 (WCNY)'), # http://www.wcny.org
156 (r'video\.wned\.org', 'WNED (WNED)'), # http://www.wned.org/
157 (r'watch\.wpbstv\.org', 'WPBS (WPBS)'), # http://www.wpbstv.org
158 (r'video\.wskg\.org', 'WSKG Public TV (WSKG)'), # http://wskg.org
159 (r'video\.wxxi\.org', 'WXXI (WXXI)'), # http://wxxi.org
160 (r'video\.wpsu\.org', 'WPSU (WPSU)'), # http://www.wpsu.org
161 # (r'wqln\.org', 'WQLN/Channel 54 (WQLN)'), # http://www.wqln.org
162 (r'on-demand\.wvia\.org', 'WVIA Public Media Studios (WVIA)'), # http://www.wvia.org/
163 (r'video\.wtvi\.org', 'WTVI (WTVI)'), # http://www.wtvi.org/
164 # (r'whro\.org', 'WHRO (WHRO)'), # http://whro.org
165 (r'video\.westernreservepublicmedia\.org', 'Western Reserve PBS (WNEO)'), # http://www.WesternReservePublicMedia.org/
166 (r'video\.ideastream\.org', 'WVIZ/PBS ideastream (WVIZ)'), # http://www.wviz.org/
167 (r'video\.kcts9\.org', 'KCTS 9 (KCTS)'), # http://kcts9.org/
168 (r'video\.basinpbs\.org', 'Basin PBS (KPBT)'), # http://www.basinpbs.org
169 (r'video\.houstonpbs\.org', 'KUHT / Channel 8 (KUHT)'), # http://www.houstonpublicmedia.org/
170 # (r'tamu\.edu', 'KAMU - TV (KAMU)'), # http://KAMU.tamu.edu
171 # (r'kedt\.org', 'KEDT/Channel 16 (KEDT)'), # http://www.kedt.org
172 (r'video\.klrn\.org', 'KLRN (KLRN)'), # http://www.klrn.org
173 (r'video\.klru\.tv', 'KLRU (KLRU)'), # http://www.klru.org
174 # (r'kmbh\.org', 'KMBH-TV (KMBH)'), # http://www.kmbh.org
175 # (r'knct\.org', 'KNCT (KNCT)'), # http://www.knct.org
176 # (r'ktxt\.org', 'KTTZ-TV (KTXT)'), # http://www.ktxt.org
177 (r'video\.wtjx\.org', 'WTJX Channel 12 (WTJX)'), # http://www.wtjx.org/
178 (r'video\.ideastations\.org', 'WCVE PBS (WCVE)'), # http://ideastations.org/
179 (r'video\.kbtc\.org', 'KBTC Public Television (KBTC)'), # http://kbtc.org
180 )
181
182 IE_NAME = 'pbs'
183 IE_DESC = 'Public Broadcasting Service (PBS) and member stations: %s' % ', '.join(list(zip(*_STATIONS))[1])
184
185 _VALID_URL = r'''(?x)https?://
186 (?:
187 # Direct video URL
188 (?:%s)/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
189 # Article with embedded player (or direct video)
190 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
191 # Player
192 (?:video|player)\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
193 )
194 ''' % '|'.join(list(zip(*_STATIONS))[0])
195
196 _TESTS = [
197 {
198 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
199 'md5': '173dc391afd361fa72eab5d3d918968d',
200 'info_dict': {
201 'id': '2365006249',
202 'ext': 'mp4',
203 'title': 'Constitution USA with Peter Sagal - A More Perfect Union',
204 'description': 'md5:36f341ae62e251b8f5bd2b754b95a071',
205 'duration': 3190,
206 },
207 },
208 {
209 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
210 'md5': '6f722cb3c3982186d34b0f13374499c7',
211 'info_dict': {
212 'id': '2365297690',
213 'ext': 'mp4',
214 'title': 'FRONTLINE - Losing Iraq',
215 'description': 'md5:4d3eaa01f94e61b3e73704735f1196d9',
216 'duration': 5050,
217 },
218 },
219 {
220 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
221 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
222 'info_dict': {
223 'id': '2201174722',
224 'ext': 'mp4',
225 'title': 'PBS NewsHour - Cyber Schools Gain Popularity, but Quality Questions Persist',
226 'description': 'md5:95a19f568689d09a166dff9edada3301',
227 'duration': 801,
228 },
229 },
230 {
231 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
232 'md5': 'c62859342be2a0358d6c9eb306595978',
233 'info_dict': {
234 'id': '2365297708',
235 'ext': 'mp4',
236 'title': 'Great Performances - Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
237 'description': 'md5:657897370e09e2bc6bf0f8d2cd313c6b',
238 'duration': 6559,
239 'thumbnail': 're:^https?://.*\.jpg$',
240 },
241 },
242 {
243 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
244 'md5': '908f3e5473a693b266b84e25e1cf9703',
245 'info_dict': {
246 'id': '2365160389',
247 'display_id': 'killer-typhoon',
248 'ext': 'mp4',
249 'description': 'md5:c741d14e979fc53228c575894094f157',
250 'title': 'NOVA - Killer Typhoon',
251 'duration': 3172,
252 'thumbnail': 're:^https?://.*\.jpg$',
253 'upload_date': '20140122',
254 'age_limit': 10,
255 },
256 },
257 {
258 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
259 'info_dict': {
260 'id': 'united-states-of-secrets',
261 },
262 'playlist_count': 2,
263 },
264 {
265 'url': 'http://www.pbs.org/wgbh/americanexperience/films/death/player/',
266 'info_dict': {
267 'id': '2276541483',
268 'display_id': 'player',
269 'ext': 'mp4',
270 'title': 'American Experience - Death and the Civil War, Chapter 1',
271 'description': 'md5:1b80a74e0380ed2a4fb335026de1600d',
272 'duration': 682,
273 'thumbnail': 're:^https?://.*\.jpg$',
274 },
275 'params': {
276 'skip_download': True, # requires ffmpeg
277 },
278 },
279 {
280 'url': 'http://www.pbs.org/video/2365245528/',
281 'md5': '115223d41bd55cda8ae5cd5ed4e11497',
282 'info_dict': {
283 'id': '2365245528',
284 'display_id': '2365245528',
285 'ext': 'mp4',
286 'title': 'FRONTLINE - United States of Secrets (Part One)',
287 'description': 'md5:55756bd5c551519cc4b7703e373e217e',
288 'duration': 6851,
289 'thumbnail': 're:^https?://.*\.jpg$',
290 },
291 },
292 {
293 # Video embedded in iframe containing angle brackets as attribute's value (e.g.
294 # "<iframe style='position: absolute;<br />\ntop: 0; left: 0;' ...", see
295 # https://github.com/rg3/youtube-dl/issues/7059)
296 'url': 'http://www.pbs.org/food/features/a-chefs-life-season-3-episode-5-prickly-business/',
297 'md5': '84ced42850d78f1d4650297356e95e6f',
298 'info_dict': {
299 'id': '2365546844',
300 'display_id': 'a-chefs-life-season-3-episode-5-prickly-business',
301 'ext': 'mp4',
302 'title': "A Chef's Life - Season 3, Ep. 5: Prickly Business",
303 'description': 'md5:54033c6baa1f9623607c6e2ed245888b',
304 'duration': 1480,
305 'thumbnail': 're:^https?://.*\.jpg$',
306 },
307 },
308 {
309 # Frontline video embedded via flp2012.js
310 'url': 'http://www.pbs.org/wgbh/pages/frontline/the-atomic-artists',
311 'info_dict': {
312 'id': '2070868960',
313 'display_id': 'the-atomic-artists',
314 'ext': 'mp4',
315 'title': 'FRONTLINE - The Atomic Artists',
316 'description': 'md5:1a2481e86b32b2e12ec1905dd473e2c1',
317 'duration': 723,
318 'thumbnail': 're:^https?://.*\.jpg$',
319 },
320 'params': {
321 'skip_download': True, # requires ffmpeg
322 },
323 },
324 {
325 # Serves hd only via wigget/partnerplayer page
326 'url': 'http://www.pbs.org/video/2365641075/',
327 'md5': 'acfd4c400b48149a44861cb16dd305cf',
328 'info_dict': {
329 'id': '2365641075',
330 'ext': 'mp4',
331 'title': 'FRONTLINE - Netanyahu at War',
332 'duration': 6852,
333 'thumbnail': 're:^https?://.*\.jpg$',
334 'formats': 'mincount:8',
335 },
336 },
337 {
338 'url': 'http://player.pbs.org/widget/partnerplayer/2365297708/?start=0&end=0&chapterbar=false&endscreen=false&topbar=true',
339 'only_matching': True,
340 },
341 {
342 'url': 'http://watch.knpb.org/video/2365616055/',
343 'only_matching': True,
344 }
345 ]
346 _ERRORS = {
347 101: 'We\'re sorry, but this video is not yet available.',
348 403: 'We\'re sorry, but this video is not available in your region due to right restrictions.',
349 404: 'We are experiencing technical difficulties that are preventing us from playing the video at this time. Please check back again soon.',
350 410: 'This video has expired and is no longer available for online streaming.',
351 }
352
353 def _extract_webpage(self, url):
354 mobj = re.match(self._VALID_URL, url)
355
356 presumptive_id = mobj.group('presumptive_id')
357 display_id = presumptive_id
358 if presumptive_id:
359 webpage = self._download_webpage(url, display_id)
360
361 upload_date = unified_strdate(self._search_regex(
362 r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
363 webpage, 'upload date', default=None))
364
365 # tabbed frontline videos
366 MULTI_PART_REGEXES = (
367 r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"',
368 r'<a[^>]+href=["\']#video-\d+["\'][^>]+data-coveid=["\'](\d+)',
369 )
370 for p in MULTI_PART_REGEXES:
371 tabbed_videos = re.findall(p, webpage)
372 if tabbed_videos:
373 return tabbed_videos, presumptive_id, upload_date
374
375 MEDIA_ID_REGEXES = [
376 r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
377 r'class="coveplayerid">([^<]+)<', # coveplayer
378 r'<section[^>]+data-coveid="(\d+)"', # coveplayer from http://www.pbs.org/wgbh/frontline/film/real-csi/
379 r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
380 ]
381
382 media_id = self._search_regex(
383 MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
384 if media_id:
385 return media_id, presumptive_id, upload_date
386
387 # Fronline video embedded via flp
388 video_id = self._search_regex(
389 r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid', default=None)
390 if video_id:
391 # pkg_id calculation is reverse engineered from
392 # http://www.pbs.org/wgbh/pages/frontline/js/flp2012.js
393 prg_id = self._search_regex(
394 r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid')[7:]
395 if 'q' in prg_id:
396 prg_id = prg_id.split('q')[1]
397 prg_id = int(prg_id, 16)
398 getdir = self._download_json(
399 'http://www.pbs.org/wgbh/pages/frontline/.json/getdir/getdir%d.json' % prg_id,
400 presumptive_id, 'Downloading getdir JSON',
401 transform_source=strip_jsonp)
402 return getdir['mid'], presumptive_id, upload_date
403
404 for iframe in re.findall(r'(?s)<iframe(.+?)></iframe>', webpage):
405 url = self._search_regex(
406 r'src=(["\'])(?P<url>.+?partnerplayer.+?)\1', iframe,
407 'player URL', default=None, group='url')
408 if url:
409 break
410
411 mobj = re.match(self._VALID_URL, url)
412
413 player_id = mobj.group('player_id')
414 if not display_id:
415 display_id = player_id
416 if player_id:
417 player_page = self._download_webpage(
418 url, display_id, note='Downloading player page',
419 errnote='Could not download player page')
420 video_id = self._search_regex(
421 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
422 else:
423 video_id = mobj.group('id')
424 display_id = video_id
425
426 return video_id, display_id, None
427
428 def _real_extract(self, url):
429 video_id, display_id, upload_date = self._extract_webpage(url)
430
431 if isinstance(video_id, list):
432 entries = [self.url_result(
433 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
434 for vid_id in video_id]
435 return self.playlist_result(entries, display_id)
436
437 info = None
438 redirects = []
439 redirect_urls = set()
440
441 def extract_redirect_urls(info):
442 for encoding_name in ('recommended_encoding', 'alternate_encoding'):
443 redirect = info.get(encoding_name)
444 if not redirect:
445 continue
446 redirect_url = redirect.get('url')
447 if redirect_url and redirect_url not in redirect_urls:
448 redirects.append(redirect)
449 redirect_urls.add(redirect_url)
450
451 try:
452 video_info = self._download_json(
453 'http://player.pbs.org/videoInfo/%s?format=json&type=partner' % video_id,
454 display_id, 'Downloading video info JSON')
455 extract_redirect_urls(video_info)
456 info = video_info
457 except ExtractorError as e:
458 # videoInfo API may not work for some videos
459 if not isinstance(e.cause, compat_HTTPError) or e.cause.code != 404:
460 raise
461
462 # Player pages may also serve different qualities
463 for page in ('widget/partnerplayer', 'portalplayer'):
464 player = self._download_webpage(
465 'http://player.pbs.org/%s/%s' % (page, video_id),
466 display_id, 'Downloading %s page' % page, fatal=False)
467 if player:
468 video_info = self._parse_json(
469 self._search_regex(
470 r'(?s)PBS\.videoData\s*=\s*({.+?});\n',
471 player, '%s video data' % page, default='{}'),
472 display_id, transform_source=js_to_json, fatal=False)
473 if video_info:
474 extract_redirect_urls(video_info)
475 if not info:
476 info = video_info
477
478 formats = []
479 http_url = None
480 for num, redirect in enumerate(redirects):
481 redirect_id = redirect.get('eeid')
482
483 redirect_info = self._download_json(
484 '%s?format=json' % redirect['url'], display_id,
485 'Downloading %s video url info' % (redirect_id or num))
486
487 if redirect_info['status'] == 'error':
488 raise ExtractorError(
489 '%s said: %s' % (
490 self.IE_NAME,
491 self._ERRORS.get(redirect_info['http_code'], redirect_info['message'])),
492 expected=True)
493
494 format_url = redirect_info.get('url')
495 if not format_url:
496 continue
497
498 if determine_ext(format_url) == 'm3u8':
499 formats.extend(self._extract_m3u8_formats(
500 format_url, display_id, 'mp4', m3u8_id='hls', fatal=False))
501 else:
502 formats.append({
503 'url': format_url,
504 'format_id': redirect_id,
505 })
506 if re.search(r'^https?://.*(?:\d+k|baseline)', format_url):
507 http_url = format_url
508 self._remove_duplicate_formats(formats)
509 m3u8_formats = list(filter(
510 lambda f: f.get('protocol') == 'm3u8' and f.get('vcodec') != 'none' and f.get('resolution') != 'multiple',
511 formats))
512 if http_url:
513 for m3u8_format in m3u8_formats:
514 bitrate = self._search_regex(r'(\d+k)', m3u8_format['url'], 'bitrate', default=None)
515 # extract only the formats that we know that they will be available as http format.
516 # https://projects.pbs.org/confluence/display/coveapi/COVE+Video+Specifications
517 if not bitrate or bitrate not in ('400k', '800k', '1200k', '2500k'):
518 continue
519 f = m3u8_format.copy()
520 f.update({
521 'url': re.sub(r'\d+k|baseline', bitrate, http_url),
522 'format_id': m3u8_format['format_id'].replace('hls', 'http'),
523 'protocol': 'http',
524 })
525 formats.append(f)
526 self._sort_formats(formats)
527
528 rating_str = info.get('rating')
529 if rating_str is not None:
530 rating_str = rating_str.rpartition('-')[2]
531 age_limit = US_RATINGS.get(rating_str)
532
533 subtitles = {}
534 closed_captions_url = info.get('closed_captions_url')
535 if closed_captions_url:
536 subtitles['en'] = [{
537 'ext': 'ttml',
538 'url': closed_captions_url,
539 }]
540 mobj = re.search(r'/(\d+)_Encoded\.dfxp', closed_captions_url)
541 if mobj:
542 ttml_caption_suffix, ttml_caption_id = mobj.group(0, 1)
543 ttml_caption_id = int(ttml_caption_id)
544 subtitles['en'].extend([{
545 'url': closed_captions_url.replace(
546 ttml_caption_suffix, '/%d_Encoded.srt' % (ttml_caption_id + 1)),
547 'ext': 'srt',
548 }, {
549 'url': closed_captions_url.replace(
550 ttml_caption_suffix, '/%d_Encoded.vtt' % (ttml_caption_id + 2)),
551 'ext': 'vtt',
552 }])
553
554 # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
555 # Try turning it to 'program - title' naming scheme if possible
556 alt_title = info.get('program', {}).get('title')
557 if alt_title:
558 info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + '[\s\-:]+', '', info['title'])
559
560 return {
561 'id': video_id,
562 'display_id': display_id,
563 'title': info['title'],
564 'description': info.get('description') or info.get('program', {}).get('description'),
565 'thumbnail': info.get('image_url'),
566 'duration': int_or_none(info.get('duration')),
567 'age_limit': age_limit,
568 'upload_date': upload_date,
569 'formats': formats,
570 'subtitles': subtitles,
571 }