AnyEvent-Net-Curl-Queued

 view release on metacpan or  search on metacpan

bin/yada  view on Meta::CPAN

#!/usr/bin/env perl
# ABSTRACT: Yet Another Download Accelerator CLI wrapper
# PODNAME: yada
use strict;
use utf8;
use warnings qw(all);

use Config;
use Fcntl;
use File::Copy;
use Getopt::Long;
use IO::Handle;
use List::Util qw(shuffle);
use Pod::Usage;
use URI;
use YADA;

our $VERSION = '0.049'; # VERSION


GetOptions(
    q(help)             => \my $help,
    q(dups!)            => \my $dups,
    q(encoding=s)       => \my $encoding,
    q(max=i)            => \my $max,
    q(maxredirs=i)      => \my $maxredirs,
    q(proxy=s)          => \my $proxy,
    q(quiet!)           => \my $quiet,
    q(referer=s)        => \my $referer,
    q(tcp_nodelay)      => \my $tcp_nodelay,
    q(timeout=i)        => \my $timeout,
    q(useragent=s)      => \my $useragent,
    q(verbose)          => \my $verbose,
    q(skip_existing)    => \my $skip_existing,
    q(shuffle)          => \my $shuffle,
) or pod2usage(q(-verbose) => 1);
pod2usage(q(-verbose) => 1) if $help;

my @urls = <>;
chomp @urls;
@urls = shuffle @urls if $shuffle;

autoflush $_, 1 for (\*STDERR, \*STDOUT);

my $q = YADA->new({
    allow_dups  => $dups // 1,
    max         => $max // 4,
    timeout     => $timeout // 600,
});

my $c = 0;
for my $url (@urls) {
    my $fh;
    my $name = get_filename(URI->new($url), $skip_existing);
    next if $skip_existing && -e $name;
    $q->append(
        $url,
        sub {
            my ($self) = @_;

            # will die() later
            sysopen($fh, $name, O_CREAT | O_NONBLOCK | O_WRONLY);
            binmode $fh;

            $self->setopt(



( run in 0.689 second using v1.01-cache-2.11-cpan-39bf76dae61 )