Advertisement
Guest User

bc

a guest
May 29th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. local chan = "Luca radio"
  2.  
  3. local handle = http.get("http://localhost/cc/list.php")
  4. local songs = {}
  5. local line = ""
  6. while line ~= nil do
  7.   line = handle.readLine()
  8.   table.insert(songs,line)
  9. end
  10. handle.close()
  11.  
  12. os.loadAPI("note")
  13. local t = peripheral.find("bitnet_tower") -- looks for tower instead
  14. local function radioPlay()
  15.   while true do
  16.     for k,v in pairs(songs) do
  17.       print("Playing "..v)
  18.       local handle = http.get("http://localhost/cc/sound/" .. v:gsub(" ","%%20"))
  19.       local handle2 = fs.open(".temp", "w")
  20.       handle2.write(handle.readAll()) handle.close() handle2.close()
  21.       song = note.readNbs(".temp")
  22.       fs.delete(".temp")
  23.       if not song.name or song.name == "" then
  24.         song.name = v:sub(1,#v-4)
  25.       end
  26.       notes = song.notes
  27.       if notes == "" then
  28.         v:gsub("_"," ")
  29.       end
  30.       len = math.floor(song.length/song.tempo)
  31.       cur = 0
  32.       while cur <= song.length do
  33.         if notes[cur] then
  34.           sec = math.floor(cur/song.tempo)
  35.           tr = {tMessage={["notes"] = notes[cur], ["all"] = len, ["cur"] = sec,["name"]=song.name},sType="radio",sChannel=chan}
  36.           t.transmit(tr)
  37.         end
  38.         sleep(song.tempo/100)
  39.         cur = cur + 1
  40.       end
  41.     end
  42.   end
  43. end
  44.  
  45. local function skipSong()
  46.   while true do
  47.     local tEvent = {os.pullEvent()}
  48.     if tEvent[1] == "key" and tEvent[2] == keys.space then
  49.       song.length = 0 -- break loop
  50.       print("Skipping current song.")
  51.     end
  52.   end
  53. end
  54.  
  55. parallel.waitForAny(skipSong, radioPlay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement