Strona 1 z 1

[RUBY]Modyfikacja skryptu Rapidshare

: 14 kwie 2009, 14:35
autor: Radeko
Witam :)

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
Z góry dziękuję i pozdrawiam :).

Odp: [RUBY]Modyfikacja skryptu Rapidshare

: 14 kwie 2009, 15:55
autor: kiler88
Widzę że chyba nie wiele mówi Ci ten fragment z początku skryptu ;)
# 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'
Wg autora tego skryptu wystarczy usunąć znak "#" w ostatniej zacytowanej przeze mnie linii, ale nie mam jak przetestować działania, więc nie gwarantuje zadziałania.

Odp: [RUBY]Modyfikacja skryptu Rapidshare

: 14 kwie 2009, 16:32
autor: Radeko
Mój błąd, z góry zignorowałem komentarze, jak kompilator :P, ale ok.
[SOLVED]

Odp: [RUBY]Modyfikacja skryptu Rapidshare

: 15 lip 2009, 00:14
autor: kafffka
Gdy uruchamiam skrypt, pokazuje mi się "Usage: ./rapidshare.rb file_list.txt". Plik z adresami rapidsahre nazywa się file_list.txt. No i nie wiem co dalej, ani co zrobiłem źle. Plik file_list.txt jest w tym samym katalogu co skrypt. Nie wiem w czym rzecz, proszę o pomoc.

Odp: [RUBY]Modyfikacja skryptu Rapidshare

: 15 lip 2009, 17:31
autor: amorfic
piszesz

Kod: Zaznacz cały

./rapidshare.rb file_list.txt
jeżeli tak nazywa sie twój plik z adresami, ale możesz go nazwać inaczej np. kolargol
to wtedy

Kod: Zaznacz cały

./rapidshare.rb kolargol
i jeszcze jedno - do zmiany ip uzywane jest

Kod: Zaznacz cały

killall -9 pppd

Powinno być

Kod: Zaznacz cały

sudo killall -9 pppd
a w pliku etc/sudoers możesz wyłączyć pytanie o hasło dopisują nakońcu pliku:

%admin ALL=NOPASSWD: /usr/bin/killall

Odp: [RUBY]Modyfikacja skryptu Rapidshare

: 15 lip 2009, 19:26
autor: kafffka
dzięki... :clap: