Left4Cake2

ccTunes

Feb 18th, 2013
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.79 KB | None | 0 0
  1. local tArgs = { ... }
  2. server = "http://www.lozengia.com/tmas/Downloads/Minecraft/firebox/cctunes.com/"
  3.  
  4. -- UPLOAD MUSIC
  5.  
  6. -- SELECT SONG TO UPLOAD
  7. if tArgs[1] == "upload" and #tArgs < 2 then
  8.    shell.run("clear")
  9.    print( "Use the arrows and enter to chose.  " )
  10.    songlist = fs.list("Music")
  11.    i = 0
  12.    max = -1
  13.    while true do
  14.        i = i + 1
  15.        max = max + 1
  16.            if songlist[i] == nil then break end
  17.    end
  18.            pointer = 1
  19.            term.setCursorPos(1, 10)
  20.        term.clearLine(none)
  21.            print( "->" .. pointer .. ": " .. songlist[pointer])
  22.             while true do
  23.                  
  24.                      list = 1
  25.                      while list < 9 do
  26.                         term.setCursorPos(1, 10 - list)
  27.                         term.clearLine(none)
  28.                         if songlist[pointer - (list)] then
  29.                             write( "  " .. pointer - (list) .. ": " .. songlist[pointer - (list)])  
  30.                         end
  31.                         list = list + 1
  32.                      end                 
  33.                      term.setCursorPos(1, 10)
  34.                      term.clearLine(none)
  35.                      print( "->" .. pointer .. ": " .. songlist[pointer])
  36.              list = 1
  37.              while list < 10 do
  38.                         term.setCursorPos(1, 10 + list)
  39.                         term.clearLine(none)
  40.                         if songlist[pointer + (list)] then
  41.                             write( "  " .. pointer + (list) .. ": " .. songlist[pointer + (list)])  
  42.                         end
  43.                         list = list + 1
  44.                      end
  45.             local evt, arg1, arg2 = os.pullEvent()
  46.                      if arg1 == 28 then break end
  47.                      if arg1 == 200 and pointer > 1 then
  48.                              pointer = pointer - 1
  49.                      elseif arg1 == 208 and pointer < max then
  50.                              pointer = pointer + 1
  51.                      end
  52.                      
  53.             end
  54.        
  55. selectedsong = songlist[pointer]
  56. else
  57. selectedsong = tArgs[2]
  58. end
  59.  
  60. -- UPLOAD THE SONG
  61. if tArgs[1] == "upload" and selectedsong then
  62.     musicexists = fs.exists("Music/" .. selectedsong)
  63.     instermentexists = fs.exists("Instrument/" .. selectedsong)
  64.    
  65.     if musicexists then
  66.         file = io.open( "Music/" .. selectedsong )
  67.         fmusicdata = file:read()
  68.         file:close()
  69.         musicdata = textutils.unserialize(fmusicdata)
  70.         if musicdata["delay"] and musicdata["lenght"] and musicdata["original_author"] and musicdata["author"] and musicdata["name"] then
  71.             if musicdata["name"] == "Unknown" then
  72.                 songname = selectedsong
  73.             else
  74.                 songname = musicdata["name"]
  75.             end
  76.            
  77.             uploadque = "filename=" .. textutils.urlEncode(selectedsong) .. "&title=" .. textutils.urlEncode(musicdata["name"]) .. "&author=" .. textutils.urlEncode(musicdata["author"]) .. "&originalauthor=" .. textutils.urlEncode(musicdata["original_author"]) .. "&musicdata=" .. textutils.urlEncode(fmusicdata)
  78.             if instermentexists then
  79.                 file = io.open( "Instrument/" .. selectedsong )
  80.                 imusicdata = ""
  81.                 while true do
  82.                     filedata = file:read()
  83.                     if filedata then
  84.                         imusicdata = imusicdata .. '\n' .. filedata    
  85.                     else break end
  86.                 end
  87.                 file:close()
  88.                 uploadque = uploadque .. "&instermentdata=" .. textutils.urlEncode(imusicdata)
  89.             end
  90.            
  91.                 local response = http.post(server .. "upload.php", uploadque)
  92.                     if response then
  93.                     -- if page is reseved
  94.                        while response do
  95.                                local sResponse = response.readAll()
  96.                                response.close()
  97.                                shell.run( "clear" )
  98.                                cache = shell.resolve( "temp" )
  99.                                local file = fs.open( cache, "w" )
  100.                                file.write( sResponse )
  101.                                file.close()
  102.                                response = nil
  103.                                shell.run( "temp" )
  104.                        end
  105.                     else
  106.                     -- if page is not reseved
  107.                        print( "Error, Something went wrong with the HTTP request." )
  108.                         cache = shell.resolve( "temp" )
  109.                     local file = fs.open( cache, "w" )
  110.                     file.write( uploadque )
  111.                         file.close()
  112.                        
  113.                     end
  114.         end
  115.     end
  116.    
  117.  
  118. else
  119. -- Upload portion of code ends here
  120. -- Download songs
  121.     local response = http.get(server .. "list.php")
  122.         if response then
  123.         -- if page is reseved
  124.            while response do
  125.                    local sResponse = response.readAll()
  126.                    response.close()
  127.                    shell.run( "clear" )
  128.                    cache = shell.resolve( "temp" )
  129.                    local file = fs.open( cache, "w" )
  130.                    file.write( sResponse )
  131.                    file.close()
  132.                    response = nil
  133.                    shell.run( "temp" )
  134.            end
  135.  
  136.     end
  137. end
  138.  
  139. shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment