| 1 | package App::Automaton::Plugin::Action::NZB; | ||||||||||||
| 2 | |||||||||||||
| 3 | # ABSTRACT: Download module for nzb files | ||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use File::Spec::Functions; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 0 | ▶ | sub go { | ||||||||||
|
Subroutine
go: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 14 | 0 | my $self = shift; | |||||||||||
| 15 | 0 | my $in = shift; | |||||||||||
| 16 | 0 | my $bits = shift; | |||||||||||
| 17 | 0 | ▶ | my $target = $in->{target} || '.'; | ||||||||||
|
Condition0%0/2
$in->{'target'} || '.'
MC/DC0%0/1
$in->{'target'} || '.'
$in->{'target'}
Truth table0%0/2
A
A= $in->{'target'}
| |||||||||||||
| 18 | 0 | my $d = $in->{debug}; | |||||||||||
| 19 | |||||||||||||
| 20 | 0 | my @patterns = ( | |||||||||||
| 21 | 'http:\/\/www.nzbsearch.net\/nzb_get.aspx\?mid=[a-z,A-Z,0-9]*', | ||||||||||||
| 22 | 'https:\/\/www.nzb-rss.com\/nzb\/.*nzb' | ||||||||||||
| 23 | ); | ||||||||||||
| 24 | 0 | my $pattern_string = join('|', @patterns); | |||||||||||
| 25 | |||||||||||||
| 26 | 0 | foreach my $bit (@$bits) { | |||||||||||
| 27 | 0 | my @urls = $bit =~ /$pattern_string/g; | |||||||||||
| 28 | 0 | foreach my $url (@urls) { | |||||||||||
| 29 | 0 | my $name = _get_name($url); | |||||||||||
| 30 | 0 | my $target_file = catfile($target, $name); | |||||||||||
| 31 | 0 | ▶ | next if -e $target_file; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||||
| 33 | 0 | _logger($d, "downloading $url to $target_file"); | |||||||||||
| 34 | 0 | $ua->mirror($url, $target_file); | |||||||||||
| 35 | } | ||||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 0 | return(1); | |||||||||||
| 39 | } | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | ▶ | sub _get_name { | ||||||||||
|
Subroutine
_get_name: called CC=2 SCAR=7.0
| |||||||||||||
| 42 | 1 | my $uri = shift; | |||||||||||
| 43 | |||||||||||||
| 44 | 1 | my $name = (split(/\//, $uri))[-1]; | |||||||||||
| 45 | |||||||||||||
| 46 | # swap out characters that we don't want in the file name | ||||||||||||
| 47 | 1 | $name =~ s/[^a-zA-Z0-9\\-]/_/g; | |||||||||||
| 48 | |||||||||||||
| 49 | # ensure file name ends in .nzb for ease | ||||||||||||
| 50 | 1 | ▶ | if ( lc(substr($name, -4)) ne '.nzb' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | 1 | $name .= '.nzb'; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 1 | return $name; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | sub _logger { | ||||||||||
|
Subroutine
_logger: not called CC=2 SCAR=17.9
| |||||||||||||
| 58 | 0 | my $level = shift; | |||||||||||
| 59 | 0 | my $message = shift; | |||||||||||
| 60 | 0 | ▶ | print "$message\n" if $level; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | 0 | return 1; | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 1 | 1; | |||||||||||
| 65 | |||||||||||||
| 66 | __END__ | ||||||||||||