line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Automaton::Plugin::Action::YouTube; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Download module for YouTube videos |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
392
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
7
|
1
|
|
|
1
|
|
368
|
use Moo; |
|
1
|
|
|
|
|
9101
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
1354
|
use File::Spec::Functions; |
|
1
|
|
|
|
|
470
|
|
|
1
|
|
|
|
|
62
|
|
9
|
1
|
|
|
1
|
|
383
|
use WWW::YouTube::Download 0.57; |
|
1
|
|
|
|
|
34517
|
|
|
1
|
|
|
|
|
40
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.57'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
482
|
use Data::Dumper; |
|
1
|
|
|
|
|
4106
|
|
|
1
|
|
|
|
|
216
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub go { |
16
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
eval { $video_data = $client->prepare_download($url); }; warn "Error with $url\n".$@ if $@; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#TODO: Report errors |
30
|
0
|
0
|
|
|
|
|
next unless $video_data; |
31
|
0
|
|
|
|
|
|
my $target_file = catfile($target, $video_data->{title} . '.' . $video_data->{suffix} ); |
32
|
0
|
0
|
|
|
|
|
next if -e $target_file; |
33
|
0
|
|
|
|
|
|
_logger($d, "downloading $url to $target_file"); |
34
|
0
|
|
|
|
|
|
eval{$client->download( $url, { filename => $target_file } );} |
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return 1; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _logger { |
42
|
0
|
|
|
0
|
|
|
my $level = shift; |
43
|
0
|
|
|
|
|
|
my $message = shift; |
44
|
0
|
0
|
|
|
|
|
print "$message\n" if $level; |
45
|
0
|
|
|
|
|
|
return 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |