Advertisement
machasins

redstonePlay

Feb 21st, 2023 (edited)
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.   redstonePlay
  3.   modification of
  4.   easyPlay
  5.   By Barnet
  6. --]] -- --
  7. local function getSongs(songPath)
  8.     local songs = {songPath}
  9.     local r = {}
  10.     for i, song in ipairs(songs) do
  11.         if fs.isDir(song) then
  12.             moreSongs = fs.list(song)
  13.             for j, s in ipairs(moreSongs) do
  14.                 table.insert(songs, song .. "/" .. s)
  15.             end
  16.             table.insert(r, i)
  17.         end
  18.     end
  19.  
  20.     for i = table.maxn(r), 1, -1 do table.remove(songs, r[i]) end
  21.  
  22.     return songs
  23. end
  24.  
  25. local function getName(song)
  26.     local i = string.find(song, "/[^/]*$")
  27.     if i ~= nil then
  28.         local songName = string.sub(song, i + 1, string.len(song))
  29.         songName = songName:gsub("^%l", string.upper)
  30.         i = string.find(songName, "%.")
  31.         if i ~= nil then songName = string.sub(songName, 1, i - 1) end
  32.         return songName
  33.     else
  34.         return song
  35.     end
  36. end
  37.  
  38. local function start(songPath, option)
  39.     local loop = option ~= nil and string.find(option, "l") ~= nil
  40.     local color = option ~= nil and string.find(option, "c") ~= nil
  41.  
  42.     if songPath == "" then error("No song path") end
  43.  
  44.     if string.sub(songPath, 1, 1) == '.' then
  45.         songPath = shell.dir() .. string.sub(songPath, 2)
  46.     end
  47.     local songs = getSongs(songPath)
  48.     local n = table.maxn(songs)
  49.  
  50.     repeat
  51.  
  52.         monitor = peripheral.find("monitor")
  53.         if monitor == nil then error("No monitor detected!") end
  54.         monitorName = peripheral.getName(monitor)
  55.  
  56.         local speakers = ""
  57.         local speakerCount = 0
  58.         for i, perName in ipairs(peripheral.getNames()) do
  59.             if string.find(perName, "speaker") then
  60.                 speakers = speakers .. perName .. " "
  61.                 speakerCount = speakerCount + 1
  62.             end
  63.         end
  64.  
  65.         if speakerCount == 0 then error("No speakers detected!") end
  66.  
  67.         for i, song in ipairs(songs) do
  68.             shell.run("EasyPlay/Core/playnbs.lua " .. tostring(color) .. " " ..
  69.                           getName(song) .. " " .. song .. " " .. monitorName ..
  70.                           " " .. speakers)
  71.         end
  72.     until not loop
  73. end
  74.  
  75. local function GetArg(a)
  76.     if a ~= nil then
  77.         return a
  78.     else
  79.         return ""
  80.     end
  81. end
  82.  
  83. local arg1 = GetArg(arg[1])
  84. local arg2 = GetArg(arg[2])
  85. local arg3 = GetArg(arg[3])
  86. local path = ""
  87. local option = ""
  88. if arg1 == "start" then
  89.     path = arg2
  90.     option = arg3
  91. else
  92.     path = arg1
  93.     option = arg2
  94. end
  95.  
  96. while true
  97. do
  98.     local e = os.pullEvent("redstone")
  99.     start(path, option)
  100. end
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement