Automaton/Plugin/Action/YouTube.pm

filter: Statementstmt 45.4% 20 / 44 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 1 / 1 totaltotal 44.2% 27 / 61 CC 7 SCAR 29.6
CC
7
Cov
38%
go
42.0
_logger
6.0
BEGIN
1.0
CRAP 19.3
« Automaton/Plugin/Source/IMAP.pm ↑ Summary Automaton.pm »
1 package App::Automaton::Plugin::Action::YouTube;
2  
3 # ABSTRACT: Download module for YouTube videos
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 File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use WWW::YouTube::Download 0.57;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.57';
12  
13 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub go {
Subroutine go: not called CC=6 SCAR=37.4
Pod documented
16 0 my $self = shift;
17 0 my $in = shift;
18 0 my $bits = shift;
19 0 my $d = $in->{debug};
20
21 0 my $target = $in->{target};
22
23 0 foreach my $bit (@$bits) {
24 0 my @urls = $bit =~ /http[s]?:\/\/www.youtube\.com\/watch\?v=.{11}/g;
25 0 foreach my $url (@urls) {
26 0 my $client = WWW::YouTube::Download->new();
27 0 my $video_data;
28 0 ▶ eval { $video_data = $client->prepare_download($url); }; warn "Error with $url\n".$@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
29 #TODO: Report errors
30 0 ▶ next unless $video_data;
Branch: 1 branch
BranchTrueFalseTotal
unless $video_data 0 0 0
31 0 my $target_file = catfile($target, $video_data->{title} . '.' . $video_data->{suffix} );
32 0 ▶ next if -e $target_file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $target_file 0 0 0
33 0 _logger($d, "downloading $url to $target_file");
34 0 eval{$client->download( $url, { filename => $target_file } );}
35 }
36 }
37
38 0 return 1;
39 }
40  
41 0 ▶sub _logger {
Subroutine _logger: not called CC=2 SCAR=17.9
42 0 my $level = shift;
43 0 my $message = shift;
44 0 ▶ print "$message\n" if $level;
Branch: 1 branch
BranchTrueFalseTotal
if $level 0 0 0
45 0 return 1;
46 }
47  
48 1 1;
49  
50 __END__
« Automaton/Plugin/Source/IMAP.pm ↑ Summary Automaton.pm »