From 705df8f454787593b5a50d890275d5417735d658 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 10 Jan 2022 08:08:16 -0800 Subject: [PATCH] allow archiving --- broadcast0.sh | 2 +- broadcast1.sh | 2 +- broadcast2.sh | 2 +- lib/mod.lua | 31 +++++++++++++++++++++++++++---- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/broadcast0.sh b/broadcast0.sh index 1d36e24..3e8ce83 100755 --- a/broadcast0.sh +++ b/broadcast0.sh @@ -2,6 +2,6 @@ while : do - /home/we/dust/code/broadcast/broadcast1.sh "${1}" "${2}" + /home/we/dust/code/broadcast/broadcast1.sh "${1}" "${2}" "${3}" sleep 10 done diff --git a/broadcast1.sh b/broadcast1.sh index a9765c2..88c5fc9 100755 --- a/broadcast1.sh +++ b/broadcast1.sh @@ -28,5 +28,5 @@ if (( $(ps -ef | grep -v grep | grep radio.mp3 | wc -l) > 0 )) then echo "broadcaster running" > /dev/null else - nohup /home/we/dust/code/broadcast/broadcast2.sh "${1}" "${2}" & + nohup /home/we/dust/code/broadcast/broadcast2.sh "${1}" "${2}" "${3}" & fi diff --git a/broadcast2.sh b/broadcast2.sh index 4471449..faaf3a0 100755 --- a/broadcast2.sh +++ b/broadcast2.sh @@ -8,6 +8,6 @@ trap cleanup EXIT while : do pkill -f radio.mp3 -curl -s http://localhost:8000/radio.mp3 | curl -s -k -H "Transfer-Encoding: chunked" -X POST -T - "https://broadcast.norns.online/${1}.mp3?stream=true&advertise=${2}" +curl -s http://localhost:8000/radio.mp3 | curl -s -k -H "Transfer-Encoding: chunked" -X POST -T - "https://broadcast.norns.online/${1}.mp3?stream=true&advertise=${2}&archive=${3}" sleep 1 done diff --git a/lib/mod.lua b/lib/mod.lua index 037c378..1685dac 100644 --- a/lib/mod.lua +++ b/lib/mod.lua @@ -23,6 +23,7 @@ local state={ x=1, is_running=false, advertise="false", + archive="false", station="", } @@ -82,7 +83,7 @@ m.toggle_station=function(start) os.execute("pkill -9 icecast2") os.execute("pkill -9 darkice") if (state.is_running==false or start==true) and state.station~="" then - os.execute("nohup /home/we/dust/code/broadcast/broadcast0.sh "..state.station.." "..state.advertise.." &") + os.execute("nohup /home/we/dust/code/broadcast/broadcast0.sh "..state.station.." "..state.advertise.." "..state.archive.." &") state.is_running=true else state.is_running=false @@ -103,6 +104,14 @@ m.key=function(n,z) if state.is_running then m.toggle_station(true) end + elseif state.x==4 then + state.archive=state.archive=="false" and "true" or "false" + local f=io.open(_path.data.."broadcast/archive","w") + f:write(state.archive) + io.close(f) + if state.is_running then + m.toggle_station(true) + end elseif state.x==2 then -- change station textentry.enter(function(x) @@ -132,7 +141,7 @@ m.enc=function(n,d) elseif d<0 then d=-1 end - state.x=util.clamp(state.x+d,1,3) + state.x=util.clamp(state.x+d,1,4) mod.menu.redraw() end @@ -153,8 +162,11 @@ m.redraw=function() screen.move(64,52+yy) screen.text_center("edit station name") screen.level(state.x==3 and 15 or 5) - screen.move(64,62+yy) - screen.text_center("advertise: "..state.advertise) + screen.move(35,62+yy) + screen.text_center("advertise:"..state.advertise) + screen.level(state.x==4 and 15 or 5) + screen.move(36+64,62+yy) + screen.text_center("archive:"..state.archive) screen.update() end @@ -188,6 +200,17 @@ m.init=function() end end end + local fname=_path.data.."broadcast/archive" + if util.file_exists(fname) then + local f=assert(io.open(fname,"rb")) + if f~=nil then + local content=f:read("*all") + f:close() + if content~=nil then + state.archive=(content:gsub("^%s*(.-)%s*$","%1")) + end + end + end state.is_running=string.find(util.os_capture("ps aux | grep broadcast0 | grep -v grep"),"broadcast0") if state.is_running==nil then state.is_running=false