Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created June 6, 2011 02:15
Show Gist options
  • Save ishiduca/1009645 to your computer and use it in GitHub Desktop.
Save ishiduca/1009645 to your computer and use it in GitHub Desktop.
pixiv 漫画コンテンツの非同期DL
#!/usr/bin/env perl
use strict;
use warnings;
use WWW::Pixiv::Download;
use Config::Pit qw(pit_get);
use Parallel::ForkManager;
use Path::Class;
use Clone;
my $illust_id = '17373419';
my $dir_home = "$ENV{HOME}/Desktop/test_image";
my $config = pit_get('www.pixiv.net', require => {
pixiv_id => '', pass => '',
});
die qq(! failed: "pit_get"\n) if ! %$config;
my $client = WWW::Pixiv::Download->new(
pixiv_id => $config->{pixiv_id},
pass => $config->{pass},
# over_write => 1,
look => 1,
);
my $info = $client->prepare_download($illust_id);
$info->{author}->{name} =~ s:/::g;
$info->{title} =~ s:/::g;
my $dir = join '/', $dir_home, $info->{author}->{name}, $info->{title};
unless (-e $dir) {
warn qq(! "${dir}" not found.\n);
dir($dir)->mkpath or die qq(! failed: can not mkpath "${dir}" $!\n);
warn qq( mkpath "${dir}" success.\n);
}
my $urls = $info->{contents}->{img_srcs};
die qq(! failed: image srcs not found.\n) unless $urls;
my $pm = Parallel::ForkManager->new(scalar @$urls);
for my $url (@$urls) {
my $pid = $pm->start and next;
my $clone_c = Clone::clone($client);
$clone_c->_save_content($url, {
path_name => $dir,
});
$pm->finish;
}
$pm->wait_all_children;
exit 0;
__END__
はいてくりん/七宮姉妹【本編】の漫画コンテツ 49枚 をフォークプロセスでDL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment