Skip to content

Commit

Permalink
Update musicify.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaKnijn authored Dec 31, 2020
1 parent e4e39f6 commit 5852f55
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions musicify.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local indexURL = "https://raw.githubusercontent.com/RubenHetKonijn/computronics-songs/main/index.json?cb=" .. os.epoch("utc")
local version = 0.03
local version = 0.04


if peripheral.find("tape_drive") == false then
Expand All @@ -11,6 +11,10 @@ local handle = http.get(indexURL)
local indexJSON = handle.readAll()
handle.close()
local index = textutils.unserialiseJSON(indexJSON)
if not index then
print("The index seems to be malformed, make an issue on github or dm RubenKnijn#0043 on Discord")
return
end
local args = {...}

local function wipe()
Expand All @@ -37,9 +41,10 @@ if #args <= 0 then
end
if args[1] == "help" then
print("Usage: <action> [action args]")
print(" help -- Displays this menu")
print(" list -- Displays a list of songs you can play")
print(" play <id> -- Plays the specified song")
print("musicify help -- Displays this menu")
print("musicify list -- Displays a list of songs you can play")
print("musicify play <id> -- Plays the specified song")
print("musicify stop -- Stops playback")
elseif args[1] == "stop" then
print("Stopping playback")
tape.stop()
Expand All @@ -49,6 +54,26 @@ elseif args[1] == "list" then
print(i .. " | " .. index.songs[i].author .. " - " .. index.songs[i].name)
end
elseif args[1] == "play" then
if args[2] == "shuffle" then
while true do
local ranNum = math.random(1,#index.songs)
print("Currently in shuffle mode, do <CTRL>+T to stop the shuffle")
print("Writing and playing " .. index.songs[ranNum].author .. " - " .. index.songs[ranNum].name)
wipe()
tape.stop()
tape.seek(-tape.getSize()) -- go back to the start

local h = http.get(index.songs[ranNum].file, nil, true) -- write in binary mode
tape.write(h.readAll()) -- that's it
h.close()

tape.seek(-tape.getSize()) -- back to start again

tape.setSpeed(index.songs[ranNum].speed)
tape.play()
sleep(index.songs[ranNum].time)
end
end
if tonumber(args[2]) <= 0 then
print("Please specify a song id, use the `list` action to see all music in a list")
return
Expand All @@ -72,4 +97,3 @@ elseif args[1] == "play" then
tape.setSpeed(index.songs[playID].speed)
tape.play()
end

0 comments on commit 5852f55

Please sign in to comment.