App-YTDL

 view release on metacpan or  search on metacpan

bin/getvideo  view on Meta::CPAN

$set->{youtube_dl} = [ $youtube_dl ];

read_config_file( $opt, $set->{config_file} );
set_options( $set, $opt ) if $help;

push @{$set->{youtube_dl}}, '--config-location', $opt->{yt_dl_config_location}  if $opt->{yt_dl_config_location};
push @{$set->{youtube_dl}}, '--ignore-config',                                  if $opt->{yt_dl_ignore_config};
push @{$set->{youtube_dl}}, '--no-warnings'                                     if $opt->{no_warnings};
push @{$set->{youtube_dl}}, '--user-agent',      $opt->{useragent}              if defined $opt->{useragent};
push @{$set->{youtube_dl}}, '--retries',         $opt->{retries}                if defined $opt->{retries};
push @{$set->{youtube_dl}}, '--socket-timeout',  $opt->{timeout}                if defined $opt->{timeout};
push @{$set->{youtube_dl}}, '--prefer-free-formats'                             if $opt->{prefer_free_formats};


local $| = 1;
print locate( 1, 1 ), cldown;


read_history_files( $set, $opt );


my @ids = @ARGV;

for my $file ( @$arg_file ) {
    open my $fh, '<:encoding(utf-8)', $file or die $!;
    while ( my $line = <$fh> ) {
        next if $line =~ /^\s*\z/;
        next if $line =~ /^\s*#/;
        $line =~ s/^\s+|\s+\z//g;
        push @ids, split /\s+/, $line;
    }
    close $fh or die $!;
}

if ( ! @ids ) {
    my $trs = Term::Form->new();
    my $ids = $trs->readline( 'Enter url/id: ' );
    @ids = split /\s+/, $ids;
    print up( 1 ), cldown;
}

my $urls_data = {};
my $data = {};

if ( @ids ) {
    my $chosen = from_arguments_to_choices( $set, $opt, $urls_data, $data, @ids );
    print_video_infos( $set, $opt, $data, $chosen );
    download( $set, $opt, $data, $chosen );
    add_uploaders_to_history( $set, $opt, $data ) if $opt->{max_size_history};
}
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;
        #    }
        #    $old_idx = $idx;
        #}
        if ( $menu->[$idx] eq $uploader ) {
            my @chosen_uploaders = choose_videos_from_saved_uploaders( $set, $opt );
            next if ! @chosen_uploaders;
            my $chosen = from_arguments_to_choices( $set, $opt, $urls_data, $data, @chosen_uploaders );
            print_video_infos( $set, $opt, $data, $chosen );
            my $total = download( $set, $opt, $data, $chosen );
            $clear_screen = $total ? 0 : 1;
            say "";
        }
        elsif ( $menu->[$idx] eq $sticky ) {
           edit_sticky_file( $set, $opt );
        }
    }
}


if ( ! @ids ) {
    say "No arguments" and exit;
}



__END__

=pod

=encoding UTF-8

=head1 NAME

getvideo - Download YouTube and other videos.

=head1 VERSION

Version 0.417

=cut

=head1 SYNOPSIS

    getvideo -h|-?|--help

    getvideo

    getvideo url [url ...]

    getvideo -f|--file filename



( run in 0.730 second using v1.01-cache-2.11-cpan-0b5f733616e )