pbs.py 31 KB

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