Advertisement
justync7

shuffle

May 15th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. local url = "http://www.lozengia.com/tmas/Downloads/Minecraft/firebox/cctunes.com/"
  2. local list = "returnsong.php"
  3. local download = "download.php"
  4. local music = "Music/"
  5. local insterment = "Insterment/"
  6. local instrument = "Instrument/"
  7.  
  8. function downloadSong(name)
  9.   local music_response = http.get(url..music..name)
  10.     local instrument_response = http.get(url..insterment..name)
  11.   if music_response then
  12.     local resp = music_response.readAll()
  13.     music_response.close()
  14.     fi = shell.resolve(music..name)
  15.     local file = fs.open(fi, "w")
  16.     file.write(resp)
  17.     file.close()
  18.   end
  19.  
  20.   if instrument_response then
  21.     local resp = instrument_response.readAll()
  22.     instrument_response.close()
  23.     fi = shell.resolve(instrument..name)
  24.     local file = fs.open(fi, "w")
  25.     file.write(resp)
  26.     file.close()
  27.   end
  28.  
  29.   if music_response then
  30.     return true
  31.   else
  32.     return false
  33.   end
  34. end
  35.  
  36. function getList()
  37.   local response = http.get(url..list)
  38.   if response then
  39.     return textutils.unserialize(response.readAll():gsub("\\'",""))
  40.   else
  41.     return false
  42.   end
  43. end
  44.  
  45. function isGood(item)
  46.   if item then
  47.     if item.title then
  48.       if item.title ~= "Unknown" and item.title ~= "Untitled" and item.originalauthor ~= "Daniel Ingram" and item.title ~= "" then
  49.         return true
  50.       else
  51.         return false
  52.       end
  53.     else
  54.       return false
  55.     end
  56.   else
  57.     return false
  58.   end
  59. end
  60.  
  61. function count(list)
  62.   local c = 0
  63.   for i,v in pairs(list) do
  64.     c = c + 1
  65.   end
  66.   return c
  67. end
  68.  
  69. local list = getList()
  70. local count = #list
  71. local cleanlist = {}
  72. if not list then
  73.   error("Failed to download the song list!")
  74. end
  75. print("Got "..#list.." songs from list")
  76. local dudcount = 0
  77. for i=1,count do
  78.   if not isGood(list[i]) then
  79.     dudcount = dudcount + 1
  80.     list[i] = nil
  81.   else
  82.     table.insert(cleanlist, list[i])
  83.   end
  84. end
  85. print("Removed "..dudcount.." duds.")
  86. print("Found "..#cleanlist.." good songs")
  87. while true do
  88.   if fs.exists("Music") then
  89.     fs.delete("Music")
  90.   end
  91.   if fs.exists("Instrument") then
  92.     fs.delete("Instrument")
  93.   end
  94.   fs.makeDir("Music")
  95.   fs.makeDir("Instrument")
  96.   local randsong = cleanlist[math.random(1,#cleanlist)]
  97.   downloadSong(randsong.file)
  98.   local fi = fs.open("playlist","w")
  99.   fi.write(randsong.file)
  100.   fi.close()
  101.   shell.run("musicplayer")
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement