Skip to content

Instantly share code, notes, and snippets.

@keiya
Created May 21, 2012 04:56
Show Gist options
  • Select an option

  • Save keiya/2760613 to your computer and use it in GitHub Desktop.

Select an option

Save keiya/2760613 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# by Keiya Chinen
# usage:
# perl animedl.pl http://www.anime44.com/the-melancholy-of-haruhi-suzumiya-season-2-episode-8
use strict;
use warnings;
use utf8;
use LWP;
use LWP::ConnCache;
use Data::Dumper;
$| = 1;
# http keepalive
my $conncache = LWP::ConnCache->new;
my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/15.0 Firefox/15.0a1');
my $base_url = $ARGV[0];
my $title = $base_url;
$title =~ tr|/:|-|;
my $movie_list = access($base_url,$ua,$conncache);
my @iframes = $movie_list =~ m|"(http://(?:www\.)?gogoanime\.com/(?:.+)player/.+?)"|mg;
foreach my $iframe (@iframes) {
$iframe =~ s/&/&/g;
my $files_raw = access($iframe,$ua,$conncache);
my @urls = $files_raw =~ m|"url":"(.+?)"|mg;
my $res = save($urls[1],$ua,$title,$conncache);
}
sub access{
print('[GET] '.$_[0].' : ');
my $ua = $_[1];
$ua->conn_cache( $_[2] );
my $response = $ua->get($_[0]);
if ($response->is_success) {
my $return = $response->decoded_content;
print("OK\n");
return $return;
} else {
#die "Failed\n";
print "NG\n";
return undef;
}
}
sub save {
print('[SAV] '.$_[0]."\n");
my $ua = $_[1];
$ua->conn_cache( $_[3] );
my $response = $ua->get($_[0],':content_file' => $_[2]);
if ($response->is_success) {
return $response;
} else {
print "Could not save : $_[0]\n";
return undef;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment