pbs.py 38 KB

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