Author: sparky
Date: Tue Jan  6 16:10:51 2009
New Revision: 10052

Modified:
   toys/fun/rsget.pl
Log:
- added odsiebie.com


Modified: toys/fun/rsget.pl
==============================================================================
--- toys/fun/rsget.pl   (original)
+++ toys/fun/rsget.pl   Tue Jan  6 16:10:51 2009
@@ -56,7 +56,7 @@
                $move = "\033[" . $steps . "B";
        }
        my $tl = length $text;
-       substr $text, 15, $tl - $columns + 18, '...'
+       substr $text, 15, $tl - $columns + 3, '...'
                if $tl > $columns;
        
        print $move . "\r\033[K" . $text;
@@ -157,8 +157,7 @@
 
        if ( $opts{cookies} ) {
                $curl->setopt( CURLOPT_COOKIEJAR, $opts{cookies} );
-               $curl->setopt( CURLOPT_COOKIEFILE, $opts{cookies} )
-                       if -r $opts{cookies};
+               $curl->setopt( CURLOPT_COOKIEFILE, $opts{cookies} );
        }
        $curl->setopt( CURLOPT_HEADERFUNCTION, \&body_scalar );
        $curl->setopt( CURLOPT_WRITEHEADER, \$ecurl->{head} );
@@ -169,6 +168,7 @@
        $curl->setopt( CURLOPT_REFERER, $opts{referer} )
                if $opts{referer};
        $curl->setopt( CURLOPT_ENCODING, 'gzip,deflate' );
+       $curl->setopt( CURLOPT_CONNECTTIMEOUT, 20 );
 
        if ( $opts{post} ) {
                my $post = $opts{post};
@@ -216,7 +216,9 @@
 
        if ( $obj->{curl_next} ) {
                my $func = $obj->{curl_next};
-               my $body = $ecurl->{file} ? "DONE" : $ecurl->{body};
+               my $body = $ecurl->{file}
+                       ? "DONE $ecurl->{file_name} $ecurl->{size_got} / 
$ecurl->{size_total}"
+                       : $ecurl->{body};
                my $eurl = $curl->getinfo( CURLINFO_EFFECTIVE_URL );
                
                &$func( $obj, $body, $eurl );
@@ -271,10 +273,13 @@
        my $size_total = $ecurl->{size_total};
 
        my $time_diff = time() - $ecurl->{time_start};
+       $time_diff = 1 unless $time_diff;
        my $eta = main::s2string( $time_diff );
        my $speed = sprintf "%.2f", $size_total / ( $time_diff * 1024 );
 
-       return "DONE $size_total; ${speed}KB/s $eta";
+       my @l = localtime;
+       my $date = sprintf "%d-%.2d-%.2d %2d:%.2d:%.2d", $l[5] + 1900, $l[4] + 
1, @l[(3,2,1,0)];
+       return "DONE $size_total; ${speed}KB/s $eta @ $date";
 }
 
 
@@ -324,18 +329,27 @@
 # }}}
 package Get; # {{{
 
-my $slots = 1;
 my %running;
 sub makenew
 {
        my $net = shift;
        my $class = shift;
        my $url = shift;
+       my $slots = 1;
+       if ( $_[0] eq "slots" ) {
+               shift;
+               $slots = shift;
+       }
 
        return {} if $gotlist{ $url };
        $running{ $net } = {} unless exists $running{ $net };
        my $rn = $running{ $net };
        return {} if $slots <= scalar keys %$rn;
+       foreach my $id ( keys %$rn ) {
+               if ( $rn->{ $id }->{url} eq $url ) {
+                       return {};
+               }
+       }
 
        my $id = 1;
        ++$id while exists $rn->{ $id };
@@ -437,7 +451,7 @@
        my $proto = shift;
        my $class = ref $proto || $proto;
        my $url = shift;
-       Get::makenew( "RS", $class, $url, @_ );
+       Get::makenew( "RS", $class, $url );
 }
 
 sub stage1
@@ -453,15 +467,24 @@
        my ($self, $body, $url) = @_;
        $self->print("starting......");
 
+       my $link;
        if ( $body =~ /The file could not be found\.  Please check the download 
link\./m ) {
                return $self->error( "file not found" );
-       }
-       if ( $body =~ /Unfortunately you will have to wait ([0-9]+) minutes,/m 
) {
+       } elsif ( $body =~ /file has been removed from the server\./m ) {
+               return $self->error( "file removed" );
+       } elsif ( $body =~ /Unfortunately you will have to wait ([0-9]+) 
minutes,/m ) {
                return $self->wait( $1 * 60, \&stage1, "servers overloaded, 
waiting" );
+       } elsif ( $body =~ /form id="ff" action="(.*?)"/m ) {
+               $link = $1;
+               $self->{s2problems} = 0;
+       } else {
+               if ( $self->{s2problems} ) {
+                       return $self->error( "unknown problem" );
+               } else {
+                       $self->{s2problems} = 1;
+                       return $self->wait( 5 * 60, \&stage1, "unknown 
problems, retrying in" );
+               }
        }
-       return $self->stage1()
-               unless $body =~ /form id="ff" action="(.*?)"/m;
-       my $link = $1;
 
        $self->curl( $link, \&stage3, post => 'dl.start=Free', referer => $url 
);
 
@@ -521,7 +544,6 @@
        unlink $cookie if -e $cookie;
 
        Get::makenew( "NL", $class, $url, cookie => $cookie );
-
 }
 
 sub stage1
@@ -815,6 +837,58 @@
 }
 
 # }}}
+package Get::OdSiebie; # {{{
+
+BEGIN {
+       our @ISA;
+       @ISA = qw(Get);
+}
+
+my $oscookie = 0;
+sub new
+{
+       my $proto = shift;
+       my $class = ref $proto || $proto;
+       my $url = shift;
+
+       ++$oscookie;
+       my $cookie = ".os.$oscookie.txt";
+       unlink $cookie if -e $cookie;
+
+       Get::makenew( "OS", $class, $url, slots => 16, cookie => $cookie );
+}
+
+sub stage1
+{
+       my $self = shift;
+
+       my $url = $self->{url};
+       $url =~ s#/pokaz/#/pobierz/#;
+
+       $self->print("starting...");
+       $self->curl( $url, \&stage2, cookies => $self->{cookie} );
+}
+
+sub stage2
+{
+       my ($self, $body, $url) = @_;
+
+       my $furl = $url;
+       $furl =~ s#/pobierz/#/download/#;
+       $self->{file_url} = $furl;
+
+       $self->print("downloading");
+
+       $self->download( referer => $url, cookies => $self->{cookie} );
+}
+
+sub DESTROY
+{
+       my $self = shift;
+       unlink $self->{cookie};
+}
+
+# }}}
 package main;
 
 my $get_list = shift @ARGV || 'get.list';
@@ -824,7 +898,8 @@
 my $listmtime = 0;
 sub readlist
 {
-       my $mtime = (stat $get_list)[9];
+       return unless -r $get_list;
+       my $mtime = (stat _)[9];
        return unless $checklist or $mtime != $listmtime;
 
        my @newlist;
@@ -841,11 +916,14 @@
                } elsif ( $line =~ m#^\s*(http://netload\.in/datei.*?)\s*$# ) { 
#){# vimbug
                        $url = $1;
                        new Get::NetLoad( $1 );
+               } elsif ( $line =~ 
m#^\s*(http://odsiebie.com/(pokaz|pobierz)/.*?)\s*$# ) { #){# vimbug
+                       $url = $1;
+                       new Get::OdSiebie( $1 );
                }
 
                if ( $url ) {
                        if ( exists $gotlist{$url} ) {
-                               push @newlist, "# " . $gotlist{$url} . ": " . 
$line;
+                               push @newlist, "# " . $gotlist{$url} . ":\n# " 
. $line;
                        } else {
                                push @newlist, $url . "\n";
                        }
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to