Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream location changes #4

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
# add your own streams:
### method one (recommended):
1. direct your browser of choice to **maiden** (http://norns.local/maiden/ **or** yournornsip/maiden)
2. go to `/code/internet-radio/lib/` directory
3. edit `streams.lua` or make your own `filename.lua` list
2. go to the `/data/internet-radio/lib/` directory
> **DO NOT edit /code/internet-radio/lib/ files!** This folder only exists to easily package the default stream lists with the script. **_Changes made to it will prevent updating the script from Maiden_**
3. edit a list or create your own `filename.lua` list
4. follow the format:
`{name = "stream name", address = "streamurl"},`

Expand Down Expand Up @@ -89,13 +90,13 @@

# to-do:
- [ ] beta test phase (currently)
- [ ] figure out update [issue](https://github.com/tapecanvas/internet-radio/issues/3)
- [ ] pitch/speed param? https://mpv.io/manual/master/#audio-filters
- [ ] demo video
- [ ] add to [norns.community](https://github.com/monome-community/norns-community) when v1.0.0 is ready

---
## archive:
- [x] resolve update [issue](https://github.com/tapecanvas/internet-radio/issues/3)
- [x] add lines link to script header and readme
- [x] add BBC streams to /lib
- [x] rename and modify /lib/default.lua (make a template file) and update streams.lua
Expand Down
49 changes: 44 additions & 5 deletions internet-radio.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- internet-radio
-- v0.1.8 (beta) @tapecanvas
-- v0.1.9 (beta) @tapecanvas
-- inspired by:
-- @mlogger + @infinitedigits
-- with help from:
-- github-copilot
-- github-copilot + @eigen
-- llllllll.co/t/internet-radio/66152
--
-- internet radio player
Expand All @@ -27,12 +27,13 @@

local current_stream = nil
FileSelect = require 'fileselect'
local selected_file = "/home/we/dust/code/internet-radio/lib/streams.lua"
local selected_file = "/home/we/dust/data/internet-radio/streams/streams.lua" -- updated
local current_stream_index = 1
local top_stream_index = 1
local is_playing = false
local exit_option = "close"


-- initialize an empty stream array to load streams.lua into
local streams = {}

Expand Down Expand Up @@ -78,6 +79,44 @@ function save_streams()
file:close()
end

-- TESTING this block should move the contents of /code/internet-radio/lib to /data/internet-radio/streams if the included files are not already there
-- this allows the user to edit the streams.lua file without making changes to the /code/internet-radio directory - which currently prevents updating from maiden
-- inelegant but functional
--
-- function to check if a file exists
function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end

-- function to copy a file if it doesn't exist
function copy_stream_defaults(src, dst)
if not file_exists(dst) then
os.execute(string.format("cp -n %s %s", src, dst))
end
end

-- define the source and destination directories
local src_dir = "home/we/dust/code/internet-radio/lib/"
local dst_dir = "home/we/dust/data/internet-radio/streams/"

-- define file names to check for
local file_names = {"streams.lua", "template.lua", "bbc.lua"}

-- for each file, call the copy function to copy files from the src to the dst if they don't already exist there
for _, file_name in ipairs(file_names) do
local src = src_dir .. file_name
local dst = dst_dir .. file_name
copy_stream_defaults(src, dst)
end
--
-- end TESTING

-- scroll through stream list
function scroll_streams(direction)
current_stream_index = current_stream_index + direction
Expand Down Expand Up @@ -193,7 +232,7 @@ function load_state()
default_file:write(" current_stream_index = 1,\n")
default_file:write(" playing_stream_index = nil,\n")
default_file:write(" exit_option = 1,\n")
default_file:write(" selected_file = \"/home/we/dust/code/internet-radio/lib/streams.lua\",\n")
default_file:write(" selected_file = \"/home/we/dust/data/internet-radio/streams/streams.lua\",\n") -- updated
default_file:write("}\n")
default_file:close()
file = dofile(path)
Expand All @@ -202,7 +241,7 @@ function load_state()
current_stream_index = file.current_stream_index or 1
playing_stream_index = file.playing_stream_index
exit_option = file.exit_option == 1 and "close" or "leave open"
selected_file = file.selected_file or "/home/we/dust/code/internet-radio/lib/streams.lua"
selected_file = file.selected_file or "/home/we/dust/data/internet-radio/streams/streams.lua" -- updated
end
end

Expand Down