Skip to content

Instantly share code, notes, and snippets.

@invalidusrname
Forked from xpepper/download_rubytapas.rb
Last active April 3, 2019 15:08
Show Gist options
  • Save invalidusrname/7e671cc34e551d4ff3e7 to your computer and use it in GitHub Desktop.
Save invalidusrname/7e671cc34e551d4ff3e7 to your computer and use it in GitHub Desktop.
Old way of downloading rubytapas videos
username = ARGV[0]
pwd = ARGV[1]
target_path = ARGV[2]
unless ARGV.size == 3
puts "usage: ruby download_rubytapas.rb username password save_path"
exit(1)
end
target_path = File.expand_path(target_path)
raise "target path must exist" unless File.directory?(target_path)
# saving auth cookie
system %Q{wget --save-cookies /tmp/cookie.txt --keep-session-cookies --post-data "username=#{username}&password=#{pwd}" -O - \
https://rubytapas.dpdcart.com/subscriber/login?__dpd_cart=d08391e6-5fe2-4400-8b27-2dc17b413027}
(25..600).each do |i|
%x[wget -q -S --spider --load-cookies /tmp/cookie.txt https://rubytapas.dpdcart.com/subscriber/download?file_id=#{i} > spider.log 2>&1]
head_log = File.read("spider.log")
if head_log =~ /Content-Disposition.*filename="(.+)\.(.+)"/
name, extension = $1, $2
puts "Processing #{name}.#{extension}..."
if name && extension && !name.empty? && !extension.empty?
#if Dir.glob("#{target_path}/**/#{name}.#{extension}").size == 0
puts "Downloading #{name}.#{extension}..."
filename = "#{name}.#{extension}"
if filename =~ /.*(\d{3}).*/
target_folder = $1
target_fullpath = "#{target_path}/#{target_folder}"
unless File.directory?(target_fullpath)
Dir.mkdir target_fullpath
end
wget_cmd = "wget -c --load-cookies /tmp/cookie.txt --output-document='#{target_path}/#{target_folder}/#{name}.#{extension}' https://rubytapas.dpdcart.com/subscriber/download?file_id=#{i}"
puts "*** #{wget_cmd}"
system wget_cmd
end
#end
end
end
end
@invalidusrname
Copy link
Author

allows username, password, and save directory to be passed in as arguments.
resumes downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment