
Znalazłem w sieci skrypt który pobiera pliki z rapidshare.
Chciałbym go trochę zmodyfikować, tak żeby po każdym pobranym pliku restartował połączenie, czyli zmieniał ip ubudls lub inaczej.
Oto skrypt :
Kod: Zaznacz cały
#!/usr/bin/ruby
############################################################################
# #
# rsdl.rb [0.0.4] #
# #
# Copyright (C) 2009 by #
# Slavomir 'Moridin' Ugolik [slavomir.ugolik@gmail.com] #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
############################################################################
if $0 == __FILE__
require 'net/http'
# If you have dynamic ip you can uncomment CHANGEIP constant
# miniscript or define it by your self to avoid wait time.
# In that case be sure you have permision to do this -
# probably you must be ROOT.
#
# For dynamic ip by internet configuration:
# CHANGEIP = 'ifdown -a; ifup -a'
#
# If you use DSL by ubuDSL (in other case change peer name):
# CHANGEIP = 'killall -9 pppd ; pppd call ubudsl_pppoa'
DLMANAGER = 'wget'
$stdout.sync = true # for \r
unless ARGV[0]
puts "Usage: #{$0} file_list.txt"
exit 1
end
File.open(ARGV[0]).each do |url|
next if url.chomp.empty?
url.delete!(' ')
url.chomp!
url = "http://#{url}" unless url =~ /^http:\/\//
filename = /\d\/(.*)$/.match(url)[1]
url = "#{url}.html" unless url =~ /\.html$/
server = nil
puts "Trying to download #{filename}"
File.delete filename if File.exist? filename
Net::HTTP.get(URI.parse(url)).each do |line|
if line =~ /<form id="ff" action="(.*)" method="post">/
server = Regexp.last_match(1)
break
end
end
unless server
puts "File not found!"
next
end
stiltime = 0
waittime = 0
source = nil
Net::HTTP.post_form(URI.parse(server), {'dl.start' => 'Free'}).body.each do |line|
if line =~ /<form name="dlf" action="(.*)" method="post">/
source = Regexp.last_match(1)
end
if source and line =~ /var c=(.*)/
stiltime = Regexp.last_match(1).to_i
break
end
if line =~ /Your IP address .* is already downloading a file./
waittime = -1
break
end
if line =~ /Instant download access! Or try again in about (.*) minutes./
waittime = Regexp.last_match(1).to_i
break
end
end
if -1 == waittime
9.downto 0 do |time|
print "\rYou're already downloading some file! Trying again in #{time} seconds."
sleep 1 ;
end
puts
redo
elsif 0 < waittime
if defined? CHANGEIP
puts "You've reached the download limit! Trying to restart internet connection..." ;
`#{CHANGEIP}`
redo
else
waittime.downto 0 do |wtime|
9.downto 0 do |time|
print "\rYou've reached the download limit! Waiting #{wtime}.#{time} minutes..."
sleep 6
end
end
puts
redo
end
end
stiltime.downto 0 do |time|
print "\rYour download will start in #{time} seconds."
sleep 1
end
puts
`#{DLMANAGER} #{source}`
urls=''
File.open(ARGV[0], "r") { |file| file.gets ; urls = file.read }
File.open(ARGV[0], "w+") { |file| file.write urls }
end
end
