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