#!/usr/bin/ruby # # This script is for validate links from rapidshare # Copyright (C) 2010 Jakub Jankiewicz (jcubic@onet.pl) # # 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 3 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . require 'net/http' require 'net/https' require 'uri' require 'optparse' class FalseException < Exception end class Net::HTTP alias_method :old_initialize, :initialize def initialize(*args) old_initialize(*args) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE end end def check(file, quiet=nil) file.each_line {|url| begin url = url.strip #skip blank lines, comments and invalid urls if url =~ /^\s*$/ or url =~ /^\s*#/ or not url =~ /^http:\/\// or not url =~ /files\/([0-9]*)\/(.*)/ next else fileid = $1 filename = $2 query = "?sub=download&fileid=#{fileid}&filename=#{filename}" apiurl = URI.parse('https://api.rapidshare.com/cgi-bin/rsapi.cgi') http = Net::HTTP.new(apiurl.host, 443) http.use_ssl = true page = http.get(apiurl.path + query).body #puts page if page =~ /File deleted/ or page =~ /This file is marked as illegal/ or page =~ /Filename invalid./ or page =~ /File not found/ or page =~ /File ID invalid/ or page =~ /This file is too big/ if quiet raise FalseException end if RUBY_PLATFORM =~ /(:?mswin|mingw)/i puts "#{url} [FAIL]" else #display red FAIL on n*ix system system("echo \"#{url} [\x1b[31m\x1b[1m\"FAIL\"\x1b[0m]\"") end else if quiet == nil if RUBY_PLATFORM =~ /(:?mswin|mingw)/i puts "#{url} [OK]" else #display green OK on *nix system system("echo \"#{url} [\x1b[32m\x1b[1m\"OK\"\x1b[0m]\"") end end end end rescue Timeout::Error, Errno::ETIMEDOUT puts "Timeout Error, try again" redo end } end def usage() puts "rapidtest.rb [-f (filename | - )] [-q] [-h]" end opts = ARGV.getopts('f:hqp') if opts['h'] usage exit(0) end filename = opts['f'] if filename begin if filename == '-' check(ARGF) else File.open(filename) {|file| check(file, opts['q']) } end rescue Interrupt, Errno::EINTR exit(1) rescue FalseException exit(1) end end exit(0)