Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fl = require("filesystem")
- local component = require("component")
- local term = require("term")
- local tape = component.tape_drive
- local a={}
- local list = {}
- local vr='0'
- print(fl.remove('/home/index.html')) os.execute('/bin/wget.lua https://www.dropbox.com/sh/2ki7ijnha2b24t7/AACjJL9V-UFa6giHOjjzf7U1a?dl=0 /home/index.html')
- local file = io.open('/home/index.html', 'r')
- local function write(path)
- local file, msg, _, y
- local block = 2048 --How much to read at a time
- tape.stop()
- tape.seek(-tape.getSize())
- tape.stop() --Just making sure
- local bytery = 0 --For the progress indicator
- local filesize = tape.getSize()
- if string.match(path, "https?://.+") then
- if not component.isAvailable("internet") then
- io.stderr:write("This command requires an internet card to run.")
- return false
- end
- local internet = component.internet
- local function setupConnection(url)
- local file, reason = internet.request(url)
- if not file then
- io.stderr:write("error requesting data from URL: " .. reason .. "\n")
- return false
- end
- local connected, reason = false, ""
- local timeout = 50
- for i = 1, timeout do
- connected, reason = file.finishConnect()
- os.sleep(.1)
- if connected or connected == nil then
- break
- end
- end
- if connected == nil then
- io.stderr:write("Could not connect to server: " .. reason)
- return false
- end
- local status, message, header = file.response()
- if status then
- status = string.format("%d", status)
- if status:sub(1,1) == "2" then
- return true, {
- close = function(self, ...) return file.close(...) end,
- read = function(self, ...) return file.read(...) end,
- }, header
- end
- return false
- end
- io.stderr:write("no valid HTTP response - no response")
- return false
- end
- local success, header
- success, file, header = setupConnection(path)
- if not success then
- if file then
- file:close()
- end
- return
- end
- print("Writing...")
- _, y = term.getCursor()
- if header and header["Content-Length"] and header["Content-Length"][1] then
- filesize = tonumber(header["Content-Length"][1])
- end
- else
- local path = shell.resolve(path)
- filesize = fs.size(path)
- file, msg = io.open(path, "rb")
- if not file then
- io.stderr:write("Error: " .. msg)
- return
- end
- print("Writing...")
- _, y = term.getCursor()
- end
- if filesize > tape.getSize() then
- term.setCursor(1, y)
- io.stderr:write("Warning: File is too large for tape, shortening file\n")
- _, y = term.getCursor()
- filesize = tape.getSize()
- end
- --Displays long numbers with commas
- local function fancyNumber(n)
- return tostring(math.floor(n)):reverse():gsub("(%d%d%d)", "%1,"):gsub("%D$", ""):reverse()
- end
- repeat
- local bytes = file:read(block)
- if bytes and #bytes > 0 then
- if not tape.isReady() then
- io.stderr:write("\nError: Tape was removed during writing.\n")
- file:close()
- return
- end
- term.setCursor(1, y)
- bytery = bytery + #bytes
- local displaySize = math.min(bytery, filesize)
- term.write(string.format("Write %s of %s bytes... (%.2f %%)", fancyNumber(displaySize), fancyNumber(filesize), 100 * displaySize / filesize))
- tape.write(bytes)
- end
- until not bytes or bytery > filesize
- file:close()
- tape.stop()
- tape.seek(-tape.getSize())
- tape.stop() --Just making sure
- print("\nDone.")
- end
- local function analuze()
- while #a~=0 do
- if string.find(a[1],'href')==nil then
- table.remove(a,1)
- else
- b = string.sub(a[1],string.find(a[1],'href'),string.len(a[1]))
- for i=2,#a do
- b=b..a[i]
- a[i]=''
- end
- a={}
- break
- end
- end
- end
- local function analuze2()
- while #b~=0 do
- if string.find(b,'href')~=nil then
- b = string.sub(b,string.find(b,'href')+8,string.len(b))
- list[#list+1]= string.sub(b,1,string.find(b,'"')-1)
- b = string.sub(b, string.find(b,'"'), string.len(b))
- else
- break
- end
- end
- end
- while vr~='' do
- vr = file:read(100)
- if string.find(vr,'InitReact')~=nil then break end
- end
- while vr~='' do
- vr = file:read(100)
- if string.find(vr,'\n')~=nil then break end
- a[#a+1] = vr
- end
- file:close()
- analuze()
- analuze2()
- print('найдено '..#list..' песен')
- print('введите любой номер песни')
- n = tonumber(io.read())
- print(list[n])
- tape.seek(-tape.getSize())
- write((list[n]):gsub("www%.dropbox%.com","dl.dropboxusercontent.com"):gsub("%?dl=%d$", ""))
- tape.setSpeed(2)
- tape.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement