App-YTDL

 view release on metacpan or  search on metacpan

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

package # hide from PAUSE
App::YTDL::Video_Info;

use warnings;
use strict;
use 5.010000;

use Exporter qw( import );
our @EXPORT_OK = qw( print_video_infos );

use List::MoreUtils        qw( none );
use Term::ANSIScreen       qw( :cursor :screen );
use Term::Choose::LineFold qw( line_fold print_columns cut_to_printwidth );
use Term::Choose::Util     qw( get_term_size );

use App::YTDL::GetData     qw( get_download_info );
use App::YTDL::ExtractData qw( extract_data_single );


sub print_video_infos {
    my ( $set, $opt, $data, $chosen ) = @_;
    if ( ! %$data ) {
        return;
    }
    my ( $cols, $rows ) = get_term_size();
    print "\n\n\n\n", '=' x $cols, "\n\n", "\n" x $rows;
    print locate( 1, 1 ), cldown;
    say 'Quality: ', $opt->{quality};
    say 'Agent  : ', $opt->{useragent} if $opt->{useragent};
    print "\n";
    my $count = 0;

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

        UPLOADER_ID: for my $up ( sort keys %{$data->{$ex}} ) {

            VIDEO_ID: for my $id ( @{$chosen->{$ex}{$up}} ) {
                $count++;
                my $key_len = 12;
                $data->{$ex}{$up}{$id}{count} = $count;
                my @print_array = _linefolded_print_info( $set, $opt, $data, $ex, $up, $id, $key_len );
                print "\r", clline;
                printf "%*.*s : %s\n", $key_len, $key_len, 'video', $count;
                say for @print_array;
                print "\n";
            }
        }
    }
    #print "\n";
    if ( $count == 0 ) {
        print cls;
    }
    return;
}


sub _prepare_print_info {
    my ( $set, $opt, $data, $ex, $up, $id ) = @_;
    my @keys = qw(title author duration raters avg_rating view_count published id_extractor description);
    if ( ! exists $data->{$ex}{$up}{$id}{fmt_to_info} ) {
        my $url = $data->{$ex}{$up}{$id}{url};
        print "\r** GET video data: ... ";
        my $h_ref;
        if ( eval { $h_ref = get_download_info( $set, $opt, $url, 0 ); 1 } ) {
            my $single_data = extract_data_single( $set, $opt, $h_ref );
            for my $key ( keys %$single_data ) {
                $data->{$ex}{$up}{$id}{$key} = $single_data->{$key};
            }
        }
        else {
            $data->{$ex}{$up}{$id}{description} = $set->{failed_fetching_data};
        }



( run in 0.518 second using v1.01-cache-2.11-cpan-39bf76dae61 )