App-YoutubeDlIf
view release on metacpan or search on metacpan
youtube_dl_if(%args) -> [status, msg, payload, meta]
Download videos using youtube-dl with extra selection/filtering.
This is a wrapper for youtube-dl.
This function is not exported.
Arguments ('*' denotes required arguments):
* if_duration_not_longer_than => *str*
* if_duration_not_shorter_than => *str*
* if_not_yet => *bool*
If set, only download videos that are not yet downloaded.
When set to true, youtube-dl-if will first extract downloaded video
ID's from filenames or URL's or video ID's listed in a text file
(specified via "--log-file"), e.g.:
35682594 Table Tennis Shots- If Were Not Filmed, Nobody Would Believe [HD]-dUjxqFbWzQo.mp4 date:[2019-12-29 ]
or:
First element (status) is an integer containing HTTP status code (200
means OK, 4xx caller error, 5xx function error). Second element (msg) is
a string containing error message, or 'OK' if status is 200. Third
element (payload) is optional, the actual result. Fourth element (meta)
is called result metadata and is optional, a hash that contains extra
information.
Return value: (any)
youtube_dl_if_not_yet
Usage:
youtube_dl_if_not_yet(%args) -> [status, msg, payload, meta]
Download videos using youtube-dl if not already downloaded.
This is a shortcut for:
% youtube-dl-if --if-not-yet ...
This function is not exported.
Arguments ('*' denotes required arguments):
* if_duration_not_longer_than => *str*
* if_duration_not_shorter_than => *str*
* log_file => *str* (default: "/home/u1/notes/download-logs.org")
File that contains list of download filenames.
* restart_if_no_output_after => *duration*
* urls_or_ids* => *array[str]*
Returns an enveloped result (an array).
lib/App/YoutubeDlIf.pm view on Meta::CPAN
if (-f $p) {
$path = $p; last;
}
}
die "Cannot find download log file, please specify using ".
"--log-file or put the log file in one of: ".
(join ", ", @paths) unless $path;
$path;
},
},
if_duration_not_shorter_than => {
#schema => 'duration*', # XXX duration coercer parses 01:00 as 1 hour 0 minutes instead of 1 minute 0 seconds
schema => 'str*',
tags => ['category:filtering'],
},
if_duration_not_longer_than => {
#schema => 'duration*',
schema => 'str*',
tags => ['category:filtering'],
},
restart_if_no_output_after => {
schema => 'duration*',
tags => ['category:restart'],
},
);
our %arg_if_not_yet = (
if_not_yet => {
summary => 'If set, only download videos that are not yet downloaded',
schema => 'bool',
description => <<'_',
When set to true, youtube-dl-if will first extract downloaded video ID's from
filenames or URL's or video ID's listed in a text file (specified via
`--log-file`), e.g.:
35682594 Table Tennis Shots- If Were Not Filmed, Nobody Would Believe [HD]-dUjxqFbWzQo.mp4 date:[2019-12-29 ]
lib/App/YoutubeDlIf.pm view on Meta::CPAN
$SPEC{youtube_dl_if} = {
v => 1.1,
summary => 'Download videos using youtube-dl with extra selection/filtering',
description => <<'_',
This is a wrapper for **youtube-dl**.
_
args => {
%args_common,
%arg_if_not_yet,
},
args_rels => {
#dep_any => [log_file => ['if_not_yet']], # XXX currently will fail if if_not_yet not specified because of the log_file's default
},
deps => {
prog => 'youtube-dl',
},
};
sub youtube_dl_if {
my %args = @_;
my $re_video_id = $Regexp::Pattern::YouTube::RE{video_id}{pat} or die;
$re_video_id = qr/\A$re_video_id\z/;
lib/App/YoutubeDlIf.pm view on Meta::CPAN
my @argv_for_youtube_dl;
ARG:
for my $arg (@{$args{urls_or_ids}}) {
FILTER: {
# looks like an option name
last FILTER if $arg =~ /\A--?\w+/ && $arg !~ $re_video_id;
my $video_id = YouTube::Util::extract_youtube_video_id($arg);
if ($video_id) {
log_trace "Argument %s has video ID %s", $arg, $video_id;
if ($args{if_not_yet}) {
if (my $filename = _search_id_in_log_file($video_id, $args{log_file})) {
log_info "Argument %s (video ID %s) has been downloaded (%s), skipped", $arg, $video_id, $filename;
next ARG;
} else {
log_trace "Argument %s (video ID %s) is not in downloaded list", $arg, $video_id;
}
}
}
if (defined $args{if_duration_not_shorter_than} || defined $args{if_duration_not_longer_than}) {
my $min_secs = _dur2sec($args{if_duration_not_shorter_than});
my $max_secs = _dur2sec($args{if_duration_not_longer_than});
my $video_dur = readpipe({log=>1, die=>1}, "youtube-dl --no-playlist --get-duration -- '$arg' 2>/dev/null");
my $video_secs = _dur2sec($video_dur);
if (defined $min_secs && $video_secs < $min_secs) {
log_info "Argument %s (video ID %s, duration %s) is too short (min %s), skipped", $arg, $video_id, $video_dur, $args{if_duration_not_shorter_than};
next ARG;
}
if (defined $max_secs && $video_secs > $max_secs) {
log_info "Argument %s (video ID %s, duration %s) is too long (min %s), skipped", $arg, $video_id, $video_dur, $args{if_duration_not_longer_than};
next ARG;
}
}
} # FILTER
push @argv_for_youtube_dl, $arg;
}
my $do_govern;
$do_govern = 1 if defined $args{restart_if_no_output_after};
lib/App/YoutubeDlIf.pm view on Meta::CPAN
my @opts_for_govern;
push @opts_for_govern, "--restart-if-no-output-after", $args{restart_if_no_output_after}
if defined $args{restart_if_no_output_after};
system({log=>1, die=>1}, "govproc", @opts_for_govern, "--", "youtube-dl", @argv_for_youtube_dl);
} else {
system({log=>1, die=>1}, "youtube-dl", @argv_for_youtube_dl);
}
[200];
}
$SPEC{youtube_dl_if_not_yet} = {
v => 1.1,
summary => 'Download videos using youtube-dl if not already downloaded',
description => <<'_',
This is a shortcut for:
% youtube-dl-if --if-not-yet ...
_
args => {
%args_common,
},
args_rels => {
},
deps => {
prog => 'youtube-dl',
},
};
sub youtube_dl_if_not_yet {
my %args = @_;
youtube_dl_if(if_not_yet=>1, %args);
}
1;
# ABSTRACT: Download videos using youtube-dl with extra selection/filtering
__END__
=pod
=encoding UTF-8
lib/App/YoutubeDlIf.pm view on Meta::CPAN
Download videos using youtube-dl with extra selectionE<sol>filtering.
This is a wrapper for B<youtube-dl>.
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<if_duration_not_longer_than> => I<str>
=item * B<if_duration_not_shorter_than> => I<str>
=item * B<if_not_yet> => I<bool>
If set, only download videos that are not yet downloaded.
When set to true, youtube-dl-if will first extract downloaded video ID's from
filenames or URL's or video ID's listed in a text file (specified via
C<--log-file>), e.g.:
35682594 Table Tennis Shots- If Were Not Filmed, Nobody Would Believe [HD]-dUjxqFbWzQo.mp4 date:[2019-12-29 ]
or:
lib/App/YoutubeDlIf.pm view on Meta::CPAN
(200 means OK, 4xx caller error, 5xx function error). Second element
(msg) is a string containing error message, or 'OK' if status is
200. Third element (payload) is optional, the actual result. Fourth
element (meta) is called result metadata and is optional, a hash
that contains extra information.
Return value: (any)
=head2 youtube_dl_if_not_yet
Usage:
youtube_dl_if_not_yet(%args) -> [status, msg, payload, meta]
Download videos using youtube-dl if not already downloaded.
This is a shortcut for:
% youtube-dl-if --if-not-yet ...
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<if_duration_not_longer_than> => I<str>
=item * B<if_duration_not_shorter_than> => I<str>
=item * B<log_file> => I<str> (default: "/home/u1/notes/download-logs.org")
File that contains list of download filenames.
=item * B<restart_if_no_output_after> => I<duration>
=item * B<urls_or_ids>* => I<array[str]>
script/youtube-dl-if-not-yet view on Meta::CPAN
our $VERSION = '0.004'; # VERSION
# FRAGMENT id=shcompgen-hint command=_youtube-dl
use 5.010001;
use strict;
use warnings;
use Perinci::CmdLine::Any;
Perinci::CmdLine::Any->new(
url => '/App/YoutubeDlIf/youtube_dl_if_not_yet',
log => 1,
log_level => 'info',
read_config => 0,
read_env => 0,
allow_unknown_opts => 1,
)->run;
# PODNAME: youtube-dl-if-not-yet
# ABSTRACT: Download videos using youtube-dl if not already downloaded
( run in 2.184 seconds using v1.01-cache-2.11-cpan-cc502c75498 )