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.

639 lines
33 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. float_or_none,
  10. js_to_json,
  11. orderedSet,
  12. strip_jsonp,
  13. strip_or_none,
  14. unified_strdate,
  15. US_RATINGS,
  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: %s' % ', '.join(list(zip(*_STATIONS))[1])
  181. _VALID_URL = r'''(?x)https?://
  182. (?:
  183. # Direct video URL
  184. (?:%s)/(?:(?: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. ''' % '|'.join(list(zip(*_STATIONS))[0])
  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/rg3/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/rg3/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://player.pbs.org/widget/partnerplayer/2365297708/?start=0&end=0&chapterbar=false&endscreen=false&topbar=true',
  357. 'only_matching': True,
  358. },
  359. {
  360. 'url': 'http://watch.knpb.org/video/2365616055/',
  361. 'only_matching': True,
  362. },
  363. {
  364. 'url': 'https://player.pbs.org/portalplayer/3004638221/?uid=',
  365. 'only_matching': True,
  366. }
  367. ]
  368. _ERRORS = {
  369. 101: 'We\'re sorry, but this video is not yet available.',
  370. 403: 'We\'re sorry, but this video is not available in your region due to right restrictions.',
  371. 404: 'We are experiencing technical difficulties that are preventing us from playing the video at this time. Please check back again soon.',
  372. 410: 'This video has expired and is no longer available for online streaming.',
  373. }
  374. def _real_initialize(self):
  375. cookie = (self._download_json(
  376. 'http://localization.services.pbs.org/localize/auto/cookie/',
  377. None, headers=self.geo_verification_headers(), fatal=False) or {}).get('cookie')
  378. if cookie:
  379. station = self._search_regex(r'#?s=\["([^"]+)"', cookie, 'station')
  380. if station:
  381. self._set_cookie('.pbs.org', 'pbsol.station', station)
  382. def _extract_webpage(self, url):
  383. mobj = re.match(self._VALID_URL, url)
  384. description = None
  385. presumptive_id = mobj.group('presumptive_id')
  386. display_id = presumptive_id
  387. if presumptive_id:
  388. webpage = self._download_webpage(url, display_id)
  389. description = strip_or_none(self._og_search_description(
  390. webpage, default=None) or self._html_search_meta(
  391. 'description', webpage, default=None))
  392. upload_date = unified_strdate(self._search_regex(
  393. r'<input type="hidden" id="air_date_[0-9]+" value="([^"]+)"',
  394. webpage, 'upload date', default=None))
  395. # tabbed frontline videos
  396. MULTI_PART_REGEXES = (
  397. r'<div[^>]+class="videotab[^"]*"[^>]+vid="(\d+)"',
  398. r'<a[^>]+href=["\']#(?:video-|part)\d+["\'][^>]+data-cove[Ii]d=["\'](\d+)',
  399. )
  400. for p in MULTI_PART_REGEXES:
  401. tabbed_videos = orderedSet(re.findall(p, webpage))
  402. if tabbed_videos:
  403. return tabbed_videos, presumptive_id, upload_date, description
  404. MEDIA_ID_REGEXES = [
  405. r"div\s*:\s*'videoembed'\s*,\s*mediaid\s*:\s*'(\d+)'", # frontline video embed
  406. r'class="coveplayerid">([^<]+)<', # coveplayer
  407. r'<section[^>]+data-coveid="(\d+)"', # coveplayer from http://www.pbs.org/wgbh/frontline/film/real-csi/
  408. r'<input type="hidden" id="pbs_video_id_[0-9]+" value="([0-9]+)"/>', # jwplayer
  409. r"(?s)window\.PBS\.playerConfig\s*=\s*{.*?id\s*:\s*'([0-9]+)',",
  410. ]
  411. media_id = self._search_regex(
  412. MEDIA_ID_REGEXES, webpage, 'media ID', fatal=False, default=None)
  413. if media_id:
  414. return media_id, presumptive_id, upload_date, description
  415. # Fronline video embedded via flp
  416. video_id = self._search_regex(
  417. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid', default=None)
  418. if video_id:
  419. # pkg_id calculation is reverse engineered from
  420. # http://www.pbs.org/wgbh/pages/frontline/js/flp2012.js
  421. prg_id = self._search_regex(
  422. r'videoid\s*:\s*"([\d+a-z]{7,})"', webpage, 'videoid')[7:]
  423. if 'q' in prg_id:
  424. prg_id = prg_id.split('q')[1]
  425. prg_id = int(prg_id, 16)
  426. getdir = self._download_json(
  427. 'http://www.pbs.org/wgbh/pages/frontline/.json/getdir/getdir%d.json' % prg_id,
  428. presumptive_id, 'Downloading getdir JSON',
  429. transform_source=strip_jsonp)
  430. return getdir['mid'], presumptive_id, upload_date, description
  431. for iframe in re.findall(r'(?s)<iframe(.+?)></iframe>', webpage):
  432. url = self._search_regex(
  433. r'src=(["\'])(?P<url>.+?partnerplayer.+?)\1', iframe,
  434. 'player URL', default=None, group='url')
  435. if url:
  436. break
  437. if not url:
  438. url = self._og_search_url(webpage)
  439. mobj = re.match(self._VALID_URL, url)
  440. player_id = mobj.group('player_id')
  441. if not display_id:
  442. display_id = player_id
  443. if player_id:
  444. player_page = self._download_webpage(
  445. url, display_id, note='Downloading player page',
  446. errnote='Could not download player page')
  447. video_id = self._search_regex(
  448. r'<div\s+id="video_([0-9]+)"', player_page, 'video ID')
  449. else:
  450. video_id = mobj.group('id')
  451. display_id = video_id
  452. return video_id, display_id, None, description
  453. def _real_extract(self, url):
  454. video_id, display_id, upload_date, description = self._extract_webpage(url)
  455. if isinstance(video_id, list):
  456. entries = [self.url_result(
  457. 'http://video.pbs.org/video/%s' % vid_id, 'PBS', vid_id)
  458. for vid_id in video_id]
  459. return self.playlist_result(entries, display_id)
  460. info = None
  461. redirects = []
  462. redirect_urls = set()
  463. def extract_redirect_urls(info):
  464. for encoding_name in ('recommended_encoding', 'alternate_encoding'):
  465. redirect = info.get(encoding_name)
  466. if not redirect:
  467. continue
  468. redirect_url = redirect.get('url')
  469. if redirect_url and redirect_url not in redirect_urls:
  470. redirects.append(redirect)
  471. redirect_urls.add(redirect_url)
  472. chapters = []
  473. # Player pages may also serve different qualities
  474. for page in ('widget/partnerplayer', 'portalplayer'):
  475. player = self._download_webpage(
  476. 'http://player.pbs.org/%s/%s' % (page, video_id),
  477. display_id, 'Downloading %s page' % page, fatal=False)
  478. if player:
  479. video_info = self._parse_json(
  480. self._search_regex(
  481. r'(?s)PBS\.videoData\s*=\s*({.+?});\n',
  482. player, '%s video data' % page, default='{}'),
  483. display_id, transform_source=js_to_json, fatal=False)
  484. if video_info:
  485. extract_redirect_urls(video_info)
  486. if not info:
  487. info = video_info
  488. if not chapters:
  489. for chapter_data in re.findall(r'(?s)chapters\.push\(({.*?})\)', player):
  490. chapter = self._parse_json(chapter_data, video_id, js_to_json, fatal=False)
  491. if not chapter:
  492. continue
  493. start_time = float_or_none(chapter.get('start_time'), 1000)
  494. duration = float_or_none(chapter.get('duration'), 1000)
  495. if start_time is None or duration is None:
  496. continue
  497. chapters.append({
  498. 'start_time': start_time,
  499. 'end_time': start_time + duration,
  500. 'title': chapter.get('title'),
  501. })
  502. formats = []
  503. http_url = None
  504. for num, redirect in enumerate(redirects):
  505. redirect_id = redirect.get('eeid')
  506. redirect_info = self._download_json(
  507. '%s?format=json' % redirect['url'], display_id,
  508. 'Downloading %s video url info' % (redirect_id or num),
  509. headers=self.geo_verification_headers())
  510. if redirect_info['status'] == 'error':
  511. message = self._ERRORS.get(
  512. redirect_info['http_code'], redirect_info['message'])
  513. if redirect_info['http_code'] == 403:
  514. self.raise_geo_restricted(
  515. msg=message, countries=self._GEO_COUNTRIES)
  516. raise ExtractorError(
  517. '%s said: %s' % (self.IE_NAME, message), expected=True)
  518. format_url = redirect_info.get('url')
  519. if not format_url:
  520. continue
  521. if determine_ext(format_url) == 'm3u8':
  522. formats.extend(self._extract_m3u8_formats(
  523. format_url, display_id, 'mp4', m3u8_id='hls', fatal=False))
  524. else:
  525. formats.append({
  526. 'url': format_url,
  527. 'format_id': redirect_id,
  528. })
  529. if re.search(r'^https?://.*(?:\d+k|baseline)', format_url):
  530. http_url = format_url
  531. self._remove_duplicate_formats(formats)
  532. m3u8_formats = list(filter(
  533. lambda f: f.get('protocol') == 'm3u8' and f.get('vcodec') != 'none',
  534. formats))
  535. if http_url:
  536. for m3u8_format in m3u8_formats:
  537. bitrate = self._search_regex(r'(\d+)k', m3u8_format['url'], 'bitrate', default=None)
  538. # Lower qualities (150k and 192k) are not available as HTTP formats (see [1]),
  539. # we won't try extracting them.
  540. # Since summer 2016 higher quality formats (4500k and 6500k) are also available
  541. # albeit they are not documented in [2].
  542. # 1. https://github.com/rg3/youtube-dl/commit/cbc032c8b70a038a69259378c92b4ba97b42d491#commitcomment-17313656
  543. # 2. https://projects.pbs.org/confluence/display/coveapi/COVE+Video+Specifications
  544. if not bitrate or int(bitrate) < 400:
  545. continue
  546. f_url = re.sub(r'\d+k|baseline', bitrate + 'k', http_url)
  547. # This may produce invalid links sometimes (e.g.
  548. # http://www.pbs.org/wgbh/frontline/film/suicide-plan)
  549. if not self._is_valid_url(f_url, display_id, 'http-%sk video' % bitrate):
  550. continue
  551. f = m3u8_format.copy()
  552. f.update({
  553. 'url': f_url,
  554. 'format_id': m3u8_format['format_id'].replace('hls', 'http'),
  555. 'protocol': 'http',
  556. })
  557. formats.append(f)
  558. self._sort_formats(formats)
  559. rating_str = info.get('rating')
  560. if rating_str is not None:
  561. rating_str = rating_str.rpartition('-')[2]
  562. age_limit = US_RATINGS.get(rating_str)
  563. subtitles = {}
  564. closed_captions_url = info.get('closed_captions_url')
  565. if closed_captions_url:
  566. subtitles['en'] = [{
  567. 'ext': 'ttml',
  568. 'url': closed_captions_url,
  569. }]
  570. mobj = re.search(r'/(\d+)_Encoded\.dfxp', closed_captions_url)
  571. if mobj:
  572. ttml_caption_suffix, ttml_caption_id = mobj.group(0, 1)
  573. ttml_caption_id = int(ttml_caption_id)
  574. subtitles['en'].extend([{
  575. 'url': closed_captions_url.replace(
  576. ttml_caption_suffix, '/%d_Encoded.srt' % (ttml_caption_id + 1)),
  577. 'ext': 'srt',
  578. }, {
  579. 'url': closed_captions_url.replace(
  580. ttml_caption_suffix, '/%d_Encoded.vtt' % (ttml_caption_id + 2)),
  581. 'ext': 'vtt',
  582. }])
  583. # info['title'] is often incomplete (e.g. 'Full Episode', 'Episode 5', etc)
  584. # Try turning it to 'program - title' naming scheme if possible
  585. alt_title = info.get('program', {}).get('title')
  586. if alt_title:
  587. info['title'] = alt_title + ' - ' + re.sub(r'^' + alt_title + r'[\s\-:]+', '', info['title'])
  588. description = info.get('description') or info.get(
  589. 'program', {}).get('description') or description
  590. return {
  591. 'id': video_id,
  592. 'display_id': display_id,
  593. 'title': info['title'],
  594. 'description': description,
  595. 'thumbnail': info.get('image_url'),
  596. 'duration': int_or_none(info.get('duration')),
  597. 'age_limit': age_limit,
  598. 'upload_date': upload_date,
  599. 'formats': formats,
  600. 'subtitles': subtitles,
  601. 'chapters': chapters,
  602. }