/
dl-script
39 lines (31 loc) · 905 Bytes
/
dl-script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Description: Download script
-- Authors: andersevenrud, larsmaehlum
-- URL: https://github.com/andersevenrud/TekkitScripts
local _argv = {...}
if #_argv > 1 then
local url = _argv[1]
local file = _argv[2]
if string.match(url, "pastebin://") then
local i1, i2 = string.find(url, "pastebin://", nil, true)
url = string.format("http://pastebin.com/raw.php?i=%s", string.sub(url, "", i2 + 1))
end
local h = http.get(url)
if h then
print("Downloading ", url)
local f = fs.open(file, "w")
if f then
print("Writing ", file)
local s = h.readAll() or "-- DOWNLOAD FAILURE"
f.write(s)
f.close()
print("DONE! :-)")
end
h.close()
return (true)
end
else
print("Usage:")
print("dl-script pastebin://<pastebin-id> <absolute-path>")
print("dl-script <url> <absolute-path> (https not supported)")
end
return (false)