1515# -------------------------------------------------------
1616# GTK YouTube Viewer
1717# Created on: 12 September 2010
18- # Latest edit on: 07 January 2021
18+ # Latest edit on: 05 March 2021
1919# https://github.com/trizen/youtube-viewer
2020# -------------------------------------------------------
2121
@@ -135,19 +135,21 @@ sub which_command {
135135}
136136
137137my %symbols = (
138- up_arrow => ' ↑' ,
139- down_arrow => ' ↓' ,
140- diamond => ' ❖' ,
141- face => ' ☺' ,
142- black_face => ' ☻' ,
143- average => ' x̄' ,
144- ellipsis => ' …' ,
145- play => ' ▶' ,
146- views => ' ◈' ,
147- heart => ' ❤' ,
148- right_arrow => ' →' ,
149- crazy_arrow => ' ↬' ,
150- numero => ' №' ,
138+ thumbs_up => ' 👍' ,
139+ thumbs_down => ' 👎' ,
140+ type => ' 💡' ,
141+ author => ' 😃' ,
142+ author_id => ' 🤖' ,
143+ average => ' 📊' ,
144+ category => ' 🗃️' ,
145+ play => ' ▶️' ,
146+ views => ' 👀' ,
147+ heart => ' ❤️' ,
148+ published => ' ⏱️' ,
149+ updated => ' ✨' ,
150+ numero => ' #️⃣' ,
151+ video => ' 🎞️' ,
152+ subs => ' 👪' ,
151153 );
152154
153155# Main configuration
@@ -1005,6 +1007,12 @@ sub apply_configuration {
10051007
10061008 # Select text from text entry
10071009 $search_entry -> select_region(0, -1);
1010+
1011+ # Create the "Saved videos" playlists if it does not exists
1012+ if (defined ($CONFIG {saved_videos_file }) and not -e $CONFIG {saved_videos_file }) {
1013+ open (my $fh , ' >' , $CONFIG {saved_videos_file });
1014+ close $fh ;
1015+ }
10081016}
10091017
10101018# Apply the configuration file
@@ -2840,6 +2848,7 @@ sub display_results {
28402848
28412849 my @video_ids ;
28422850 my @playlist_ids ;
2851+ my @channel_ids ;
28432852
28442853 foreach my $i (0 .. $# {$items }) {
28452854 my $item = $items -> [$i ];
@@ -2850,6 +2859,9 @@ sub display_results {
28502859 elsif ($yv_utils -> is_video($item )) {
28512860 push @video_ids , $yv_utils -> get_video_id($item );
28522861 }
2862+ elsif ($yv_utils -> is_channel($item )) {
2863+ push @channel_ids , $yv_utils -> get_channel_id($item );
2864+ }
28532865 }
28542866
28552867 my %id_lookup ;
@@ -2858,17 +2870,26 @@ sub display_results {
28582870 my $content_details = $yv_obj -> video_details(join (' ,' , @video_ids ), VIDEO_PART);
28592871 my $video_details = $content_details -> {results }{items };
28602872
2861- foreach my $i (0 .. $#video_ids ) {
2862- $id_lookup {$video_ids [ $i ]} = $video_details -> [ $i ] ;
2873+ foreach my $video ( @$video_details ) {
2874+ $id_lookup {$video -> { id }} = $video ;
28632875 }
28642876 }
28652877
28662878 if (@playlist_ids ) {
28672879 my $content_details = $yv_obj -> playlist_from_id(join (' ,' , @playlist_ids ), ' contentDetails' );
28682880 my $playlist_details = $content_details -> {results }{items };
28692881
2870- foreach my $i (0 .. $#playlist_ids ) {
2871- $id_lookup {$playlist_ids [$i ]} = $playlist_details -> [$i ];
2882+ foreach my $playlist (@$playlist_details ) {
2883+ $id_lookup {$playlist -> {id }} = $playlist ;
2884+ }
2885+ }
2886+
2887+ if (@channel_ids ) {
2888+ my $content_details = $yv_obj -> channel_from_id(join (' ,' , @channel_ids ), ' statistics,snippet,id' );
2889+ my $channel_details = $content_details -> {results }{items };
2890+
2891+ foreach my $channel (@$channel_details ) {
2892+ $id_lookup {$channel -> {id }} = $channel ;
28722893 }
28732894 }
28742895
@@ -2890,6 +2911,14 @@ sub display_results {
28902911 add_playlist_entry($item );
28912912 }
28922913 elsif ($yv_utils -> is_channel($item )) {
2914+
2915+ my $channel_id = $yv_utils -> get_channel_id($item ) || next ;
2916+
2917+ if (exists ($info -> {__extra_info__ }{$channel_id })) {
2918+ @{$item }{qw( statistics snippet) } =
2919+ @{$info -> {__extra_info__ }{$channel_id }}{qw( statistics snippet) };
2920+ }
2921+
28932922 add_channel_entry($item );
28942923 }
28952924 elsif ($yv_utils -> is_subscription($item )) {
@@ -2971,14 +3000,14 @@ sub add_subscription_entry {
29713000 ' <big><b>'
29723001 . encode_entities($title )
29733002 . " </b></big>\n\n "
2974- . " <b> $symbols {face }\t </b> "
3003+ . " $symbols {author }\t "
29753004 . encode_entities($channel_id ) . " \n "
2976- . " <b> $symbols {crazy_arrow }\t </b> "
3005+ . " $symbols {updated }\t "
29773006 . $yv_utils -> get_publication_date($subscription )
29783007 . " \n\n <i>"
29793008 . encode_entities($row_description ) . ' </i>' ;
29803009
2981- my $type_label = " <b> $symbols {diamond}</b> " . ' Subscription' . " \n " ;
3010+ my $type_label = " $symbols {type} \t " . ' Subscription' . " \n " ;
29823011
29833012 $liststore -> set(
29843013 $iter ,
@@ -3012,30 +3041,38 @@ sub add_video_entry {
30123041
30133042 set_entry_tooltip($iter , $title , $description );
30143043
3015- my $title_label =
3016- reflow_text( " <big><b>"
3017- . encode_entities($title )
3018- . " </b></big>\n "
3019- . " <b>$symbols {up_arrow}\t </b> "
3020- . $yv_utils -> set_thousands($yv_utils -> get_likes($video )) . " \n "
3021- . " <b>$symbols {down_arrow}\t </b> "
3022- . $yv_utils -> set_thousands($yv_utils -> get_dislikes($video )) . " \n "
3023- . " <b>$symbols {ellipsis}\t </b> "
3024- . encode_entities($yv_utils -> get_category_name($video )) . " \n "
3025- . " <b>$symbols {face}\t </b> "
3026- . encode_entities($yv_utils -> get_channel_title($video )) . " \n " . " <i>"
3027- . encode_entities($row_description )
3028- . " </i>" );
3029-
3030- my $info_label =
3031- reflow_text( " <b>$symbols {play}\t </b> "
3032- . $yv_utils -> get_time($video ) . " \n "
3033- . " <b>$symbols {diamond}\t </b> "
3034- . $yv_utils -> get_definition($video ) . " \n "
3035- . " <b>$symbols {views}\t </b> "
3036- . $yv_utils -> set_thousands($yv_utils -> get_views($video )) . " \n "
3037- . " <b>$symbols {right_arrow}\t </b>"
3038- . $yv_utils -> get_publication_date($video ));
3044+ my $title_label = reflow_text(
3045+ sprintf (
3046+ " <big><b>%s </b></big>
3047+ $symbols {thumbs_up}\t %s
3048+ $symbols {thumbs_down}\t %s
3049+ $symbols {category}\t %s
3050+ $symbols {author}\t %s
3051+ <i>%s </i>" ,
3052+
3053+ encode_entities($title ),
3054+ $yv_utils -> set_thousands($yv_utils -> get_likes($video )),
3055+ $yv_utils -> set_thousands($yv_utils -> get_dislikes($video )),
3056+ encode_entities($yv_utils -> get_category_name($video )),
3057+ encode_entities($yv_utils -> get_channel_title($video )),
3058+ encode_entities($row_description ),
3059+ )
3060+ );
3061+
3062+ my $info_label = reflow_text(
3063+ sprintf (
3064+ " $symbols {play}\t %s
3065+ $symbols {type}\t %s
3066+ $symbols {views}\t %s
3067+ $symbols {published}\t %s " ,
3068+
3069+ $yv_utils -> get_time($video ),
3070+ $yv_utils -> get_definition($video ),
3071+ $yv_utils -> set_thousands($yv_utils -> get_views($video )),
3072+ $yv_utils -> get_publication_date($video ),
3073+
3074+ )
3075+ );
30393076
30403077 $liststore -> set(
30413078 $iter ,
@@ -3064,21 +3101,34 @@ sub add_channel_entry {
30643101
30653102 set_entry_tooltip($iter , $title , $description );
30663103
3067- my $title_label =
3068- reflow_text( ' <big><b>'
3069- . encode_entities($title )
3070- . " </b></big>\n\n "
3071- . " <b>$symbols {face}\t </b> "
3072- . encode_entities($yv_utils -> get_channel_title($channel )) . " \n "
3073- . " <b>$symbols {play}\t </b> "
3074- . encode_entities($channel_id ) . " \n "
3075- . " <b>$symbols {crazy_arrow}\t </b> "
3076- . $yv_utils -> get_publication_date($channel )
3077- . " \n\n <i>"
3078- . encode_entities($row_description )
3079- . ' </i>' );
3080-
3081- my $type_label = reflow_text(" <b>$symbols {diamond}</b> " . ' Channel' . " \n " );
3104+ my $title_label = reflow_text(
3105+ sprintf (
3106+ " <big><b>%s </b></big>
3107+
3108+ $symbols {author}\t %s
3109+ $symbols {play}\t %s
3110+ $symbols {published}\t %s
3111+
3112+ <i>%s </i>" ,
3113+
3114+ encode_entities($title ),
3115+ encode_entities($title ),
3116+ encode_entities($channel_id ),
3117+ $yv_utils -> get_publication_date($channel ),
3118+ encode_entities($row_description ),
3119+ )
3120+ );
3121+
3122+ my $type_label = reflow_text(
3123+ sprintf (
3124+ " $symbols {type}\t Channel
3125+ $symbols {video}\t %s videos
3126+ $symbols {subs}\t %s subs" ,
3127+
3128+ $yv_utils -> set_thousands($yv_utils -> get_channel_video_count($channel ) // 0),
3129+ $yv_utils -> short_human_number($yv_utils -> get_channel_subscriber_count($channel ) // 0),
3130+ )
3131+ );
30823132
30833133 $liststore -> set(
30843134 $iter ,
@@ -3108,26 +3158,31 @@ sub add_playlist_entry {
31083158
31093159 set_entry_tooltip($iter , $title , $description );
31103160
3111- my $title_label =
3112- reflow_text( ' <big><b>'
3113- . encode_entities($title )
3114- . " </b></big>\n\n "
3115- . " <b>$symbols {face}\t </b> "
3116- . encode_entities($channel_title ) . " \n "
3117- . " <b>$symbols {play}\t </b> "
3118- . encode_entities($playlist_id ) . " \n "
3119- . " <b>$symbols {crazy_arrow}\t </b> "
3120- . $yv_utils -> get_publication_date($playlist ) . " \n\n " . ' <i>'
3121- . encode_entities($row_description )
3122- . ' </i>' );
3161+ my $title_label = reflow_text(
3162+ sprintf (
3163+ " <big><b>%s </b></big>
31233164
3124- my $num_items_text = $yv_utils -> get_playlist_item_count($playlist ) // " " ;
3165+ $symbols {author}\t %s
3166+ $symbols {play}\t %s
31253167
3126- if ($num_items_text ne ' ' ) {
3127- $num_items_text = sprintf (" <b>$symbols {numero}</b> %d items\n " , $num_items_text );
3128- }
3168+ <i>%s </i>" ,
31293169
3130- my $type_label = reflow_text(" <b>$symbols {diamond}</b> " . ' Playlist' . " \n " . $num_items_text );
3170+ encode_entities($title ),
3171+ encode_entities($channel_title ),
3172+ $playlist_id ,
3173+ encode_entities($row_description ),
3174+ )
3175+ );
3176+
3177+ my $type_label = reflow_text(
3178+ sprintf (
3179+ " $symbols {type}\t Playlist
3180+ $symbols {video}\t %s videos
3181+ $symbols {published}\t %s " ,
3182+ $yv_utils -> set_thousands($yv_utils -> get_playlist_item_count($playlist ) // 0),
3183+ $yv_utils -> get_publication_date($playlist ),
3184+ )
3185+ );
31313186
31323187 $liststore -> set(
31333188 $iter ,
@@ -3842,28 +3897,44 @@ sub show_playlists_from_selected_author {
38423897sub set_entry_details {
38433898 my ($code , $iter ) = @_ ;
38443899
3845- my $type = $liststore -> get($iter , 7);
3846- my $main_details = $liststore -> get($iter , 0);
3847- my $channel_id = get_channel_id_for_selected_video();
3900+ # Currently, only video entries are supported.
3901+
3902+ my $type = $liststore -> get($iter , 7);
3903+ my $info = $yv_obj -> parse_json_string($liststore -> get($iter , 8));
38483904
38493905 # Setting title
3850- my $title = substr ($main_details , 0, index ($main_details , ' </big>' ) + 6, ' ' );
3851- $gui -> get_object(' video_title_label' )-> set_label(" <big>$title </big>" );
3852- $gui -> get_object(' video_title_label' )-> set_tooltip_markup(" $title " );
3906+ my $title = encode_entities($yv_utils -> get_title($info ));
3907+ $gui -> get_object(' video_title_label' )-> set_label(" <big><big><b>$title </b></big></big>" );
3908+ $gui -> get_object(' video_title_label' )-> set_tooltip_markup(" <b>$title </b>" );
3909+
3910+ my $details_format = <<"EOT" ;
3911+ $symbols {thumbs_up}\t %s
3912+ $symbols {thumbs_down}\t %s
3913+ $symbols {author}\t %s
3914+ $symbols {category}\t %s
3915+ $symbols {play}\t %s
3916+ $symbols {average}\t %s
3917+ $symbols {views}\t %s
3918+ $symbols {published}\t %s
3919+ $symbols {author_id}\t %s
3920+ EOT
38533921
3854- # Setting video details
3855- $main_details =~ s / ^\s +// ;
3856- $main_details =~ s {\s *<i>.+</i>\s *} { \n } ;
3857- $main_details =~ s {\h +} { } g ;
3858- $main_details =~ s { ^.*?<b>.*?</b>\K\h *} { \t } gm ;
3922+ my $likes = $yv_utils -> get_likes($info );
3923+ my $dislikes = $yv_utils -> get_dislikes($info );
3924+ my $rating = 1;
38593925
3860- my $secondary_details = $liststore -> get($iter , 2);
3861- $secondary_details =~ s {\h +} { } g ;
3862- $secondary_details =~ s { ^.*?<b>.*?</b>\K\h *} { \t } gm ;
3863- $secondary_details .= " \n $symbols {black_face}\t $channel_id " ;
3926+ if ($likes > 0) {
3927+ $rating = sprintf (' %.2f' , $likes / ($likes + $dislikes ) * 4 + 1);
3928+ }
3929+
3930+ my $text_info = sprintf ($details_format ,
3931+ $yv_utils -> set_thousands($likes ), $yv_utils -> set_thousands($dislikes ),
3932+ $yv_utils -> get_channel_title($info ), $yv_utils -> get_category_name($info ),
3933+ $yv_utils -> get_time($info ), $rating ,
3934+ $yv_utils -> set_thousands($yv_utils -> get_views($info )), $yv_utils -> get_publication_date($info ),
3935+ $yv_utils -> get_channel_id($info ),);
38643936
3865- my $text_info = join (" \n " , grep { !/^&# \w+;$/ } split(/\R/, "$main_details$secondary_details"));
3866- $gui -> get_object(' video_details_label' )-> set_label($text_info );
3937+ $gui -> get_object(' video_details_label' )-> set_label(" <big>" . encode_entities(" \n " . $text_info ) . " </big>" );
38673938
38683939 # Setting the link button
38693940 my $url = make_youtube_url($type , $code );
@@ -3872,8 +3943,6 @@ sub set_entry_details {
38723943 $linkbutton -> set_label($url );
38733944 $linkbutton -> set_uri($url );
38743945
3875- my $info = $yv_obj -> parse_json_string($liststore -> get($iter , 8));
3876-
38773946 # Getting thumbs
38783947 foreach my $nr (qw( 1 2 3) ) {
38793948
0 commit comments