Advertisement
Kitomas

Tape Downloader

Feb 13th, 2021
1,249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. --this program takes an argument in the form of a url to download to a tape
  2. --2nd arg specifies where in the tape to start writing at
  3. args={...}--{'https://kitomas.neocities.org/YMO-Tong_Poo6.txt'}
  4. local tape=peripheral.find("tape_drive")
  5. local multi=' '
  6. local inc=6000
  7. term.clear()
  8. term.setCursorPos(1,1)
  9. if #args > 0 then
  10.     if tape then
  11.         if tape.isReady() then
  12.             print("Verifying URL...")
  13.             local ok, err = http.checkURLAsync(args[1])
  14.             if ok then
  15.                 print("Fetching URL contents... (This may take a while)")
  16.                 local request, err = http.get(args[1],nil,true)
  17.                 if request then
  18.                     print("Preparing Tape Drive...")
  19.                     os.sleep(.2) --so that you can see the text before the screen clears
  20.                     local counter,yield=0,0
  21.                     local size=tape.getSize()
  22.                     tape.stop()
  23.                     tape.seek(-size-9999)
  24.                     if tonumber(args[2]) ~= nil then tape.seek(tonumber(args[2])) end
  25.                     while counter < size and multi ~= nil do
  26.                         term.setCursorPos(1,3)
  27.                         term.write("Writing: "..counter.."/"..size.."                        ")
  28.                         multi=request.read(inc)
  29.                         if multi ~= nil then
  30.                             tape.write(multi)
  31.                             counter=counter+multi:len()
  32.                         end
  33.                         yield=yield+1
  34.                         if yield > 60 then
  35.                             os.sleep(.05)
  36.                             yield=0
  37.                         end
  38.                     end
  39.                     tape.seek(-size-9999)
  40.                     term.setCursorPos(1,3)
  41.                     term.write("Writing: "..counter.."/"..size.."                            ")
  42.                     print("-DONE-")
  43.                     request.close()
  44.                 else
  45.                     printError(err)
  46.                 end
  47.             else
  48.                 printError(err)
  49.             end
  50.         else
  51.             printError("Place a tape into the Tape Drive's tray plz")
  52.         end
  53.     else
  54.         printError("Attatch a Tape Drive to this computer plz")
  55.     end
  56. else
  57.     printError("Plz add a direct file URL as an argument")
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement