WebServerLink = "" -- without the https:// -------------------------------------------------- local byte_A = string.byte("A") local byte_Z = string.byte("Z") local byte_a = string.byte("a") local byte_z = string.byte("z") local byte_0 = string.byte("0") local byte_9 = string.byte("9") local byte_62 = string.byte("+") local byte_63 = string.byte("/") function base64_decode(str, byteCallback) local stringLength = string.len(str) local bits = 0 local bitCount = 0 -- For each byte in string for i = 1,stringLength do local strByte = string.byte(str, i) local b64Digit = -1 -- Determine its digit value in base64 if (strByte == byte_62) then b64Digit = 62 elseif (strByte == byte_63) then b64Digit = 63 elseif (strByte >= byte_A and strByte <= byte_Z) then b64Digit = strByte - byte_A elseif (strByte >= byte_a and strByte <= byte_z) then b64Digit = strByte - byte_a + 26 elseif (strByte >= byte_0 and strByte <= byte_9) then b64Digit = strByte - byte_0 + 52 end -- If it's a valid digit, shift it onto the output if (b64Digit >= 0) then bits = bit32.lshift(bits, 6) bits = bit32.bor(bits, b64Digit) bitCount = bitCount + 6 -- If there are enough bits for a byte, shift it out if (bitCount >= 8) then bitCount = bitCount - 8 local byteVal = bit32.rshift(bits, bitCount) bits = bit32.band(bits, bit32.lshift(1, bitCount) - 1) byteCallback(byteVal) end end end end local tape = peripheral.find("tape_drive") if (not tape.isReady()) then error("No tape inserted") end -- HTTP API endpoint URL local url = "https://"..WebServerLink.."/download" -- HTTP request headers local headers = { ["Content-Type"] = "application/json" } shell.run("clear") write("Youtube ID: ") msg = read() -- HTTP request body local body = { youtubeLink = "https://www.youtube.com/watch?v="..msg } while true do -- Convert the request body to a string local requestBody = textutils.serializeJSON(body) -- Make an HTTP POST request local response = http.post(url, requestBody, headers) -- Check if the request was successful (HTTP status code 200) if response.getResponseCode() == 200 then -- Parse the response JSON local responseData = textutils.unserializeJSON(response.readAll()) -- Extract the base64 file data from the response local fileData = responseData.file local k = tape.getSize() tape.stop() tape.seek(-k) tape.stop() --Just making sure tape.seek(-90000) local s = string.rep("\xAA", 8192) for i = 1, k + 8191, 8192 do tape.write(s) end tape.seek(-k) tape.seek(-90000) print(data) local ctr = 0 local byteCount = 0 base64_decode(fileData, function(byteVal) tape.write(byteVal) ctr = ctr + 1 if (ctr >= 65536) then byteCount = byteCount + 65536 ctr = 0 sleep(0.01) print("Written ", byteCount, " bytes") end end) tape.stop() tape.seek(-tape.getSize()) tape.setSpeed(2) tape.play() break end end