You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

502 lines
25 KiB

  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. strip_jsonp,
  10. unified_strdate,
  11. US_RATINGS,
  12. )
  13. class PBSIE(InfoExtractor):
  14. _STATIONS = (
  15. ('aptv.org', 'APT - Alabama Public Television (WBIQ)'), # http://aptv.org/
  16. ('gpb.org', 'GPB/Georgia Public Broadcasting (WGTV)'), # http://www.gpb.org/
  17. ('mpbonline.org', 'Mississippi Public Broadcasting (WMPN)'), # http://www.mpbonline.org
  18. ('wnpt.org', 'Nashville Public Television (WNPT)'), # http://www.wnpt.org
  19. ('wfsu.org', 'WFSU-TV (WFSU)'), # http://wfsu.org/
  20. ('wsre.org', 'WSRE (WSRE)'), # http://www.wsre.org
  21. ('wtcitv.org', 'WTCI (WTCI)'), # http://www.wtcitv.org
  22. ('pba.org', 'WPBA/Channel 30 (WPBA)'), # http://pba.org/
  23. ('alaskapublic.org', 'Alaska Public Media (KAKM)'), # http://alaskapublic.org/kakm
  24. ('kuac.org', 'KUAC (KUAC)'), # http://kuac.org/kuac-tv/
  25. ('ktoo.org', '360 North (KTOO)'), # http://www.ktoo.org/
  26. ('azpm.org', 'KUAT 6 (KUAT)'), # http://www.azpm.org/
  27. ('azpbs.org', 'Arizona PBS (KAET)'), # http://www.azpbs.org
  28. ('newmexicopbs.org', 'KNME-TV/Channel 5 (KNME)'), # http://www.newmexicopbs.org/
  29. ('vegaspbs.org', 'Vegas PBS (KLVX)'), # http://vegaspbs.org/
  30. ('aetn.org', 'AETN/ARKANSAS ETV NETWORK (KETS)'), # http://www.aetn.org/
  31. ('ket.org', 'KET (WKLE)'), # http://www.ket.org/
  32. ('wkno.org', 'WKNO/Channel 10 (WKNO)'), # http://www.wkno.org/
  33. ('lpb.org', 'LPB/LOUISIANA PUBLIC BROADCASTING (WLPB)'), # http://www.lpb.org/
  34. ('oeta.tv', 'OETA (KETA)'), # http://www.oeta.tv
  35. ('optv.org', 'Ozarks Public Television (KOZK)'), # http://www.optv.org/
  36. ('wsiu.org', 'WSIU Public Broadcasting (WSIU)'), # http://www.wsiu.org/
  37. ('keet.org', 'KEET TV (KEET)'), # http://www.keet.org
  38. ('kixe.org', 'KIXE/Channel 9 (KIXE)'), # http://kixe.org/
  39. ('kpbs.org', 'KPBS San Diego (KPBS)'), # http://www.kpbs.org/
  40. ('kqed.org', 'KQED (KQED)'), # http://www.kqed.org
  41. ('kvie.org', 'KVIE Public Television (KVIE)'), # http://www.kvie.org
  42. ('pbssocal.org', 'PBS SoCal/KOCE (KOCE)'), # http://www.pbssocal.org/
  43. ('valleypbs.org', 'ValleyPBS (KVPT)'), # http://www.valleypbs.org/
  44. ('cptv.org', 'CONNECTICUT PUBLIC TELEVISION (WEDH)'), # http://cptv.org
  45. ('knpb.org', 'KNPB Channel 5 (KNPB)'), # http://www.knpb.org/
  46. ('soptv.org', 'SOPTV (KSYS)'), # http://www.soptv.org
  47. ('klcs.org', 'KLCS/Channel 58 (KLCS)'), # http://www.klcs.org
  48. ('krcb.org', 'KRCB Television & Radio (KRCB)'), # http://www.krcb.org
  49. ('kvcr.org', 'KVCR TV/DT/FM :: Vision for the Future (KVCR)'), # http://kvcr.org
  50. ('rmpbs.org', 'Rocky Mountain PBS (KRMA)'), # http://www.rmpbs.org
  51. ('kenw.org', 'KENW-TV3 (KENW)'), # http://www.kenw.org
  52. ('kued.org', 'KUED Channel 7 (KUED)'), # http://www.kued.org
  53. ('wyomingpbs.org', 'Wyoming PBS (KCWC)'), # http://www.wyomingpbs.org
  54. ('cpt12.org', 'Colorado Public Television / KBDI 12 (KBDI)'), # http://www.cpt12.org/
  55. ('kbyutv.org', 'KBYU-TV (KBYU)'), # http://www.kbyutv.org/
  56. ('thirteen.org', 'Thirteen/WNET New York (WNET)'), # http://www.thirteen.org
  57. ('wgbh.org', 'WGBH/Channel 2 (WGBH)'), # http://wgbh.org
  58. ('wgby.org', 'WGBY (WGBY)'), # http://www.wgby.org
  59. ('njtvonline.org', 'NJTV Public Media NJ (WNJT)'), # http://www.njtvonline.org/
  60. ('ripbs.org', 'Rhode Island PBS (WSBE)'), # http://www.ripbs.org/home/
  61. ('wliw.org', 'WLIW21 (WLIW)'), # http://www.wliw.org/
  62. ('mpt.org', 'mpt/Maryland Public Television (WMPB)'), # http://www.mpt.org
  63. ('weta.org', 'WETA Television and Radio (WETA)'), # http://www.weta.org
  64. ('whyy.org', 'WHYY (WHYY)'), # http://www.whyy.org
  65. ('wlvt.org', 'PBS 39 (WLVT)'), # http://www.wlvt.org/
  66. ('wvpt.net', 'WVPT - Your Source for PBS and More! (WVPT)'), # http://www.wvpt.net
  67. ('whut.org', 'Howard University Television (WHUT)'), # http://www.whut.org
  68. ('wedu.org', 'WEDU PBS (WEDU)'), # http://www.wedu.org
  69. ('wgcu.org', 'WGCU Public Media (WGCU)'), # http://www.wgcu.org/
  70. ('wjct.org', 'WJCT Public Broadcasting (WJCT)'), # http://www.wjct.org
  71. ('wpbt2.org', 'WPBT2 (WPBT)'), # http://www.wpbt2.org
  72. ('wucftv.org', 'WUCF TV (WUCF)'), # http://wucftv.org
  73. ('wuft.org', 'WUFT/Channel 5 (WUFT)'), # http://www.wuft.org
  74. ('wxel.org', 'WXEL/Channel 42 (WXEL)'), # http://www.wxel.org/home/
  75. ('wlrn.org', 'WLRN/Channel 17 (WLRN)'), # http://www.wlrn.org/
  76. ('wusf.org', 'WUSF Public Broadcasting (WUSF)'), # http://wusf.org/
  77. ('scetv.org', 'ETV (WRLK)'), # http://www.scetv.org
  78. ('unctv.org', 'UNC-TV (WUNC)'), # http://www.unctv.org/
  79. ('pbsguam.org', 'PBS Guam (KGTF)'), # http://www.pbsguam.org/
  80. ('pbshawaii.org', 'PBS Hawaii - Oceanic Cable Channel 10 (KHET)'), # http://www.pbshawaii.org/
  81. ('idahoptv.org', 'Idaho Public Television (KAID)'), # http://idahoptv.org
  82. ('ksps.org', 'KSPS (KSPS)'), # http://www.ksps.org/home/
  83. ('opb.org', 'OPB (KOPB)'), # http://www.opb.org
  84. ('kwsu.org', 'KWSU/Channel 10 & KTNW/Channel 31 (KWSU)'), # http://www.kwsu.org
  85. ('illinois.edu', 'WILL-TV (WILL)'), # http://will.illinois.edu/
  86. ('wsec.tv', 'Network Knowledge - WSEC/Springfield (WSEC)'), # http://www.wsec.tv
  87. ('wttw.com', 'WTTW11 (WTTW)'), # http://www.wttw.com/
  88. ('wtvp.org', 'WTVP & WTVP.org, Public Media for Central Illinois (WTVP)'), # http://www.wtvp.org/
  89. ('iptv.org', 'Iowa Public Television/IPTV (KDIN)'), # http://www.iptv.org/
  90. ('ninenet.org', 'Nine Network (KETC)'), # http://www.ninenet.org
  91. ('wfwa.org', 'PBS39 Fort Wayne (WFWA)'), # http://wfwa.org/
  92. ('wfyi.org', 'WFYI Indianapolis (WFYI)'), # http://www.wfyi.org
  93. ('mptv.org', 'Milwaukee Public Television (WMVS)'), # http://www.mptv.org
  94. ('wnin.org', 'WNIN (WNIN)'), # http://www.wnin.org/
  95. ('wnit.org', 'WNIT Public Television (WNIT)'), # http://www.wnit.org/
  96. ('wpt.org', 'WPT (WPNE)'), # http://www.wpt.org/
  97. ('wvut.org', 'WVUT/Channel 22 (WVUT)'), # http://wvut.org/
  98. ('weiu.net', 'WEIU/Channel 51 (WEIU)'), # http://www.weiu.net
  99. ('wqpt.org', 'WQPT-TV (WQPT)'), # http://www.wqpt.org
  100. ('wycc.org', 'WYCC PBS Chicago (WYCC)'), # http://www.wycc.org
  101. ('lakeshorepublicmedia.org', 'Lakeshore Public Television (WYIN)'), # http://lakeshorepublicmedia.org/
  102. ('wipb.org', 'WIPB-TV (WIPB)'), # http://wipb.org
  103. ('indianapublicmedia.org', 'WTIU (WTIU)'), # http://indianapublicmedia.org/tv/
  104. ('cetconnect.org', 'CET (WCET)'), # http://www.cetconnect.org
  105. ('thinktv.org', 'ThinkTVNetwork (WPTD)'), # http://www.thinktv.org
  106. ('wbgu.org', 'WBGU-TV (WBGU)'), # http://wbgu.org
  107. ('wgvu.org', 'WGVU TV (WGVU)'), # http://www.wgvu.org/
  108. ('netnebraska.org', 'NET1 (KUON)'), # http://netnebraska.org
  109. ('pioneer.org', 'Pioneer Public Television (KWCM)'), # http://www.pioneer.org
  110. ('sdpb.org', 'SDPB Television (KUSD)'), # http://www.sdpb.org
  111. ('tpt.org', 'TPT (KTCA)'), # http://www.tpt.org
  112. ('ksmq.org', 'KSMQ (KSMQ)'), # http://www.ksmq.org/
  113. ('kpts.org', 'KPTS/Channel 8 (KPTS)'), # http://www.kpts.org/
  114. ('ktwu.org', 'KTWU/Channel 11 (KTWU)'), # http://ktwu.org
  115. ('shptv.org', 'Smoky Hills Public Television (KOOD)'), # http://www.shptv.org
  116. ('kcpt.org', 'KCPT Kansas City Public Television (KCPT)'), # http://kcpt.org/
  117. ('blueridgepbs.org', 'Blue Ridge PBS (WBRA)'), # http://www.blueridgepbs.org/
  118. ('easttennesseepbs.org', 'East Tennessee PBS (WSJK)'), # http://easttennesseepbs.org
  119. ('wcte.org', 'WCTE-TV (WCTE)'), # http://www.wcte.org
  120. ('wljt.org', 'WLJT, Channel 11 (WLJT)'), # http://wljt.org/
  121. ('wosu.org', 'WOSU TV (WOSU)'), # http://wosu.org/
  122. ('woub.org', 'WOUB/WOUC (WOUB)'), # http://woub.org/tv/index.php?section=5
  123. ('wvpublic.org', 'WVPB (WVPB)'), # http://wvpublic.org/
  124. ('wkyupbs.org', 'WKYU-PBS (WKYU)'), # http://www.wkyupbs.org
  125. ('wyes.org', 'WYES-TV/New Orleans (WYES)'), # http://www.wyes.org
  126. ('kera.org', 'KERA 13 (KERA)'), # http://www.kera.org/
  127. ('mpbn.net', 'MPBN (WCBB)'), # http://www.mpbn.net/
  128. ('mountainlake.org', 'Mountain Lake PBS (WCFE)'), # http://www.mountainlake.org/
  129. ('nhptv.org', 'NHPTV (WENH)'), # http://nhptv.org/
  130. ('vpt.org', 'Vermont PBS (WETK)'), # http://www.vpt.org
  131. ('witf.org', 'witf (WITF)'), # http://www.witf.org
  132. ('wqed.org', 'WQED Multimedia (WQED)'), # http://www.wqed.org/
  133. ('wmht.org', 'WMHT Educational Telecommunications (WMHT)'), # http://www.wmht.org/home/
  134. ('deltabroadcasting.org', 'Q-TV (WDCQ)'), # http://www.deltabroadcasting.org
  135. ('dptv.org', 'WTVS Detroit Public TV (WTVS)'), # http://www.dptv.org/
  136. ('wcmu.org', 'CMU Public Television (WCMU)'), # http://www.wcmu.org
  137. ('wkar.org', 'WKAR-TV (WKAR)'), # http://wkar.org/
  138. ('nmu.edu', 'WNMU-TV Public TV 13 (WNMU)'), # http://wnmutv.nmu.edu
  139. ('wdse.org', 'WDSE - WRPT (WDSE)'), # http://www.wdse.org/
  140. ('wgte.org', 'WGTE TV (WGTE)'), # http://www.wgte.org
  141. ('lakelandptv.org', 'Lakeland Public Television (KAWE)'), # http://www.lakelandptv.org
  142. ('prairiepublic.org', 'PRAIRIE PUBLIC (KFME)'), # http://www.prairiepublic.org/
  143. ('kmos.org', 'KMOS-TV - Channels 6.1, 6.2 and 6.3 (KMOS)'), # http://www.kmos.org/
  144. ('montanapbs.org', 'MontanaPBS (KUSM)'), # http://montanapbs.org
  145. ('krwg.org', 'KRWG/Channel 22 (KRWG)'), # http://www.krwg.org
  146. ('panhandlepbs.org', 'KACV (KACV)'), # http://www.panhandlepbs.org/home/
  147. ('kcostv.org', 'KCOS/Channel 13 (KCOS)'), # www.kcostv.org
  148. ('wcny.org', 'WCNY/Channel 24 (WCNY)'), # http://www.wcny.org
  149. ('wned.org', 'WNED (WNED)'), # http://www.wned.org/
  150. ('wpbstv.org', 'WPBS (WPBS)'), # http://www.wpbstv.org
  151. ('wskg.org', 'WSKG Public TV (WSKG)'), # http://wskg.org
  152. ('wxxi.org', 'WXXI (WXXI)'), # http://wxxi.org
  153. ('wpsu.org', 'WPSU (WPSU)'), # http://www.wpsu.org
  154. ('wqln.org', 'WQLN/Channel 54 (WQLN)'), # http://www.wqln.org
  155. ('wvia.org', 'WVIA Public Media Studios (WVIA)'), # http://www.wvia.org/
  156. ('wtvi.org', 'WTVI (WTVI)'), # http://www.wtvi.org/
  157. ('whro.org', 'WHRO (WHRO)'), # http://whro.org
  158. ('westernreservepublicmedia.org', 'Western Reserve PBS (WNEO)'), # http://www.WesternReservePublicMedia.org/
  159. ('wviz.org', 'WVIZ/PBS ideastream (WVIZ)'), # http://www.wviz.org/
  160. ('kcts9.org', 'KCTS 9 (KCTS)'), # http://kcts9.org/
  161. ('basinpbs.org', 'Basin PBS (KPBT)'), # http://www.basinpbs.org
  162. ('houstonpublicmedia.org', 'KUHT / Channel 8 (KUHT)'), # http://www.houstonpublicmedia.org/
  163. ('tamu.edu', 'KAMU - TV (KAMU)'), # http://KAMU.tamu.edu
  164. ('kedt.org', 'KEDT/Channel 16 (KEDT)'), # http://www.kedt.org
  165. ('klrn.org', 'KLRN (KLRN)'), # http://www.klrn.org
  166. ('klru.org', 'KLRU (KLRU)'), # http://www.klru.org
  167. ('kmbh.org', 'KMBH-TV (KMBH)'), # http://www.kmbh.org
  168. ('knct.org', 'KNCT (KNCT)'), # http://www.knct.org
  169. ('ktxt.org', 'KTTZ-TV (KTXT)'), # http://www.ktxt.org
  170. ('wtjx.org', 'WTJX Channel 12 (WTJX)'), # http://www.wtjx.org/
  171. ('ideastations.org', 'WCVE PBS (WCVE)'), # http://ideastations.org/
  172. ('kbtc.org', 'KBTC Public Television (KBTC)'), # http://kbtc.org
  173. )
  174. IE_NAME = 'pbs'
  175. IE_DESC = 'Public Broadcasting Service (PBS) and member stations: %s' % ', '.join(list(zip(*_STATIONS))[1])
  176. _VALID_URL = r'''(?x)https?://
  177. (?:
  178. # Direct video URL
  179. (?:videos?|watch)\.(?:%s)/(?:viralplayer|video)/(?P<id>[0-9]+)/? |
  180. # Article with embedded player (or direct video)
  181. (?:www\.)?pbs\.org/(?:[^/]+/){2,5}(?P<presumptive_id>[^/]+?)(?:\.html)?/?(?:$|[?\#]) |
  182. # Player
  183. (?:video|player)\.pbs\.org/(?:widget/)?partnerplayer/(?P<player_id>[^/]+)/
  184. )
  185. ''' % '|'.join(list(zip(*_STATIONS))[0])
  186. _TESTS = [
  187. {
  188. 'url': 'http://www.pbs.org/tpt/constitution-usa-peter-sagal/watch/a-more-perfect-union/',
  189. 'md5': 'ce1888486f0908d555a8093cac9a7362',
  190. 'info_dict': {
  191. 'id': '2365006249',
  192. 'ext': 'mp4',
  193. 'title': 'Constitution USA with Peter Sagal - A More Perfect Union',
  194. 'description': 'md5:ba0c207295339c8d6eced00b7c363c6a',
  195. 'duration': 3190,
  196. },
  197. 'params': {
  198. 'skip_download': True, # requires ffmpeg
  199. },
  200. },
  201. {
  202. 'url': 'http://www.pbs.org/wgbh/pages/frontline/losing-iraq/',
  203. 'md5': '143c98aa54a346738a3d78f54c925321',
  204. 'info_dict': {
  205. 'id': '2365297690',
  206. 'ext': 'mp4',
  207. 'title': 'FRONTLINE - Losing Iraq',
  208. 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
  209. 'duration': 5050,
  210. },
  211. 'params': {
  212. 'skip_download': True, # requires ffmpeg
  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:5871c15cba347c1b3d28ac47a73c7c28',
  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. 'description': 'md5:68d87ef760660eb564455eb30ca464fe',
  233. 'title': 'Great Performances - Dudamel Conducts Verdi Requiem at the Hollywood Bowl - Full',
  234. 'duration': 6559,
  235. 'thumbnail': 're:^https?://.*\.jpg$',
  236. },
  237. 'params': {
  238. 'skip_download': True, # requires ffmpeg
  239. },
  240. },
  241. {
  242. 'url': 'http://www.pbs.org/wgbh/nova/earth/killer-typhoon.html',
  243. 'md5': '908f3e5473a693b266b84e25e1cf9703',
  244. 'info_dict': {
  245. 'id': '2365160389',
  246. 'display_id': 'killer-typhoon',
  247. 'ext': 'mp4',
  248. 'description': 'md5:c741d14e979fc53228c575894094f157',
  249. 'title': 'NOVA - Killer Typhoon',
  250. 'duration': 3172,
  251. 'thumbnail': 're:^https?://.*\.jpg$',
  252. 'upload_date': '20140122',
  253. 'age_limit': 10,
  254. },
  255. 'params': {
  256. 'skip_download': True, # requires ffmpeg
  257. },
  258. },
  259. {
  260. 'url': 'http://www.pbs.org/wgbh/pages/frontline/united-states-of-secrets/',
  261. 'info_dict': {
  262. 'id': 'united-states-of-secrets',
  263. },
  264. 'playlist_count': 2,
  265. },
  266. {
  267. 'url': 'http://www.pbs.org/wgbh/americanexperience/films/death/player/',
  268. 'info_dict': {
  269. 'id': '2276541483',
  270. 'display_id': 'player',
  271. 'ext': 'mp4',
  272. 'title': 'American Experience - Death and the Civil War, Chapter 1',
  273. '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.',
  274. 'duration': 682,
  275. 'thumbnail': 're:^https?://.*\.jpg$',
  276. },
  277. 'params': {
  278. 'skip_download': True, # requires ffmpeg
  279. },
  280. },
  281. {
  282. 'url': 'http://video.pbs.org/video/2365367186/',
  283. 'info_dict': {
  284. 'id': '2365367186',
  285. 'display_id': '2365367186',
  286. 'ext': 'mp4',
  287. 'title': 'To Catch A Comet - Full Episode',
  288. '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.',
  289. 'duration': 3342,
  290. 'thumbnail': 're:^https?://.*\.jpg$',
  291. },
  292. 'params': {
  293. 'skip_download': True, # requires ffmpeg
  294. },
  295. 'skip': 'Expired',
  296. },
  297. {
  298. # Video embedded in iframe containing angle brackets as attribute's value (e.g.
  299. # "<iframe style='position: absolute;<br />\ntop: 0; left: 0;' ...", see
  300. # https://github.com/rg3/youtube-dl/issues/7059)
  301. 'url': 'http://www.pbs.org/food/features/a-chefs-life-season-3-episode-5-prickly-business/',
  302. 'info_dict': {
  303. 'id': '2365546844',
  304. 'display_id': 'a-chefs-life-season-3-episode-5-prickly-business',
  305. 'ext': 'mp4',
  306. 'title': "A Chef's Life - Season 3, Ep. 5: Prickly Business",
  307. 'description': 'md5:61db2ddf27c9912f09c241014b118ed1',
  308. 'duration': 1480,
  309. 'thumbnail': 're:^https?://.*\.jpg$',
  310. },
  311. 'params': {
  312. 'skip_download': True, # requires ffmpeg
  313. },
  314. },
  315. {
  316. # Frontline video embedded via flp2012.js
  317. 'url': 'http://www.pbs.org/wgbh/pages/frontline/the-atomic-artists',
  318. 'info_dict': {
  319. 'id': '2070868960',
  320. 'display_id': 'the-atomic-artists',
  321. 'ext': 'mp4',
  322. 'title': 'FRONTLINE - The Atomic Artists',
  323. 'description': 'md5:f5bfbefadf421e8bb8647602011caf8e',
  324. 'duration': 723,
  325. 'thumbnail': 're:^https?://.*\.jpg$',
  326. },
  327. 'params': {
  328. 'skip_download': True, # requires ffmpeg
  329. },
  330. },
  331. {
  332. 'url': 'http://player.pbs.org/widget/partnerplayer/2365297708/?start=0&end=0&chapterbar=false&endscreen=false&topbar=true',
  333. 'only_matching': True,
  334. },
  335. {
  336. 'url': 'http://watch.knpb.org/video/2365616055/',
  337. 'only_matching': True,
  338. }
  339. ]
  340. _ERRORS = {
  341. 101: 'We\'re sorry, but this video is not yet available.',
  342. 403: 'We\'re sorry, but this video is not available in your region due to right restrictions.',
  343. 404: 'We are experiencing technical difficulties that are preventing us from playing the video at this time. Please check back again soon.',
  344. 410: 'This video has expired and is no longer available for online streaming.',
  345. }
  346. def _extract_webpage(self, url):
  347. mobj = re.match(self._VALID_URL, url)
  348. presumptive_id = mobj.group('presumptive_id')
  349. display_id = presumptive_id
  350. if presumptive_id:
  351. webpage = self._download_webpage(url, display_id)
  352. upload_date = unified_strdate(self._search_regex(
  353. r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
  354. webpage, 'upload date', default=None))
  355. # tabbed frontline videos
  356. tabbed_videos = re.findall(
  357. r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"', webpage)
  358. if tabbed_videos:
  359. return tabbed_videos, presumptive_id, upload_date
  360. MEDIA_ID_REGEXES = [
  361. r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
  362. r'class="coveplayerid">([^<]+)<', # coveplayer
  363. r'<section[^>]+data-coveid="(\d+)"', # coveplayer from http://www.pbs.org/wgbh/frontline/film/real-csi/
  364. r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
  365. ]
  366. media_id = self._search_regex(
  367. MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
  368. if media_id:
  369. return media_id, presumptive_id, upload_date
  370. # Fronline video embedded via flp
  371. video_id = self._search_regex(
  372. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid', default=None)
  373. if video_id:
  374. # pkg_id calculation is reverse engineered from
  375. # http://www.pbs.org/wgbh/pages/frontline/js/flp2012.js
  376. prg_id = self._search_regex(
  377. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid')[7:]
  378. if 'q' in prg_id:
  379. prg_id = prg_id.split('q')[1]
  380. prg_id = int(prg_id, 16)
  381. getdir = self._download_json(
  382. 'http://www.pbs.org/wgbh/pages/frontline/.json/getdir/getdir%d.json' % prg_id,
  383. presumptive_id, 'Downloading getdir JSON',
  384. transform_source=strip_jsonp)
  385. return getdir['mid'], presumptive_id, upload_date
  386. for iframe in re.findall(r'(?s)<iframe(.+?)></iframe>', webpage):
  387. url = self._search_regex(
  388. r'src=(["\'])(?P<url>.+?partnerplayer.+?)\1', iframe,
  389. 'player URL', default=None, group='url')
  390. if url:
  391. break
  392. mobj = re.match(self._VALID_URL, url)
  393. player_id = mobj.group('player_id')
  394. if not display_id:
  395. display_id = player_id
  396. if player_id:
  397. player_page = self._download_webpage(
  398. url, display_id, note='Downloading player page',
  399. errnote='Could not download player page')
  400. video_id = self._search_regex(
  401. r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
  402. else:
  403. video_id = mobj.group('id')
  404. display_id = video_id
  405. return video_id, display_id, None
  406. def _real_extract(self, url):
  407. video_id, display_id, upload_date = self._extract_webpage(url)
  408. if isinstance(video_id, list):
  409. entries = [self.url_result(
  410. 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
  411. for vid_id in video_id]
  412. return self.playlist_result(entries, display_id)
  413. info = self._download_json(
  414. 'http://player.pbs.org/videoInfo/%s?format=json&type=partner' % video_id,
  415. display_id)
  416. formats = []
  417. for encoding_name in ('recommended_encoding', 'alternate_encoding'):
  418. redirect = info.get(encoding_name)
  419. if not redirect:
  420. continue
  421. redirect_url = redirect.get('url')
  422. if not redirect_url:
  423. continue
  424. redirect_info = self._download_json(
  425. redirect_url + '?format=json', display_id,
  426. 'Downloading %s video url info' % encoding_name)
  427. if redirect_info['status'] == 'error':
  428. raise ExtractorError(
  429. '%s said: %s' % (
  430. self.IE_NAME,
  431. self._ERRORS.get(redirect_info['http_code'], redirect_info['message'])),
  432. expected=True)
  433. format_url = redirect_info.get('url')
  434. if not format_url:
  435. continue
  436. if determine_ext(format_url) == 'm3u8':
  437. formats.extend(self._extract_m3u8_formats(
  438. format_url, display_id, 'mp4', preference=1, m3u8_id='hls'))
  439. else:
  440. formats.append({
  441. 'url': format_url,
  442. 'format_id': redirect.get('eeid'),
  443. })
  444. self._sort_formats(formats)
  445. rating_str = info.get('rating')
  446. if rating_str is not None:
  447. rating_str = rating_str.rpartition('-')[2]
  448. age_limit = US_RATINGS.get(rating_str)
  449. subtitles = {}
  450. closed_captions_url = info.get('closed_captions_url')
  451. if closed_captions_url:
  452. subtitles['en'] = [{
  453. 'ext': 'ttml',
  454. 'url': closed_captions_url,
  455. }]
  456. # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
  457. # Try turning it to 'program - title' naming scheme if possible
  458. alt_title = info.get('program', {}).get('title')
  459. if alt_title:
  460. info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + '[\s\-:]+', '', info['title'])
  461. return {
  462. 'id': video_id,
  463. 'display_id': display_id,
  464. 'title': info['title'],
  465. 'description': info['program'].get('description'),
  466. 'thumbnail': info.get('image_url'),
  467. 'duration': int_or_none(info.get('duration')),
  468. 'age_limit': age_limit,
  469. 'upload_date': upload_date,
  470. 'formats': formats,
  471. 'subtitles': subtitles,
  472. }