| 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
| |||||||||||
| 29 | #TODO: Report errors | ||||||||||
| 30 | 0 | ▶ | next unless $video_data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | my $target_file = catfile($target, $video_data->{title} . '.' . $video_data->{suffix} ); | |||||||||
| 32 | 0 | ▶ | next if -e $target_file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 45 | 0 | return 1; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 1 | 1; | |||||||||
| 49 | |||||||||||
| 50 | __END__ | ||||||||||