Script in Ruby for validating rapidshare links

This is script which I wrote for testing if file exist on rapidshare hosting service, it use Rapidshare API

require 'net/http'
require 'uri'
require 'optparse'

class FalseException < Exception
end


def check(file, quiet=nil)
  file.each_line {|url|
    begin
      url = url.stript
      #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_v1&fileid=#{fileid}&filename=#{filename}"
        apiurl = URI.parse('http://api.rapidshare.com/cgi-bin/rsapi.cgi')
        page = Net::HTTP.new(apiurl.host).get(apiurl.path + query).body
        if page =~ /File deleted/ or 
           page =~ /This file is marked as illegal/ or
           page =~ /Filename invalid./ or
           page =~ /File not found/
          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 | - )] [-h]"
end

opts = ARGV.getopts('f:hq')

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)

It will display url and [FAIL] or [OK] (on unix like system it display in color), or return true or false when used with -q option.

You can use it with -f option which must be filename with urls or – to read from stdin

If you using linux you can use xclip program to get data from clipboard.

If you have some urls in clipboard you can use:

xclip -o -sel clip | rapidtest.rb -f -

You can download it from here.

you can test if all files are valid with:

xclip -o -sel clip | rapidtest -f- && echo 'all fine' || echo 'some are invalid'

You can put this script in panel and display GUI message dialogs with zenity

function ok() {
  zenity --info --title "rapidtest" --text "all links are valid"
}
function error() {
  zenity --error --title "rapidtest" --text "some links are invalid"
}
xclip -o -sel clip | rapidtest.rb -q -f- && ok || eror

,

Leave a comment

I just got 666 reputation on stackoverflow.

666 reputation on stackoverflow

Leave a comment

Great T-Shirt Design.

This is the best T-Shirt design ever.

.ninja { color: black; visibility: hidden; }

, ,

1 Comment

Ściąganie plików z wrzuty

Aby ściągnąć pliki z wrzuty w Ruby, należy ze strony danego adresu odczytać zmienne javascript-u które zostaną przekazane do odtwarzacza napisanego we flashu.

require 'net/http'
require 'uri'
require 'rexml/document'

def get(url)
  url = URI.parse(url)
  http = Net::HTTP.new(url.host)
  return http.get(url.path).body
end

page = get(url)
#zczytanie zmiennych javascript
if page =~ /'key' : '([^']*)',/
  key = $1
else
  key = '4KWNcfGaCak'
end
if page =~ /'login' : '([^']*)',/
  login = $1
else
  login = 'lifthrasil'
end
if page =~ /'host' : '([^']*)',/
  host = $1
else
  host = 'labs.wrzuta.pl'
end
if page =~ /'site' : '([^']*)',/
  site = $1
else
  site = 'wrzuta.pl'
end
if page =~ /'lang' : '([^']*)',/
  lang = $1
end

Następnie z podanych zmiennych należy utworzyć adres url

rnd = (rand*1000000).floor
url = "http://#{login}.#{host}/xml/#{_local2}/#{key}/sa/#{site}/#{rnd}"

Pobrać daną stronę (jest to plik XML) i wczytać adres pliku

xml = REXML::Document.new(get(url)).root
url = xml.elements['//file/storeIds/fileId'][0]
#pobranie nazwy pliku
filename = xml.elements['//name'][0]

Następnie można użyć programu wget do ściągnięcia pliku

`wget -O #{filename} "#{url}"`

Możesz także skorzystać z Downloadera mój projekt na github, który ściąga pliki z przekleja, rapidshare, 4shared i wrzuty. Jak o używać możesz przeczytać w poście: File hosting downloader project (po angielsku) oraz skrypty do wszukiwania i walidacji linków z rapidshare.

, , ,

Leave a comment

Abelson & Sussman video lectures mirror download

Structure and Interpretation of Computer ProgramsIf you have trouble find all Abelson & Sussman SICP video lectures from MIT, here are direct downloads from archive.org (mp4 256kb).

http://ia361309.us.archive.org/3/items/halmit1a/Lecture-1a_256kb.mp4
http://ia361301.us.archive.org/22/items/halmit1b/Lecture-1b_256kb.mp4
http://ia361301.us.archive.org/19/items/halmit2a/Lecture-2a_256kb.mp4
http://ia361301.us.archive.org/18/items/halmit2b/Lecture-2b_256kb.mp4
http://ia361301.us.archive.org/20/items/halmit3a/Lecture-3a_256kb.mp4
http://ia361301.us.archive.org/17/items/halmit3b/Lecture-3b_256kb.mp4
http://ia361301.us.archive.org/11/items/halmit4a/Lecture-4a_256kb.mp4
http://ia361300.us.archive.org/3/items/halmit4b/Lecture-4b_256kb.mp4
http://ia361300.us.archive.org/11/items/halmit5a/Lecture-5a_256kb.mp4
http://ia361301.us.archive.org/8/items/halmit5b/Lecture-5b_256kb.mp4
http://ia361300.us.archive.org/4/items/halmit6a/Lecture-6a_256kb.mp4
http://ia361301.us.archive.org/7/items/halmit6b/Lecture-6b_256kb.mp4
http://ia361301.us.archive.org/10/items/halmit7a/Lecture-7a_256kb.mp4
http://ia361300.us.archive.org/12/items/halmit7b/Lecture-7b_256kb.mp4
http://ia361308.us.archive.org/3/items/halmit8a/Lecture-8a_256kb.mp4
http://ia361301.us.archive.org/14/items/halmit8b/Lecture-8b_256kb.mp4
http://ia361300.us.archive.org/4/items/halmit9a/Lecture-9a_256kb.mp4
http://ia361300.us.archive.org/16/items/halmit9b/Lecture-9b_256kb.mp4
http://ia361300.us.archive.org/6/items/halmit10a/Lecture-10a_256kb.mp4
http://ia361300.us.archive.org/15/items/halmit10b/Lecture-10b_256kb.mp4

,

2 Comments

Get you livebox router IP Adres

Here is bash on alias for get IP adress of your livebox router. (tested on Ubuntu GNU/Linux)

alias livebox-ip='tmp=`mktemp`;curl -u admin:<your password> --silent --url http://192.168.1.1/internetservices.html -o $tmp; grep -E "var v_Adrs_IP[^=]*=" $tmp | cut -d"\"" -f2 ; rm $tmp'

You must have installed curl. Note that you must change your livebox password.

, ,

Leave a comment

Program do ściągania plików z przeklej.pl

Poniżej podaje skrypt w ruby do ściągania plików z przekleja


#!/usr/bin/ruby
require "net/http"
require "uri"
require "getoptlong"

class FileToBigException < Exception
end

class FileDeletedException < Exception
end

class LinkErrorException < Exception
end

def file(name)
  File.open(name) {|file|
    return file.read()
  }
end

def host(url)
  url =~ /http:\/\/([^\/]*)\//
  return $1
end

def trail_slash(url)
  if url =~ /http:\/\/[^\/]*$/
    url += '/'
  end
  return url
end

class GetOpt
  def initialize(*options)
    opts = GetoptLong.new(*options)
    @opts = {}
    opts.each{|opt,arg|
      @opts[opt] = arg
    }
  end
  def [](key)
    return @opts[key]
  end
end

def get(url, cookies=nil, referer=nil)
  url = URI.parse(trail_slash(url))
  http = Net::HTTP.new(url.host)
  headers = {}
  if cookies
    headers['Cookie'] = cookies
  end
  if referer
    headers['Referer'] = referer
  end
  res = http.get(url.path, headers)
  return res.body
end

def wget(url, limit=false, filename=nil, referer=nil, cookies=nil)
  params = '-c -U Mozilla --keep-session-cookies' 
  if limit
    params += " --limit-rate=#{limit}" 
  end
  if filename
    params += " -O \"#{filename}\""
  end
  if cookies
    params += " --load-cookies=\"#{cookies}\""
  end
  if referer
    params += " --referer=\"#{referer}\""
  end
  `wget #{params} "#{url}"`
end

def przeklej_login_cookies(user, passwd)
  url = URI.parse('http://www.przeklej.pl/loguj')
  data = {
    'login[login]'=> user,
    'login[pass]' => passwd}
  res = Net::HTTP.post_form(url, data)
  return res.response['set-cookie']
end

def przeklej_logout()
  url = 'http://przeklej.pl/wyloguj'
  return get(url)
end

def fix_filename(filename)
  filename = filename.gsub(/ +/, ' ')
  filename = filename.gsub(' .', '.')
  filename = title(filename)
  return filename
end

def download(url, limit=false, user=nil, passwd=nil)
  referer = url
  if user and passwd
    cookies = przeklej_login_cookies(user, passwd)
    cookies_filename = 'download_przeklej_cookies.txt'
    File.open(cookies_filename, 'w') {|file|
      file.puts cookies
    }
    page = get(url, cookies)
  else
    cookies_filename = nil
    page = get(url)
  end
  if page =~ /Plik zosta/
    raise FileDeletedException
  end
  #if not loged
  if not page =~ /Wyloguj/
    loged = false
    if page =~ /pny <strong>abonament<\/strong>/
      raise FileToBigException
    end
  else
    loged = true
  end
  if page =~ /<p class="download-popup-abonament-button-box">[^<]*<a href="([^"]*)">/
    uri = $1
  elsif page =~ /<a class="download" href="([^"]*)"/
    uri = $1
  end
  if page =~ /B..dny parametr w linku/
    raise LinkErrorException
  end
  if page =~ /title="Pobierz plik">([^<]*)/
    filename = fix_filename($1)
    if loged
      #send request (simulate XHR)
      page =~ /var myhref = "([^"]*)"/
      check = get("http://www.przeklej.pl#{$1}#{(rand*1000).floor}", cookies, url)
      if check =~ /"return_code":1/
        raise TransferLimitException
      end
      res = response("http://www.przeklej.pl#{uri}", cookies, url)
      if not res['Location'] =~ /http:\/\//
        url = "http://www.przeklej.pl#{res['Location']}"
      else
        url = res['Location']
      end
      wget(url, limit, filename, referer)
    else
      wget("http://www.przeklej.pl#{uri}", limit, filename, referer)
    end
  end
  if user and passwd
    przeklej_logout
  end
end

opts = GetOpt.new(
                  ["--limit-rate", "-r", GetoptLong::REQUIRED_ARGUMENT],
                  ["--user", "-u", GetoptLong::REQUIRED_ARGUMENT],
                  ["--help", "-h", GetoptLong::NO_ARGUMENT],
                  ["--passwd", "-p", GetoptLong::REQUIRED_ARGUMENT])


limit = opts['--limit-rate']
user = opts['--user']
passwd = opts['--passwd']

if ARGV.length != 0 and host(ARGV[0]) == 'www.przeklej.pl'
  begin
    przeklej(url, limit)
  rescue FileToBigException
    if user and passwd
      begin
        przeklej(url, limit, user, passwd)
      rescue TransferLimitException
        puts "You can't download that file (buy more transfer)"
      end
    else
      puts "File Too Big"
    end
  rescue FileDeleted
    puts "File Deleted"
  rescue LinkError  rescue FileToBigException
    if user and passwd
      begin
        przeklej(url, limit, user, passwd)
      rescue TransferLimitException
        puts "You can't download that file (buy more transfer)"
      end
    else
      puts "File Too Big"
    end
  rescue FileDeletedException
    puts "File Deleted"
  rescue LinkErrorException
    puts "Link Error"
  end
end

Można go użyć tak:

download.rb <adres url>
download.rb -f <plik z adresami>

Jeśli mamy konto na przekleju to możemy użyć hasła i nazwy użytkownika do pobierani plików większych niż 50MB

download.rb -u <urzytkownik> -p <hasło> -f <plik z adresami>

Możesz także zwolnić zciąganie plików:

download.rb -r 128k <adres>

Aby użyć tego skryptu musisz mieć zainstalowany program wet. Skrypt możesz pobrać stąd.

,

Leave a comment

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: