App-YTDL
view release on metacpan or search on metacpan
lib/App/YTDL/ChooseVideos.pm view on Meta::CPAN
];
return $chosen;
}
}
}
}
sub set_sort_videolist {
my ( $set, $opt ) = @_;
my $backup_item = $opt->{list_sort_item};
my $backup_order = $set->{list_sort_order};
my $sort_items = [ 'upload_date', 'title', 'view_count_raw', 'duration' ];
my $confirm = ' CONFIRM';
my @pre = ( undef, $confirm );
my $menu = [ @pre, map { my $s = $_; $s =~ s/_raw\z//; $s =~ s/_/ /g; '- ' . $s } @$sort_items ];
ITEM: while ( 1 ) {
my $current = $opt->{list_sort_item};
$current =~ s/_raw\z//;
$current =~ s/_/ /g;
my $prompt = sprintf 'Sort item: [%s]', $current;
my $idx = choose (
$menu,
{ prompt => $prompt, clear_screen => 0, layout => 3, index => 1, undef => ' BACK' }
);
if ( ! defined $idx || ! defined $menu->[$idx] ) {
$opt->{list_sort_item} = $backup_item;
return;
}
if ( $menu->[$idx] eq $confirm ) {
last ITEM;
}
$idx -= @pre;
$opt->{list_sort_item} = $sort_items->[$idx];
}
ORDER: while ( 1 ) {
my $curr_sort_item = $opt->{list_sort_item};
$curr_sort_item =~ s/_raw\z//;
$curr_sort_item =~ s/_/ /g;
my $order_prompt = sprintf 'Sort order "%s": [%s]', $curr_sort_item, $set->{list_sort_order};
my $choice = choose (
[ @pre, '- Asc', '- Desc' ],
{ prompt => $order_prompt, clear_screen => 0, layout => 3, undef => ' BACK' }
);
if ( ! defined $choice ) {
$set->{list_sort_order} = $backup_order;
return;
}
if ( $choice eq $confirm ) {
$set->{change}++;
return;
}
$choice =~ s/^-\s//;
$set->{list_sort_order} = $choice;
}
}
lib/App/YTDL/Download.pm view on Meta::CPAN
elsif ( $choice eq $no ) {
$keep_fmt_choices = 0;
}
else {
$keep_fmt_choices = 1;
}
}
my $fmt_str;
my $count = {};
my @fmt_data;
my @backup_fmt_data;
VIDEO_ID: for my $id ( @sorted_ids ) {
my $count_of_total = $data->{$ex}{$up}{$id}{count} . '/' . $total_chosen_videos;
if ( ! defined $data->{$ex}{$up}{$id}{fmt_to_info} ) {
$download_cmds{$ex}{$up}{$id} = [ sprintf "[%s] %s\n%s\nSkipped: %s\n", $ex, $id, $data->{$ex}{$up}{$id}{title}, $set->{failed_fetching_data} ];
next VIDEO_ID;
}
my @cmd = @{$set->{youtube_dl}};
if ( $qty eq 'manually' ) {
if ( ! $fmt_str ) {
lib/App/YTDL/Download.pm view on Meta::CPAN
$info .= "Requested formats (@unavailable_fmts) not available!\n";
my $answer = choose(
[ undef, 'Choose from available formats' ],
{ info => $info, undef => 'Skip this video', prompt => '', layout => 3 }
);
if ( ! defined $answer ) {
$download_cmds{$ex}{$up}{$id} = [ sprintf "[%s] %s\n%s\nSkipped: user request\n", $ex, $id, $data->{$ex}{$up}{$id}{title} ];
next VIDEO_ID;
}
else {
@backup_fmt_data = @fmt_data;
@fmt_data = ();
$fmt_str = undef;
redo VIDEO_ID;
}
}
}
}
else {
@fmt_data = ( $qty );
}
lib/App/YTDL/Download.pm view on Meta::CPAN
$output .= '/%(uploader)s' if $opt->{use_uploader_dir} == 1 || $opt->{use_uploader_dir} == 2 && $data->{$ex}{$up}{$id}{from_list};
if ( $opt->{filename_format} == 0 ) { $output .= '/%(title)s.%(ext)s'; }
elsif ( $opt->{filename_format} == 1 ) { $output .= '/%(title)s_%(height)s.%(ext)s'; }
elsif ( $opt->{filename_format} == 2 ) { $output .= '/%(title)s_%(format_id)s.%(ext)s'; }
elsif ( $opt->{filename_format} == 3 ) { $output .= '/%(title)s_%(format_id)s_%(height)s.%(ext)s'; }
else { $output .= '/%(title)s_%(format)s.%(ext)s'; }
push @cmd, '-o', $output;
push @cmd, '--', $data->{$ex}{$up}{$id}{webpage_url};
$download_cmds{$ex}{$up}{$id} = [ @cmd ];
if ( @backup_fmt_data ) {
@fmt_data = @backup_fmt_data;
@backup_fmt_data = ();
}
}
}
}
say "";
my %download_failed;
my $count_downloads = 0;
my $total_downloads = 0;
for my $ex ( keys %download_cmds ) {
for my $up ( keys %{$download_cmds{$ex}} ) {
lib/App/YTDL/Options.pm view on Meta::CPAN
my $choice = choose_a_number( $digits, { cs_label => $name, info => $info, small_first => 1 } );
return if ! defined $choice;
$opt->{$key} = $choice eq '--' ? undef : $choice;
$set->{change}++;
return;
}
sub _opt_choose_from_list_idx {
my ( $set, $opt, $key, $prompt, $list ) = @_;
my $backup = $opt->{$key};
my $confirm = ' CONFIRM';
my @pre = ( undef, $confirm );
my $choices = [ @pre, map { "- $_" } @$list ];
while ( 1 ) {
my $local_prompt = $prompt . ': [' . ( $list->[$opt->{$key}] // '--' ) . ']';
# Choose
my $idx = choose(
$choices,
{ prompt => $local_prompt, layout => 3, undef => ' BACK', index => 1 }
);
if ( ! defined $idx || $idx == 0 ) {
$opt->{$key} = $backup;
return;
}
elsif ( $choices->[$idx] eq $confirm ) {
$set->{change}++;
return;
}
else {
$opt->{$key} = $idx - @pre;
}
}
}
sub _opt_choose_from_list_value {
my ( $set, $opt, $key, $prompt, $list ) = @_;
my $backup = $opt->{$key};
my $confirm = ' CONFIRM';
my @pre = ( undef, $confirm );
while ( 1 ) {
my $local_prompt = $prompt . ': [' . ( $opt->{$key} // '--' ) . ']';
# Choose
my $choice = choose(
[ @pre, map { "- $_" } @$list ],
{ prompt => $local_prompt, layout => 3, undef => ' BACK', index => 0 }
);
if ( ! defined $choice ) {
$opt->{$key} = $backup;
return;
}
elsif ( $choice eq $confirm ) {
$set->{change}++;
return;
}
else {
$choice =~ s/^-\s//;
$opt->{$key} = $choice;
}
( run in 1.282 second using v1.01-cache-2.11-cpan-49f99fa48dc )