Last active
August 29, 2015 14:14
-
-
Save Konstantinusz/884db2047a9624aa4d98 to your computer and use it in GitHub Desktop.
Download and delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require "pty" | |
require "pry" | |
puts "usage: dad in.txt [password]" | |
passwd=ARGV[1] | |
STDOUT.sync=true | |
STDERR.sync=true | |
def download(akt_url) | |
if akt_url =~ /mega\.co\.nz/ then | |
ret=%x{megadl \'#{akt_url}\'} | |
fname=ret.split("\r\r\e").last.scan(/Downloaded (.*?)\n/).flatten[0] | |
else | |
%x{wget -c #{akt_url}} | |
fname=akt_url.split('/').last | |
end | |
return fname | |
end | |
l=open(ARGV[0],"r"){|f| f.readlines}.map{|z| z.chomp} | |
akt_url=l.shift | |
fname=download(akt_url) | |
cmd="rar x -ierr -vp #{passwd==nil ? "" : "-p#{passwd}"} \"#{fname}\" 2>&1|unbuffered -t '\r\n'" | |
a=Array.new(50) | |
PTY.spawn( cmd ) do |stdin, stdout, pid| | |
begin | |
stdin.each_line do |line| | |
binding.pry | |
(a.push line[0]).shift | |
out=a.join | |
print out | |
print 13.chr | |
if out =~ /\[Q\]uit$|Insert disk with/ then | |
%x{rm \"#{fname}\"} | |
akt_url=l.shift | |
puts akt_url | |
if akt_url != nil then | |
fname=download(akt_url) | |
end | |
stdout.puts "c" | |
#binding.pry | |
#raise(Errno::EIO) | |
elsif out =~ /\[Q\]uit $|Overwrite it/ then | |
stdout.puts "y" | |
end | |
end | |
rescue Errno::EIO | |
binding.pry | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment