#!/usr/bin/perl #This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. #written by Fengyuan Chen. #cfy1990 at gmail dot com use strict; use warnings; use Getopt::Long; use Pod::Usage; use LWP::UserAgent; use Encode; use utf8; use MIME::Base64 qw(encode_base64); use constant UA => 'Opera/9.80 (X11; Linux i686; U; en) Presto/2.6.30 Version/10.60'; use constant VERSION => 1.0; my $ua=new LWP::UserAgent agent=> UA; sub say{ print @_,"\n"; } sub get_content{ my $ua=shift; my $url=shift; my $response = $ua->get('http://iperl.co.cc/115.pl?'.$url); if ($response->is_success) { return decode 'utf-8',$response->content; } else{ warn "get_content error:".$response->status_line; return undef; } } GetOptions( 'file|f=s' => \ my $file, 'show|s' => \ my $show, 'help|h' => \ my $help, 'version|V'=>\ my $version, ); if(defined $version){ say 'version:'.VERSION; exit 0; } if(defined $help|| (! defined $file && (scalar @ARGV == 0) ) ) { pod2usage(1); } my @web_urls; if(scalar @ARGV > 0){ @web_urls=@ARGV; @ARGV=(); } if(defined $file){ my @files=split /,/,$file; unshift @ARGV,@files; my $urls=join "",<>; while($urls=~m{(\Qhttp://u.115.com/file/\E[a-z0-9]++)}g){ #http://u.115.com/file/t99717cfae push @web_urls,$1; } } unless(@web_urls){ pod2usage(1); } #get to download urls #open URL,'<','url'; #close URL; for my $web_url (@web_urls) { chomp($web_url); #get real download urls my $web_content=get_content($ua,$web_url); for(split /\n/,$web_content){ my ($file_name,$file_url)=split /:::/; unless(defined $show){ print encode 'utf-8',"\e]2;115_client-$file_name\a"; # system('wget','-c','-U',UA,$file_url,'-O',$file_name); system('wget','-c','-U',UA,$file_url,'--timeout=10','-O',$file_name); exit $? if $?; sleep 1; } else { say encode 'utf-8',"$file_name\:\:\:$file_url"; } } } __END__ =head1 NAME 115_down - A simple 115.com file downloader written by cfy (cfy1990 at gmail dot com) =head1 SYNOPSIS 115_down [-f|--file file] [-s] [-h|--help] [-V|--version] [url] =head1 OPTIONS =item B<-f, --file> specify the files to read urls.Multiple files can be given,separated by commas.use '-' to read from stdin. =item B<-s, --show> show the download urls instead download them =item B<-V,--version> show version =item B<--help> print help =cut