App-YTDL

 view release on metacpan or  search on metacpan

bin/getvideo  view on Meta::CPAN

elsif ( ! @ids && ( %{$set->{history}} || %{$set->{sticky}} ) ) {
    my $clear_screen = 1;
    my $old_idx = 0;

    MENU: while ( 1 ) {
        my ( $uploader, $sticky ) = ( '- Uploaders', '  Edit Sticky' );
        my $menu = [ undef, $uploader, $sticky ];
        # Choose
        my $idx = choose(
            $menu,
            { prompt => 'Choose:', layout => 3, undef => '  QUIT',
              clear_screen => $clear_screen, index => 1, default => $old_idx }
        );
        if ( ! defined $idx || ! defined $menu->[$idx] ) {
            exit;
        }
        #if ( $opt->{menu_memory} ) {
        #    if ( $old_idx == $idx && ! $ENV{TC_RESET_AUTO_UP} ) {
        #        $old_idx = 0;
        #        next MENU;
        #    }

lib/App/YTDL/Arguments.pm  view on Meta::CPAN

        else {
            if ( $opt->{entries_with_info} ) {
                _get_video_data( $set, $opt, $data, $ex, $up, $ids, $progress );
            }
        }
    }

    URL_DATA: for my $webpage_url ( @args ) {
        my ( $ex, $up, $ids ) = @{$urls_data->{$webpage_url}};
        if ( @$ids > 1 ) {
            my $prompt = $data->{$ex}{$up}{$ids->[0]}{uploader} || $webpage_url;
            my $chosen_ids = choose_videos( $set, $opt, $data, $ex, $up, $ids, $prompt );
            if ( ! defined $chosen_ids ) {
                next URL_DATA;
            }
            push @{$chosen->{$ex}{$up}}, @$chosen_ids;
        }
        else {
            push @{$chosen->{$ex}{$up}}, @$ids;
        }
    }
    if ( @failed_download_list_info ) {
        my $prompt = 'List info - failed downloads:' . "\n";
        $prompt .= '  ' . join "\n  ", @failed_download_list_info;
        choose( [ 'Press "Enter" to continue.' ], { prompt => $prompt } );
    }
    return $chosen;
}



sub _get_video_data {
    my ( $set, $opt, $data, $ex, $up, $ids, $progress ) = @_;
    my ( $min, $max ) = minmax( $opt->{entries_with_info}, scalar @$ids );
    my $message = sprintf "%s GET video data: ", ' ' x length $progress;

lib/App/YTDL/ChooseVideos.pm  view on Meta::CPAN

       || $h_ref->{$a}{title} cmp $h_ref->{$b}{title};
    }
    else {
          ( $s[0] // '' )     cmp ( $s[1] // '' )
       || $h_ref->{$a}{title} cmp $h_ref->{$b}{title};
   }
}


sub choose_videos {
    my ( $set, $opt, $data, $ex, $up, $ids, $prompt ) = @_;
    my $view_count_w  = 0;
    my $id_w          = 0;
    my $upload_date_w = 0;
    my $duration_w    = 7;
    my $has_date_sort   = 0;
    my $has_view_count  = 0;
    my $has_duration    = 0;
    my $has_upload_date = 0;
    my $dummy;
    for my $id ( keys %{$data->{$ex}{$up}} ) {

lib/App/YTDL/ChooseVideos.pm  view on Meta::CPAN

            $line .= sprintf "%s", $title;
            push @str_videos, $line;
            push @avail_ids, $id;
            $index++;
            push @$mark, $index if any { $id eq $_ } keys %$chosen_ids;
        }
        my $menu = [ @pre, @str_videos ];
        # Choose
        my @idx = choose(
            $menu,
            { prompt => $prompt . ':', layout => 3, index => 1, clear_screen => 1, mark => $mark,
              undef => $back, meta_items => [ 0 .. $#pre ], include_highlighted => 2 }
        );
        if ( ! defined $idx[0] || ! defined $menu->[$idx[0]] ) {
            if ( length $regexp ) {
                $regexp = '';
                next FILTER;
            }
            return;
        }
        my $choice = $menu->[$idx[0]];

lib/App/YTDL/ChooseVideos.pm  view on Meta::CPAN

    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//;

lib/App/YTDL/Download.pm  view on Meta::CPAN

            push @choices, $fmt_to_info->{$fmt}{format} . ' ' . $fmt_to_info->{$fmt}{ext};
            push @format_ids, $fmt;
        }
    }
    my @relative_formats = ( 'best', 'bestaudio' );
    push @choices, @relative_formats;
    push @format_ids, @relative_formats;
    my @fmt_data;

    while ( 1 ) {
        my $prompt = 'Fmt: ';
        my @pre = ( undef );
        my $menu = [ @pre, @choices ];
        # Choose
        my $idx = choose(
            $menu,
            { prompt => $prompt . join( '', @fmt_data ), index => 1, order => 1, undef => '<<', info => $title }
        );
        if ( ! defined $idx || ! defined $menu->[$idx] ) {
            return if ! @fmt_data;
            pop @fmt_data;
            pop @fmt_data;
            next;
        }

        push @fmt_data, @format_ids[ $idx - @pre ];
        my $enough = '  OK';
        @pre = ( undef, $enough );
        my $ops = [
            [ '+', "  +  " ],
            [ ',', "  ,  " ],
            [ '/', "  /  " ],
        ];
        $menu = [ @pre, map( $_->[1], @$ops ) ];
        # Choose
        my $idx_op = choose(
            $menu,
            { prompt => $prompt . join( '', @fmt_data ), undef => '  <<', info => $title, layout => 3, index => 1 }
        );
        if ( ! defined $idx_op || ! defined $menu->[$idx_op] ) {
            pop @fmt_data;
            next;
        }
        if ( $menu->[$idx_op] eq $enough ) {
            return @fmt_data;
        }
        push @fmt_data, $ops->[$idx_op - @pre][0];
    }

lib/App/YTDL/Download.pm  view on Meta::CPAN

        EXTRACTOR_KEY: for my $ex ( sort keys %$data ) {

            UPLOADER_ID: for my $up ( sort keys %{$data->{$ex}} ) {
                if ( ! exists $chosen->{$ex}{$up} ) {
                    next;
                }
                my @sorted_ids = sort { $data->{$ex}{$up}{$a}{count} <=> $data->{$ex}{$up}{$b}{count} } @{$chosen->{$ex}{$up}};
                my $keep_fmt_choices;
                if ( $qty eq 'manually' && @sorted_ids > 1 ) {
                    my ( $yes, $no ) = (  '- YES', '- NO' );
                    my $prompt = "\n" . ( $data->{$ex}{$up}{$sorted_ids[0]}{uploader} // $up ) . ':' . "\n";
                    $prompt .= 'Keep format choices?';
                    # Choose
                    my $choice = choose(
                        [ undef, $yes, $no ],
                        { prompt => $prompt, undef => '<<', layout => 3 }
                    );
                    if ( ! defined $choice ) {
                        next UPLOADER_ID;
                    }
                    elsif ( $choice eq $no ) {
                        $keep_fmt_choices = 0;
                    }
                    else {
                        $keep_fmt_choices = 1;
                    }

lib/App/YTDL/Download.pm  view on Meta::CPAN

                        }
                        elsif ( $keep_fmt_choices ) {
                            my @fmts = @fmt_data[ grep { ! ( $_ % 2 ) } 0 .. $#fmt_data ];
                            my @unavailable_fmts = grep { $_ !~ /^best/ && ! exists $data->{$ex}{$up}{$id}{fmt_to_info}{$_} } @fmts;
                            if ( @unavailable_fmts ) {
                                my $info = "\n" . $id . "\n";
                                $info .= $data->{$ex}{$up}{$id}{title} . "\n";
                                $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;

lib/App/YTDL/Download.pm  view on Meta::CPAN

            my $info = "\nDownload failed for:\n";
            for my $ex ( keys %download_failed ) {
                for my $up ( keys %{$download_failed{$ex}} ) {
                    for my $id ( @{$download_failed{$ex}{$up}} ) {
                        $info .= "$id : $data->{$ex}{$up}{$id}{title}\n";
                    }
                }
            }
            my $answer = choose(
                [ undef, 'Yes' ],
                { undef => 'No', prompt => 'Retry with a different format?', info => $info }
            );
            if ( ! $answer ) {
                last RETRY;
            }
            else {
                $qty = 'manually';
                $chosen = { %download_failed };
                next RETRY;
            }
        }

lib/App/YTDL/History.pm  view on Meta::CPAN

    return $new_h_ref;
}


sub choose_videos_from_saved_uploaders {
    my ( $set, $opt ) = @_;
    my $truncated = _to_history_size_limit( $set, $opt );
    if ( $truncated ) {
        write_json( $set->{history_file}, $set->{history} );
    }
    my $prompt = 'Chosen:' . "\n";
    my @urls;
    my $sticky  = _get_sorted_sticky( $set->{sticky} );
    my $history = _get_sorted_history( $opt, $set->{history} );

    CHANNEL: while ( 1 ) {
        my $mark = '*';
        my $confirm = '  CONFIRM';
        my $hidden  = 'Your choice:' . $mark;
        my @pre = ( $hidden, undef, $confirm );
        my $available_uploader = _available_uploader( $set, $opt, $sticky, $history );
        my $menu = [ @pre, @$available_uploader ];
        # Choose
        my @indexes = choose(
            $menu,
            { prompt => $prompt, layout => 3, index => 1, default => 1,
                undef => '  BACK', meta_items => [ 0 .. $#pre ], include_highlighted => 2 }
        );
        if ( ! defined $indexes[0] || ! defined $menu->[$indexes[0]] ) {
            if ( @urls ) {
                $prompt = 'Channels:' . "\n";
                @urls = ();
                $sticky  = _get_sorted_sticky( $set->{sticky} );
                $history = _get_sorted_history( $opt, $set->{history} );
                $mark = '*';
                next CHANNEL;
            }
            else {
                return;
            }
        }
        elsif ( $menu->[$indexes[0]] eq $hidden ) {
            for my $i ( 0 .. $#$sticky ) {
                $prompt .= sprintf "= %s (%s)\n", $sticky->[$i]{uploader}, $sticky->[$i]{uploader_id};
                push @urls, $sticky->[$i]{uploader_url};
            }
            @$sticky = ();
            $mark = '';
            next CHANNEL;
        }
        my $confirmed;
        if ( $menu->[$indexes[0]] eq $confirm ) {
            shift @indexes;
            $confirmed = 1;
        }
        my $count = 0;
        for my $i ( @indexes ) {
            $i -= @pre + $count;
            if ( $i <= $#$sticky ) {
                $prompt .= sprintf "= %s (%s)\n", $sticky->[$i]{uploader}, $sticky->[$i]{uploader_id};
                push @urls, $sticky->[$i]{uploader_url};
                splice @$sticky, $i, 1;
            }
            else {
                $i -= @$sticky;
                $prompt .= sprintf "= %s (%s)\n", $history->[$i]{uploader}, $history->[$i]{uploader_id};
                push @urls, $history->[$i]{uploader_url};
                splice @$history, $i, 1;

            }
            $count++;
        }
        $mark = '*';
        if ( $confirmed ) {
            return @urls;
        }

lib/App/YTDL/History.pm  view on Meta::CPAN

    my $sticky  = _get_sorted_sticky( $set->{sticky} );
    my $history = _get_sorted_history( $opt, $set->{history} );
    my $changed = 0;

    STICKY: while ( 1 ) {
        my @pre = ( undef );
        my $menu = [ @pre, map( "+ $_->{uploader}", @$sticky ), map( "- $_->{uploader}", @$history ) ];
        # Choose
        my $idx = choose(
            $menu,
            { prompt => 'Stickify:', layout => 3, index => 1, undef => '  <<' }
        );
        if ( ! defined $idx || ! defined $menu->[$idx] ) {
            if ( $changed ) {
                write_json( $set->{sticky_file},  $set->{sticky} );
                write_json( $set->{history_file}, $set->{history} );
            }
            return;
        }
        else {
            $changed++;

lib/App/YTDL/Options.pm  view on Meta::CPAN

    };
    eval {
        $ffprobe_version = uni_capture( $set->{ffprobe}, '-version' );
        if ( $ffprobe_version && $ffprobe_version =~ /^ffprobe version (\S+)/m ) {
            $ffprobe_version = $1;
        }
        else {
            $ffprobe_version = '';
        }
    };
    my $prompt = "INFO\n\n";
    $prompt .= "Directories:\n";
    $prompt .= "    Video : $opt->{video_dir}"   . "\n";
    $prompt .= "    Config: $set->{config_file}" . "\n";
    $prompt .= "\n";
    $prompt .= "Versions:\n";
    $prompt .= '    ' . catfile( $RealBin, $RealScript ) . ": " . $main::VERSION                 . "\n";
    $prompt .= '    ' . $set->{youtube_dl}[0]            . ": " . ( $youtube_dl_version // '?' ) . "\n";
    if ( $set->{ffmpeg} ) {
        $prompt .= '    ' . $set->{ffmpeg} . " : " . ( $ffmpeg_version // '?' ) . "\n";
    }
    if ( $set->{ffprobe} ) {
        $prompt .= '    ' . $set->{ffprobe} . ": " . ( $ffprobe_version // '?' ) . "\n";
    }
    # Choose
    choose(
        [ 'Close' ],
        { prompt => $prompt }
    );
}


sub get_defaults {
    return {
        entries_with_info            => 0,
        filename_format              => 3,
        list_sort_item               => 'upload_date',
        max_info_width               => 120,

lib/App/YTDL/Options.pm  view on Meta::CPAN


    MAIN_MENU: while ( 1 ) {
        my $back_main     = '  QUIT';
        my $continue_main = '  CONTINUE';
        my @pre  = ( undef, $continue_main );
        my @choices_main = map( $_->[1], @$main );
        my $menu_main = [ @pre, @choices_main ];
        # Choose
        my $idx_main = choose(
            $menu_main,
            { prompt => 'Options:', layout => 3, index => 1, clear_screen => 1,
              undef => $back_main, default => $old_idx_main }
        );
        if ( ! defined $idx_main || ! defined $menu_main->[$idx_main] ) {
            if ( $set->{change} ) {
                _write_config_file( $opt, $set->{config_file} );
                delete $set->{change};
            }
            exit;
        }
        if ( $old_idx_main == $idx_main ) {

lib/App/YTDL/Options.pm  view on Meta::CPAN

        }
        $old_idx_main = $idx_main;
        my $choice = $menu_main->[$idx_main];
        if ( $choice eq $continue_main ) {
            if ( $set->{change} ) {
                _write_config_file( $opt, $set->{config_file} );
                delete $set->{change};
            }
            last MAIN_MENU;
        }
        my ( $main_key, $main_prompt ) = @{$main->[$idx_main-@pre]};
        $main_prompt =~ s/^-\s//;
        if ( $main_key !~ /^group_/ ) {
            if ( $main_key eq "show_help_text" ) {
                pod2usage( { -exitval => 'NOEXIT', -verbose => 2 } );
            }
            elsif ( $main_key eq "show_info" ) {
                _show_info( $set, $opt );
            }
            elsif ( $main_key eq "avail_extractors" ) {
                say 'Close with ENTER';
                my @capture;

lib/App/YTDL/Options.pm  view on Meta::CPAN


        GROUP: while ( 1 ) {
            my $back_group     = '  <<';
            my $continue_group = '  CONTINUE';
            my @pre  = ( undef );
            my @choices_group = map( $_->[1], @$group );
            my $menu_group = [ @pre, @choices_group ];
            # Choose
            my $idx_group = choose(
                $menu_group,
                { prompt => $main_prompt, layout => 3, index => 1, clear_screen => 1, undef => $back_group, default => $old_idx_group }
            );
            if ( ! defined $idx_group || ! defined $menu_group->[$idx_group] ) {
                next MAIN_MENU;
            }
            if ( $old_idx_group == $idx_group ) {
                $old_idx_group = 0;
                next GROUP;
            }
            $old_idx_group = $idx_group;
            my $choice = $menu_group->[$idx_group];
            if ( $choice eq $continue_group ) {
                next MAIN_MENU;
            }
            my $key = $group->[$idx_group-@pre][0];
            if ( $key eq "video_dir" ) {
                my $info = "Video Directory\nNow: " . $opt->{$key} // 'current directory';
                my $name = 'New: ';
                _opt_choose_a_directory( $set, $opt, $key, $info, $name );
            }
            elsif ( $key eq "use_extractor_dir" ) {
                my $prompt = 'Use extractor directories';
                my $list = [ 'no', 'yes' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "use_uploader_dir" ) {
                my $prompt = 'Use uploader directories';
                my $list = [
                    'no',
                    'yes',
                    'if from list-menu',
                ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "filename_format" ) {
                my $prompt = 'Filename: choose the format info:';
                my $list = [
                    'none (unsafe)',
                    'video-height (unsafe)',
                    'fmt-id',
                    'fmt-id and video-height',
                    'fmt-string',
                ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "useragent" ) {
                my $prompt = 'Set the UserAgent';
                my $list = [
                    [ 'UserAgent', $opt->{useragent} ]
                ];
                _local_readline( $set, $opt, $key, $prompt, $list );
                $opt->{useragent} = '' if $opt->{useragent} eq '""';
            }
            elsif ( $key eq "quality" ) {
                my $prompt = 'Video resolution';
                my $list = [
                    'manually',
                    ' 180 or less',
                    ' 360 or less',
                    ' 720 or less',
                    '1080 or less',
                    '1440 or less',
                    '2160 or less',
                    'best'
                ];
                _opt_choose_from_list_value( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "no_height_ok" ) {
                my $prompt = 'Download videos with unkown height';
                my $list = [ 'no', 'yes' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "retries" ) {
                my $digits = 2;
                my $info = sprintf "Download retries\nNow: %${digits}s", insert_sep( $opt->{$key} );
                my $name = 'New: ';
                _opt_number_range( $set, $opt, $key, $name, $info, $digits );
            }
            elsif ( $key eq "timeout" ) {
                my $digits = 3;
                my $info = sprintf "Connection timeout (s)\nNow: %${digits}s", insert_sep( $opt->{$key} );
                my $name = 'New: ';
                _opt_number_range( $set, $opt, $key, $name, $info, $digits );
            }
            elsif ( $key eq "no_warnings" ) {
                my $prompt = 'Disable youtube-dl warnings';
                my $list = [ 'no', 'yes' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "prefer_free_formats" ) {
                my $prompt = 'Prefer free formats';
                my $list = [ 'no', 'yes' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "max_size_history" ) {
                my $digits = 3;
                my $info = sprintf "Max size of history\nNow: %${digits}s", insert_sep( $opt->{$key} );
                my $name = 'New: ';
                _opt_number_range( $set, $opt, $key, $name, $info, $digits );
            }
            elsif ( $key eq "sort_history_by_timestamp" ) {
                my $prompt = 'Sort history by';
                my $list = [ 'by name', 'by timestamp' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "entries_with_info" ) {
                my $digits = 4;
                my $sep_w = 1;
                my $w = $digits + int( ( $digits - 1 ) / 3 ) * $sep_w;
                my $info = sprintf "Number of entries with additional information\nNow: %${w}s", insert_sep( $opt->{$key} );
                my $name = 'New: ';
                _opt_number_range( $set, $opt, $key, $name, $info, $digits );
            }
            elsif ( $key eq "max_processes" ) {
                my $digits = 2;
                my $info = sprintf "Fetching additional information: the maximum number of parallel downloads\nNow: %${digits}s", insert_sep( $opt->{$key} );
                my $name = 'New: ';
                _opt_number_range( $set, $opt, $key, $name, $info, $digits );
            }
            elsif ( $key eq "list_sort_item" ) {
                set_sort_videolist( $set, $opt );
            }
            elsif ( $key eq "show_view_count" ) {
                my $prompt = 'Show the view-count in list-menus';
                my $list = [ 'if sorted by "view count"', 'always' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "show_video_id" ) {
                my $prompt = 'Show the video-id in list-menus';
                my $list = [ 'no', 'yes' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            elsif ( $key eq "max_info_width" ) {
                my $digits = 3;
                my $info = sprintf "Max Info width\nNow: %${digits}s", insert_sep( $opt->{$key} );
                my $name = 'New: ';
                _opt_number_range( $set, $opt, $key, $name, $info, $digits );
            }
            elsif ( $key eq "max_rows_description" ) {
                my $digits = 2;
                my $info = sprintf "Max Rows of description\nNow: %${digits}s", insert_sep( $opt->{$key} );

lib/App/YTDL/Options.pm  view on Meta::CPAN

                }
                else {
                    $info .= 'default (';
                    $info .= $^O eq 'MSWin32' ? "%APPDATA%/youtube-dl/config.txt" : "~/.config/youtube-dl/config";
                    $info .= ')';
                }
                my $name = 'New: ';
                _opt_choose_a_file( $set, $opt, $key, $info, $name );
            }
            elsif ( $key eq "_reset_yt_dl_config_location" ) {
                my $prompt = 'Reset the youtube-dl config location to default';
                my $list = [ 'no', 'yes' ];
                $opt->{_reset_yt_dl_config_location} = 0;
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
                if ( $opt->{_reset_yt_dl_config_location} ) {
                    $opt->{yt_dl_config_location} = undef;
                }
                delete $opt->{_reset_yt_dl_config_location};
            }
            elsif ( $key eq "yt_dl_ignore_config" ) {
                my $prompt = 'Ignore youtube-dl config file';
                my $list = [ 'no', 'yes' ];
                _opt_choose_from_list_idx( $set, $opt, $key, $prompt, $list );
            }
            else { die $key }
        }
    }
    return;
}


sub _opt_settings_menu {
    my ( $set, $opt, $sub_menu, $current, $prompt ) = @_;
    # Settings_menu
    my $changed = settings_menu( $sub_menu, $current, { prompt => $prompt } );
    return if ! $changed;
    for my $key ( keys %$current ) {
        $opt->{$key} = $current->{$key};
    }
    $set->{change}++;
}


sub _opt_choose_a_directory {
    my( $set, $opt, $key, $info, $name ) = @_;

lib/App/YTDL/Options.pm  view on Meta::CPAN

    return if ! defined $new_dir;
    if ( $new_dir ne $opt->{$key} ) {
        if ( ! eval {
            my $fh = File::Temp->new( TEMPLATE => 'XXXXXXXXXXXXXXX', UNLINK => 1, DIR => $new_dir ); ##
            1 }
        ) {
            print "$@";
            # Choose
            choose(
                [ 'Press Enter:' ],
                { prompt => '' }
            );
        }
        else {
            $opt->{$key} = $new_dir;
            $set->{change}++;
        }
    }
}


lib/App/YTDL/Options.pm  view on Meta::CPAN

    my( $set, $opt, $key, $info, $name ) = @_;
    # Choose_a_file
    my $file = choose_a_file( { cs_label => $name, info => $info } );
    return if ! defined $file;
    $opt->{$key} = $file;
    $set->{change}++;
}


sub _local_readline {
    my ( $set, $opt, $key, $prompt, $list ) = @_;
    # Fill_form
    my $trs = Term::Form->new();
    my $new_list = $trs->fill_form(
        $list,
        { prompt => $prompt, auto_up => 2, confirm => 'CONFIRM', back => 'BACK   ' }
    );
    if ( $new_list ) {
        for my $i ( 0 .. $#$new_list ) {
            $opt->{$key} = $new_list->[$i][1];
        }
        $set->{change}++;
    }
}


lib/App/YTDL/Options.pm  view on Meta::CPAN

    # Choose_a_number
    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 {



( run in 2.026 seconds using v1.01-cache-2.11-cpan-6aa56a78535 )