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.

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