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