2 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class PBSIE(InfoExtractor):
19 ('video.pbs.org', 'PBS: Public Broadcasting Service'), # http://www.pbs.org/
20 ('video.aptv.org', 'APT - Alabama Public Television (WBIQ)'), # http://aptv.org/
21 ('video.gpb.org', 'GPB/Georgia Public Broadcasting (WGTV)'), # http://www.gpb.org/
22 ('video.mpbonline.org', 'Mississippi Public Broadcasting (WMPN)'), # http://www.mpbonline.org
23 ('video.wnpt.org', 'Nashville Public Television (WNPT)'), # http://www.wnpt.org
24 ('video.wfsu.org', 'WFSU-TV (WFSU)'), # http://wfsu.org/
25 ('video.wsre.org', 'WSRE (WSRE)'), # http://www.wsre.org
26 ('video.wtcitv.org', 'WTCI (WTCI)'), # http://www.wtcitv.org
27 ('video.pba.org', 'WPBA/Channel 30 (WPBA)'), # http://pba.org/
28 ('video.alaskapublic.org', 'Alaska Public Media (KAKM)'), # http://alaskapublic.org/kakm
29 # ('kuac.org', 'KUAC (KUAC)'), # http://kuac.org/kuac-tv/
30 # ('ktoo.org', '360 North (KTOO)'), # http://www.ktoo.org/
31 # ('azpm.org', 'KUAT 6 (KUAT)'), # http://www.azpm.org/
32 ('video.azpbs.org', 'Arizona PBS (KAET)'), # http://www.azpbs.org
33 ('portal.knme.org', 'KNME-TV/Channel 5 (KNME)'), # http://www.newmexicopbs.org/
34 ('video.vegaspbs.org', 'Vegas PBS (KLVX)'), # http://vegaspbs.org/
35 ('watch.aetn.org', 'AETN/ARKANSAS ETV NETWORK (KETS)'), # http://www.aetn.org/
36 ('video.ket.org', 'KET (WKLE)'), # http://www.ket.org/
37 ('video.wkno.org', 'WKNO/Channel 10 (WKNO)'), # http://www.wkno.org/
38 ('video.lpb.org', 'LPB/LOUISIANA PUBLIC BROADCASTING (WLPB)'), # http://www.lpb.org/
39 ('videos.oeta.tv', 'OETA (KETA)'), # http://www.oeta.tv
40 ('video.optv.org', 'Ozarks Public Television (KOZK)'), # http://www.optv.org/
41 ('watch.wsiu.org', 'WSIU Public Broadcasting (WSIU)'), # http://www.wsiu.org/
42 ('video.keet.org', 'KEET TV (KEET)'), # http://www.keet.org
43 ('pbs.kixe.org', 'KIXE/Channel 9 (KIXE)'), # http://kixe.org/
44 ('video.kpbs.org', 'KPBS San Diego (KPBS)'), # http://www.kpbs.org/
45 ('video.kqed.org', 'KQED (KQED)'), # http://www.kqed.org
46 ('vids.kvie.org', 'KVIE Public Television (KVIE)'), # http://www.kvie.org
47 ('video.pbssocal.org', 'PBS SoCal/KOCE (KOCE)'), # http://www.pbssocal.org/
48 ('video.valleypbs.org', 'ValleyPBS (KVPT)'), # http://www.valleypbs.org/
49 ('video.cptv.org', 'CONNECTICUT PUBLIC TELEVISION (WEDH)'), # http://cptv.org
50 ('watch.knpb.org', 'KNPB Channel 5 (KNPB)'), # http://www.knpb.org/
51 ('video.soptv.org', 'SOPTV (KSYS)'), # http://www.soptv.org
52 # ('klcs.org', 'KLCS/Channel 58 (KLCS)'), # http://www.klcs.org
53 # ('krcb.org', 'KRCB Television & Radio (KRCB)'), # http://www.krcb.org
54 # ('kvcr.org', 'KVCR TV/DT/FM :: Vision for the Future (KVCR)'), # http://kvcr.org
55 ('video.rmpbs.org', 'Rocky Mountain PBS (KRMA)'), # http://www.rmpbs.org
56 ('video.kenw.org', 'KENW-TV3 (KENW)'), # http://www.kenw.org
57 ('video.kued.org', 'KUED Channel 7 (KUED)'), # http://www.kued.org
58 ('video.wyomingpbs.org', 'Wyoming PBS (KCWC)'), # http://www.wyomingpbs.org
59 ('video.cpt12.org', 'Colorado Public Television / KBDI 12 (KBDI)'), # http://www.cpt12.org/
60 ('video.kbyueleven.org', 'KBYU-TV (KBYU)'), # http://www.kbyutv.org/
61 ('video.thirteen.org', 'Thirteen/WNET New York (WNET)'), # http://www.thirteen.org
62 ('video.wgbh.org', 'WGBH/Channel 2 (WGBH)'), # http://wgbh.org
63 ('video.wgby.org', 'WGBY (WGBY)'), # http://www.wgby.org
64 ('watch.njtvonline.org', 'NJTV Public Media NJ (WNJT)'), # http://www.njtvonline.org/
65 # ('ripbs.org', 'Rhode Island PBS (WSBE)'), # http://www.ripbs.org/home/
66 ('watch.wliw.org', 'WLIW21 (WLIW)'), # http://www.wliw.org/
67 ('video.mpt.tv', 'mpt/Maryland Public Television (WMPB)'), # http://www.mpt.org
68 ('watch.weta.org', 'WETA Television and Radio (WETA)'), # http://www.weta.org
69 ('video.whyy.org', 'WHYY (WHYY)'), # http://www.whyy.org
70 ('video.wlvt.org', 'PBS 39 (WLVT)'), # http://www.wlvt.org/
71 ('video.wvpt.net', 'WVPT - Your Source for PBS and More! (WVPT)'), # http://www.wvpt.net
72 ('video.whut.org', 'Howard University Television (WHUT)'), # http://www.whut.org
73 ('video.wedu.org', 'WEDU PBS (WEDU)'), # http://www.wedu.org
74 ('video.wgcu.org', 'WGCU Public Media (WGCU)'), # http://www.wgcu.org/
75 # ('wjct.org', 'WJCT Public Broadcasting (WJCT)'), # http://www.wjct.org
76 ('video.wpbt2.org', 'WPBT2 (WPBT)'), # http://www.wpbt2.org
77 ('video.wucftv.org', 'WUCF TV (WUCF)'), # http://wucftv.org
78 ('video.wuft.org', 'WUFT/Channel 5 (WUFT)'), # http://www.wuft.org
79 ('watch.wxel.org', 'WXEL/Channel 42 (WXEL)'), # http://www.wxel.org/home/
80 ('video.wlrn.org', 'WLRN/Channel 17 (WLRN)'), # http://www.wlrn.org/
81 ('video.wusf.usf.edu', 'WUSF Public Broadcasting (WUSF)'), # http://wusf.org/
82 ('video.scetv.org', 'ETV (WRLK)'), # http://www.scetv.org
83 ('video.unctv.org', 'UNC-TV (WUNC)'), # http://www.unctv.org/
84 # ('pbsguam.org', 'PBS Guam (KGTF)'), # http://www.pbsguam.org/
85 ('video.pbshawaii.org', 'PBS Hawaii - Oceanic Cable Channel 10 (KHET)'), # http://www.pbshawaii.org/
86 ('video.idahoptv.org', 'Idaho Public Television (KAID)'), # http://idahoptv.org
87 ('video.ksps.org', 'KSPS (KSPS)'), # http://www.ksps.org/home/
88 ('watch.opb.org', 'OPB (KOPB)'), # http://www.opb.org
89 ('watch.nwptv.org', 'KWSU/Channel 10 & KTNW/Channel 31 (KWSU)'), # http://www.kwsu.org
90 ('video.will.illinois.edu', 'WILL-TV (WILL)'), # http://will.illinois.edu/
91 ('video.networkknowledge.tv', 'Network Knowledge - WSEC/Springfield (WSEC)'), # http://www.wsec.tv
92 ('video.wttw.com', 'WTTW11 (WTTW)'), # http://www.wttw.com/
93 # ('wtvp.org', 'WTVP & WTVP.org, Public Media for Central Illinois (WTVP)'), # http://www.wtvp.org/
94 ('video.iptv.org', 'Iowa Public Television/IPTV (KDIN)'), # http://www.iptv.org/
95 ('video.ninenet.org', 'Nine Network (KETC)'), # http://www.ninenet.org
96 ('video.wfwa.org', 'PBS39 Fort Wayne (WFWA)'), # http://wfwa.org/
97 ('video.wfyi.org', 'WFYI Indianapolis (WFYI)'), # http://www.wfyi.org
98 ('video.mptv.org', 'Milwaukee Public Television (WMVS)'), # http://www.mptv.org
99 ('video.wnin.org', 'WNIN (WNIN)'), # http://www.wnin.org/
100 ('video.wnit.org', 'WNIT Public Television (WNIT)'), # http://www.wnit.org/
101 ('video.wpt.org', 'WPT (WPNE)'), # http://www.wpt.org/
102 ('video.wvut.org', 'WVUT/Channel 22 (WVUT)'), # http://wvut.org/
103 ('video.weiu.net', 'WEIU/Channel 51 (WEIU)'), # http://www.weiu.net
104 ('video.wqpt.org', 'WQPT-TV (WQPT)'), # http://www.wqpt.org
105 ('video.wycc.org', 'WYCC PBS Chicago (WYCC)'), # http://www.wycc.org
106 # ('lakeshorepublicmedia.org', 'Lakeshore Public Television (WYIN)'), # http://lakeshorepublicmedia.org/
107 ('video.wipb.org', 'WIPB-TV (WIPB)'), # http://wipb.org
108 ('video.indianapublicmedia.org', 'WTIU (WTIU)'), # http://indianapublicmedia.org/tv/
109 ('watch.cetconnect.org', 'CET (WCET)'), # http://www.cetconnect.org
110 ('video.thinktv.org', 'ThinkTVNetwork (WPTD)'), # http://www.thinktv.org
111 ('video.wbgu.org', 'WBGU-TV (WBGU)'), # http://wbgu.org
112 ('video.wgvu.org', 'WGVU TV (WGVU)'), # http://www.wgvu.org/
113 ('video.netnebraska.org', 'NET1 (KUON)'), # http://netnebraska.org
114 ('video.pioneer.org', 'Pioneer Public Television (KWCM)'), # http://www.pioneer.org
115 ('watch.sdpb.org', 'SDPB Television (KUSD)'), # http://www.sdpb.org
116 ('video.tpt.org', 'TPT (KTCA)'), # http://www.tpt.org
117 ('watch.ksmq.org', 'KSMQ (KSMQ)'), # http://www.ksmq.org/
118 ('watch.kpts.org', 'KPTS/Channel 8 (KPTS)'), # http://www.kpts.org/
119 ('watch.ktwu.org', 'KTWU/Channel 11 (KTWU)'), # http://ktwu.org
120 # ('shptv.org', 'Smoky Hills Public Television (KOOD)'), # http://www.shptv.org
121 # ('kcpt.org', 'KCPT Kansas City Public Television (KCPT)'), # http://kcpt.org/
122 # ('blueridgepbs.org', 'Blue Ridge PBS (WBRA)'), # http://www.blueridgepbs.org/
123 ('watch.easttennesseepbs.org', 'East Tennessee PBS (WSJK)'), # http://easttennesseepbs.org
124 ('video.wcte.tv', 'WCTE-TV (WCTE)'), # http://www.wcte.org
125 ('video.wljt.org', 'WLJT, Channel 11 (WLJT)'), # http://wljt.org/
126 ('video.wosu.org', 'WOSU TV (WOSU)'), # http://wosu.org/
127 ('video.woub.org', 'WOUB/WOUC (WOUB)'), # http://woub.org/tv/index.php?section=5
128 ('video.wvpublic.org', 'WVPB (WVPB)'), # http://wvpublic.org/
129 ('video.wkyupbs.org', 'WKYU-PBS (WKYU)'), # http://www.wkyupbs.org
130 # ('wyes.org', 'WYES-TV/New Orleans (WYES)'), # http://www.wyes.org
131 ('video.kera.org', 'KERA 13 (KERA)'), # http://www.kera.org/
132 ('video.mpbn.net', 'MPBN (WCBB)'), # http://www.mpbn.net/
133 ('video.mountainlake.org', 'Mountain Lake PBS (WCFE)'), # http://www.mountainlake.org/
134 ('video.nhptv.org', 'NHPTV (WENH)'), # http://nhptv.org/
135 ('video.vpt.org', 'Vermont PBS (WETK)'), # http://www.vpt.org
136 ('video.witf.org', 'witf (WITF)'), # http://www.witf.org
137 ('watch.wqed.org', 'WQED Multimedia (WQED)'), # http://www.wqed.org/
138 ('video.wmht.org', 'WMHT Educational Telecommunications (WMHT)'), # http://www.wmht.org/home/
139 ('video.deltabroadcasting.org', 'Q-TV (WDCQ)'), # http://www.deltabroadcasting.org
140 ('video.dptv.org', 'WTVS Detroit Public TV (WTVS)'), # http://www.dptv.org/
141 ('video.wcmu.org', 'CMU Public Television (WCMU)'), # http://www.wcmu.org
142 ('video.wkar.org', 'WKAR-TV (WKAR)'), # http://wkar.org/
143 ('wnmuvideo.nmu.edu', 'WNMU-TV Public TV 13 (WNMU)'), # http://wnmutv.nmu.edu
144 ('video.wdse.org', 'WDSE - WRPT (WDSE)'), # http://www.wdse.org/
145 ('video.wgte.org', 'WGTE TV (WGTE)'), # http://www.wgte.org
146 ('video.lptv.org', 'Lakeland Public Television (KAWE)'), # http://www.lakelandptv.org
147 # ('prairiepublic.org', 'PRAIRIE PUBLIC (KFME)'), # http://www.prairiepublic.org/
148 ('video.kmos.org', 'KMOS-TV - Channels 6.1, 6.2 and 6.3 (KMOS)'), # http://www.kmos.org/
149 ('watch.montanapbs.org', 'MontanaPBS (KUSM)'), # http://montanapbs.org
150 ('video.krwg.org', 'KRWG/Channel 22 (KRWG)'), # http://www.krwg.org
151 ('video.kacvtv.org', 'KACV (KACV)'), # http://www.panhandlepbs.org/home/
152 ('video.kcostv.org', 'KCOS/Channel 13 (KCOS)'), # www.kcostv.org
153 ('video.wcny.org', 'WCNY/Channel 24 (WCNY)'), # http://www.wcny.org
154 ('video.wned.org', 'WNED (WNED)'), # http://www.wned.org/
155 ('watch.wpbstv.org', 'WPBS (WPBS)'), # http://www.wpbstv.org
156 ('video.wskg.org', 'WSKG Public TV (WSKG)'), # http://wskg.org
157 ('video.wxxi.org', 'WXXI (WXXI)'), # http://wxxi.org
158 ('video.wpsu.org', 'WPSU (WPSU)'), # http://www.wpsu.org
159 # ('wqln.org', 'WQLN/Channel 54 (WQLN)'), # http://www.wqln.org
160 ('on-demand.wvia.org', 'WVIA Public Media Studios (WVIA)'), # http://www.wvia.org/
161 ('video.wtvi.org', 'WTVI (WTVI)'), # http://www.wtvi.org/
162 # ('whro.org', 'WHRO (WHRO)'), # http://whro.org
163 ('video.westernreservepublicmedia.org', 'Western Reserve PBS (WNEO)'), # http://www.WesternReservePublicMedia.org/
164 ('video.ideastream.org', 'WVIZ/PBS ideastream (WVIZ)'), # http://www.wviz.org/
165 ('video.kcts9.org', 'KCTS 9 (KCTS)'), # http://kcts9.org/
166 ('video.basinpbs.org', 'Basin PBS (KPBT)'), # http://www.basinpbs.org
167 ('video.houstonpbs.org', 'KUHT / Channel 8 (KUHT)'), # http://www.houstonpublicmedia.org/
168 # ('tamu.edu', 'KAMU - TV (KAMU)'), # http://KAMU.tamu.edu
169 # ('kedt.org', 'KEDT/Channel 16 (KEDT)'), # http://www.kedt.org
170 ('video.klrn.org', 'KLRN (KLRN)'), # http://www.klrn.org
171 ('video.klru.tv', 'KLRU (KLRU)'), # http://www.klru.org
172 # ('kmbh.org', 'KMBH-TV (KMBH)'), # http://www.kmbh.org
173 # ('knct.org', 'KNCT (KNCT)'), # http://www.knct.org
174 # ('ktxt.org', 'KTTZ-TV (KTXT)'), # http://www.ktxt.org
175 ('video.wtjx.org', 'WTJX Channel 12 (WTJX)'), # http://www.wtjx.org/
176 ('video.ideastations.org', 'WCVE PBS (WCVE)'), # http://ideastations.org/
177 ('video.kbtc.org', 'KBTC Public Television (KBTC)'), # http://kbtc.org
181 IE_DESC = 'Public Broadcasting Service (PBS) and member stations: %s' % ', '.join(list(zip(*_STATIONS))[1])
183 _VALID_URL = r'''(?x)https?://
186 (?:%s)/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
187 # Article with embedded player (or direct video)
188 (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
190 (?:video|player)\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
192 ''' % '|'.join(re.escape(p) for p in list(zip(*_STATIONS))[0])
196 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
197 'md5': 'ce1888486f0908d555a8093cac9a7362',
201 'title': 'Constitution USA with Peter Sagal - A More Perfect Union',
202 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
206 'skip_download': True, # requires ffmpeg
210 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
211 'md5': '143c98aa54a346738a3d78f54c925321',
215 'title': 'FRONTLINE - Losing Iraq',
216 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
220 'skip_download': True, # requires ffmpeg
224 'url': 'http://www.pbs.org/newshour/bb/education-jan-june12-cyberschools_02-23/',
225 'md5': 'b19856d7f5351b17a5ab1dc6a64be633',
229 'title': 'PBS NewsHour - Cyber Schools Gain Popularity, but Quality Questions Persist',
230 'description': 'md5:5871c15cba347c1b3d28ac47a73c7c28',
235 'url': 'http://www.pbs.org/wnet/gperf/dudamel-conducts-verdi-requiem-hollywood-bowl-full-episode/3374/',
236 'md5': 'c62859342be2a0358d6c9eb306595978',
240 'description': 'md5:68d87ef760660eb564455eb30ca464fe',
241 'title': 'Great Performances - Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
243 'thumbnail': 're:^https?://.*\.jpg$',
246 'skip_download': True, # requires ffmpeg
250 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
251 'md5': '908f3e5473a693b266b84e25e1cf9703',
254 'display_id': 'killer-typhoon',
256 'description': 'md5:c741d14e979fc53228c575894094f157',
257 'title': 'NOVA - Killer Typhoon',
259 'thumbnail': 're:^https?://.*\.jpg$',
260 'upload_date': '20140122',
264 'skip_download': True, # requires ffmpeg
268 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
270 'id': 'united-states-of-secrets',
275 'url': 'http://www.pbs.org/wgbh/americanexperience/films/death/player/',
278 'display_id': 'player',
280 'title': 'American Experience - Death and the Civil War, Chapter 1',
281 '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.',
283 'thumbnail': 're:^https?://.*\.jpg$',
286 'skip_download': True, # requires ffmpeg
290 'url': 'http://video.pbs.org/video/2365367186/',
293 'display_id': '2365367186',
295 'title': 'To Catch A Comet - Full Episode',
296 'description': 'On November 12, 2014, billions of kilometers from Earth, spacecraft orbiter Rosetta and lander Philae did what no other had dared to attempt \u2014 land on the volatile surface of a comet as it zooms around the sun at 67,000 km/hr. The European Space Agency hopes this mission can help peer into our past and unlock secrets of our origins.',
298 'thumbnail': 're:^https?://.*\.jpg$',
301 'skip_download': True, # requires ffmpeg
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
308 # https://github.com/rg3/youtube-dl/issues/7059)
309 'url': 'http://www.pbs.org/food/features/a-chefs-life-season-3-episode-5-prickly-business/',
312 'display_id': 'a-chefs-life-season-3-episode-5-prickly-business',
314 'title': "A Chef's Life - Season 3, Ep. 5: Prickly Business",
315 'description': 'md5:61db2ddf27c9912f09c241014b118ed1',
317 'thumbnail': 're:^https?://.*\.jpg$',
320 'skip_download': True, # requires ffmpeg
324 # Frontline video embedded via flp2012.js
325 'url': 'http://www.pbs.org/wgbh/pages/frontline/the-atomic-artists',
328 'display_id': 'the-atomic-artists',
330 'title': 'FRONTLINE - The Atomic Artists',
331 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
333 'thumbnail': 're:^https?://.*\.jpg$',
336 'skip_download': True, # requires ffmpeg
340 'url': 'http://player.pbs.org/widget/partnerplayer/2365297708/?start=0&end=0&chapterbar=false&endscreen=false&topbar=true',
341 'only_matching': True,
344 'url': 'http://watch.knpb.org/video/2365616055/',
345 'only_matching': True,
349 101: 'We\'re sorry, but this video is not yet available.',
350 403: 'We\'re sorry, but this video is not available in your region due to right restrictions.',
351 404: 'We are experiencing technical difficulties that are preventing us from playing the video at this time. Please check back again soon.',
352 410: 'This video has expired and is no longer available for online streaming.',
355 def _extract_webpage(self, url):
356 mobj = re.match(self._VALID_URL, url)
358 presumptive_id = mobj.group('presumptive_id')
359 display_id = presumptive_id
361 webpage = self._download_webpage(url, display_id)
363 upload_date = unified_strdate(self._search_regex(
364 r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
365 webpage, 'upload date', default=None))
367 # tabbed frontline videos
368 tabbed_videos = re.findall(
369 r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"', webpage)
371 return tabbed_videos, presumptive_id, upload_date
374 r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
375 r'class="coveplayerid">([^<]+)<', # coveplayer
376 r'<section[^>]+data-coveid="(\d+)"', # coveplayer from http://www.pbs.org/wgbh/frontline/film/real-csi/
377 r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
380 media_id = self._search_regex(
381 MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
383 return media_id, presumptive_id, upload_date
385 # Fronline video embedded via flp
386 video_id = self._search_regex(
387 r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid', default=None)
389 # pkg_id calculation is reverse engineered from
390 # http://www.pbs.org/wgbh/pages/frontline/js/flp2012.js
391 prg_id = self._search_regex(
392 r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid')[7:]
394 prg_id = prg_id.split('q')[1]
395 prg_id = int(prg_id, 16)
396 getdir = self._download_json(
397 'http://www.pbs.org/wgbh/pages/frontline/.json/getdir/getdir%d.json' % prg_id,
398 presumptive_id, 'Downloading getdir JSON',
399 transform_source=strip_jsonp)
400 return getdir['mid'], presumptive_id, upload_date
402 for iframe in re.findall(r'(?s)<iframe(.+?)></iframe>', webpage):
403 url = self._search_regex(
404 r'src=(["\'])(?P<url>.+?partnerplayer.+?)\1', iframe,
405 'player URL', default=None, group='url')
409 mobj = re.match(self._VALID_URL, url)
411 player_id = mobj.group('player_id')
413 display_id = player_id
415 player_page = self._download_webpage(
416 url, display_id, note='Downloading player page',
417 errnote='Could not download player page')
418 video_id = self._search_regex(
419 r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
421 video_id = mobj.group('id')
422 display_id = video_id
424 return video_id, display_id, None
426 def _real_extract(self, url):
427 video_id, display_id, upload_date = self._extract_webpage(url)
429 if isinstance(video_id, list):
430 entries = [self.url_result(
431 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
432 for vid_id in video_id]
433 return self.playlist_result(entries, display_id)
435 info = self._download_json(
436 'http://player.pbs.org/videoInfo/%s?format=json&type=partner' % video_id,
440 for encoding_name in ('recommended_encoding', 'alternate_encoding'):
441 redirect = info.get(encoding_name)
444 redirect_url = redirect.get('url')
448 redirect_info = self._download_json(
449 redirect_url + '?format=json', display_id,
450 'Downloading %s video url info' % encoding_name)
452 if redirect_info['status'] == 'error':
453 raise ExtractorError(
456 self._ERRORS.get(redirect_info['http_code'], redirect_info['message'])),
459 format_url = redirect_info.get('url')
463 if determine_ext(format_url) == 'm3u8':
464 formats.extend(self._extract_m3u8_formats(
465 format_url, display_id, 'mp4', preference=1, m3u8_id='hls'))
469 'format_id': redirect.get('eeid'),
471 self._sort_formats(formats)
473 rating_str = info.get('rating')
474 if rating_str is not None:
475 rating_str = rating_str.rpartition('-')[2]
476 age_limit = US_RATINGS.get(rating_str)
479 closed_captions_url = info.get('closed_captions_url')
480 if closed_captions_url:
483 'url': closed_captions_url,
486 # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
487 # Try turning it to 'program - title' naming scheme if possible
488 alt_title = info.get('program', {}).get('title')
490 info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + '[\s\-:]+', '', info['title'])
494 'display_id': display_id,
495 'title': info['title'],
496 'description': info['program'].get('description'),
497 'thumbnail': info.get('image_url'),
498 'duration': int_or_none(info.get('duration')),
499 'age_limit': age_limit,
500 'upload_date': upload_date,
502 'subtitles': subtitles,