aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authortrizen <trizen@protonmail.com>2020-10-05 22:00:21 +0300
committerJesús <heckyel@hyperbola.info>2020-11-09 16:07:10 -0500
commit9838963cf2aab02241a37cee7d305025dc694d90 (patch)
tree3241214473b1295ffd3c28829814e04210309bfa /bin
parentbe00b89005ffc38f257848b47d2e4a0b2a536c44 (diff)
downloadfair-viewer-9838963cf2aab02241a37cee7d305025dc694d90.tar.lz
fair-viewer-9838963cf2aab02241a37cee7d305025dc694d90.tar.xz
fair-viewer-9838963cf2aab02241a37cee7d305025dc694d90.zip
- Implemented support for trending categories.
Example: fair-viewer --trending # trending videos fair-viewer --trending=music # trending music videos fair-viewer -c # list trending categories In the Gtk version, the trending categories are listed in the "Categories" tab. - Several internal code tweaks and improvements. Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fair-viewer84
-rwxr-xr-xbin/gtk-fair-viewer101
2 files changed, 27 insertions, 158 deletions
diff --git a/bin/fair-viewer b/bin/fair-viewer
index c72db85..a9f412b 100755
--- a/bin/fair-viewer
+++ b/bin/fair-viewer
@@ -197,7 +197,6 @@ my %CONFIG = (
comments_order => 'top', # valid values: top, new
subscriptions_order => 'relevance', # valid values: alphabetical, relevance, unread
- hl => 'en_US',
region => undef,
# URI options
@@ -661,7 +660,6 @@ usage: $execname [options] ([url] | [keywords])
* Categories
-c --categories : display the available YouTube categories
- -hl --catlang=s : language for categories (default: en_US)
* Region
--region=s : set the region code (default: US)
@@ -687,7 +685,8 @@ usage: $execname [options] ([url] | [keywords])
-ua --activities:s : show activity events for a given channel
* Trending
- --trending:s : show trending videos in a given category ID or name
+ --trending:s : show trending videos in a given category
+ valid categories: music gaming news movies
* Channels
-sc --channels : search for YouTube channels
@@ -1110,7 +1109,7 @@ sub apply_configuration {
videoDefinition
videoDimension videoDuration
date order
- channelId region debug hl
+ channelId region debug
http_proxy page comments_order
subscriptions_order user_agent
cookie_file timeout ytdl ytdl_cmd
@@ -1129,20 +1128,6 @@ sub apply_configuration {
}
}
- if (defined $opt->{category_id}) {
-
- my $str = delete $opt->{category_id};
- my $category = extract_category($str);
-
- if (ref($category) eq 'HASH') {
- say ":: Category selected: $category->{snippet}{title}" if $yv_obj->get_debug;
- $yv_obj->set_videoCategoryId($category->{id});
- }
- else {
- warn_invalid('category', $str);
- }
- }
-
if (defined $opt->{hd}) {
$yv_obj->set_videoDefinition(delete($opt->{hd}) ? 'high' : 'any');
}
@@ -1306,19 +1291,7 @@ sub apply_configuration {
}
if (defined $opt->{trending}) {
-
- my $str = delete $opt->{trending};
- my $category = extract_category($str);
- my $cat_id = undef;
-
- if (ref($category) eq 'HASH') {
- say ":: Category selected: $category->{snippet}{title}" if $yv_obj->get_debug;
- $cat_id = $category->{id};
- }
- elsif ($str) {
- warn_invalid('category', $str);
- }
-
+ my $cat_id = delete $opt->{trending};
print_videos($yv_obj->trending_videos_from_category($cat_id));
}
@@ -1519,8 +1492,6 @@ sub parse_arguments {
'user-agent|agent=s' => \$opt{user_agent},
'http-proxy|https-proxy|proxy=s' => \$opt{http_proxy},
- 'catlang|cl|hl=s' => \$opt{hl},
- 'category|cat-id|cat=s' => \$opt{category_id},
'r|region|region-code=s' => \$opt{region},
'order|order-by|sort|sort-by=s' => \$opt{order},
@@ -1715,34 +1686,6 @@ sub get_valid_playlist_id {
return $id;
}
-sub extract_category {
- my ($str) = @_;
-
- $str || return;
-
- state $results = $yv_obj->video_categories;
- return if ref($results) ne 'HASH';
-
- my $categories = $results->{items};
- return if ref($categories) ne 'ARRAY';
-
- foreach my $category (@$categories) {
- if ($category->{id} eq $str) {
- return $category;
- }
- }
-
- my $str_re = qr/\Q$str\E/i;
-
- foreach my $category (@$categories) {
- if ($yv_utils->get_title($category) =~ /$str_re/) {
- return $category;
- }
- }
-
- return;
-}
-
sub extract_channel_id {
my ($str) = @_;
@@ -2448,10 +2391,9 @@ sub valid_num {
sub adjust_width {
my ($str, $len, $prepend) = @_;
- $len > 0 or do {
- warn "[WARN] Insufficient space for the title: increase your terminal width!\n";
+ if ($len <= 0) {
return $str;
- };
+ }
state $pkg = (
eval {
@@ -2749,18 +2691,14 @@ sub print_comments {
sub print_categories {
my ($results) = @_;
- return if ref($results) ne 'HASH';
- my $categories = $results->{items};
+ my $categories = $results;
return if ref($categories) ne 'ARRAY';
my $i = 0;
print "\n" if @{$categories};
- # Filter out nonassignable categories
- @$categories = grep { $_->{snippet}{assignable} } @$categories;
-
foreach my $category (@{$categories}) {
- printf "%s. %-40s (id: %s)\n", colored(sprintf('%2d', ++$i), 'bold'), $yv_utils->get_title($category), $category->{id};
+ printf "%s. %-40s\n", colored(sprintf('%2d', ++$i), 'bold'), $category->{title};
}
my @keywords = get_input_for_categories();
@@ -2796,11 +2734,7 @@ sub print_categories {
elsif (valid_num($key, $categories)) {
my $category = $categories->[$key - 1];
my $cat_id = $category->{id};
- my $videos = $yv_obj->videos_from_category($cat_id);
-
- if (not $yv_utils->has_entries($videos)) {
- $videos = $yv_obj->trending_videos_from_category($cat_id);
- }
+ my $videos = $yv_obj->trending_videos_from_category($cat_id);
print_videos($videos);
}
diff --git a/bin/gtk-fair-viewer b/bin/gtk-fair-viewer
index 3274ce2..bafdc12 100755
--- a/bin/gtk-fair-viewer
+++ b/bin/gtk-fair-viewer
@@ -186,20 +186,19 @@ my %CONFIG = (
# Fair options
dash_support => 1,
dash_mp4_audio => 1,
- dash_segmented => 1, # may load slow
+ dash_segmented => 1, # may load slow
prefer_mp4 => 0,
prefer_av1 => 0,
ignore_av1 => 0,
maxResults => 10,
- hfr => 1, # true to prefer high frame rate (HFR) videos
+ hfr => 1, # true to prefer high frame rate (HFR) videos
resolution => 'best',
videoDimension => undef,
videoLicense => undef,
- hl => 'en_US',
region => undef,
- comments_width => 80, # wrap comments longer than `n` characters
- comments_order => 'top', # valid values: time, relevance
+ comments_width => 80, # wrap comments longer than `n` characters
+ comments_order => 'top', # valid values: time, relevance
# API
api_host => "auto",
@@ -338,7 +337,6 @@ my %objects = (
'treeviewcolumn2' => \my $thumbs_column,
'textview2' => \my $textview_help,
'from_author_entry' => \my $from_author_entry,
- 'category_id_entry' => \my $category_id_entry,
'more_options_expander' => \my $more_options_expander,
'notebook1' => \my $notebook,
'comboboxtext9' => \my $resolution_combobox,
@@ -352,9 +350,7 @@ my %objects = (
'comboboxtext6' => \my $panel_account_type_combobox,
'comboboxtext2' => \my $order_combobox,
'comboboxtext7' => \my $channel_type_combobox,
- 'videos_checkbox' => \my $search_for_videos_checkbox,
- 'playlists_checkbox' => \my $search_for_playlists_checkbox,
- 'channels_checkbox' => \my $search_for_channels_checkbox,
+ 'comboboxtext10' => \my $search_for_combobox,
'spinbutton1' => \my $spin_results,
'spinbutton2' => \my $spin_start_with_page,
'thumbs_checkbutton' => \my $thumbs_checkbutton,
@@ -822,7 +818,6 @@ my $yv_obj = WWW::FairViewer->new(
config_dir => $config_dir,
ytdl => $CONFIG{ytdl},
ytdl_cmd => $CONFIG{ytdl_cmd},
- hl => $CONFIG{hl},
env_proxy => $CONFIG{env_proxy},
cache_dir => $CONFIG{cache_dir},
cookie_file => $CONFIG{cookie_file},
@@ -852,9 +847,6 @@ $order_combobox->set_active(0);
# Spin button start with page
$spin_start_with_page->set_value(1);
-# Set search for videos
-$search_for_videos_checkbox->set_active(1);
-
sub apply_configuration {
# Fullscreen mode
@@ -875,14 +867,11 @@ sub apply_configuration {
foreach my $option_name (
qw(
- api_host
videoSyndicated comments_order
- maxResults videoDimension
- videoLicense
- region videoCategoryId
- debug http_proxy user_agent
+ maxResults videoDimension videoLicense
+ region debug http_proxy user_agent
timeout cookie_file ytdl ytdl_cmd
- prefer_mp4 prefer_av1
+ api_host prefer_mp4 prefer_av1
)
) {
@@ -1703,6 +1692,7 @@ sub combobox_definition_changed {
}
sub combobox_published_within_changed {
+
my $period = $published_within_combobox->get_active_text;
if ($period =~ /^any/) {
@@ -1781,17 +1771,15 @@ sub add_category_header {
sub append_categories {
my ($categories, $type) = @_;
- foreach my $category (@{$categories->{items}}) {
+ foreach my $category (@$categories) {
- # Ignore nonassignable categories
- $category->{snippet}{assignable} || next;
-
- my $label = $yv_utils->get_title($category);
+ my $label = $category->{title};
my $id = $category->{id};
$label =~ s{&}{&amp;}g;
my $iter = $cats_liststore->append;
+
$cats_liststore->set(
$iter,
0 => $label,
@@ -1803,33 +1791,7 @@ sub append_categories {
return 1;
}
-#<<<
-#~ {
- # Standard categories:
- #~ add_category_header("Categories");
-
- #~ my $cats = $yv_obj->video_categories();
- #~ if (ref($cats) eq 'HASH' and ref($cats->{items}) eq 'ARRAY') {
-
- #~ my $help_text = '';
- #~ foreach my $cat (sort { $a->{id} <=> $b->{id} } @{$cats->{items}}) {
- #~ $cat->{snippet}{assignable} || next;
- #~ $help_text .= sprintf("%2d - %s\n", $cat->{id}, $yv_utils->get_title($cat));
- #~ }
-
- #~ # Set tooltip text for "CategoryID" entry
- #~ chomp($help_text);
- #~ $category_id_entry->set_tooltip_text($help_text);
-
- #~ # Append the categories to the "Categories" tab
- #~ append_categories($cats, 'cat');
- #~ }
-
- # EDU categories:
- #add_category_header("EDU Categories");
- #append_categories($yv_obj->get_educategories(), 'edu-cat');
-#~ }
-#>>>
+append_categories($yv_obj->video_categories, 'cat');
my $tops_liststore = $gui->get_object('liststore6');
my $tops_treeview = $gui->get_object('treeview4');
@@ -2285,29 +2247,7 @@ sub search {
$yv_obj->set_channelId();
}
- # Set the category ID
- my $category_id = $category_id_entry->get_text;
- if ($category_id =~ /^\d+\z/) {
- $yv_obj->set_videoCategoryId($category_id);
- }
- else {
- $yv_obj->set_videoCategoryId();
- }
-
- my @types;
- if ($search_for_playlists_checkbox->get_active) {
- push @types, 'playlist';
- }
-
- if ($search_for_channels_checkbox->get_active) {
- push @types, 'channel';
- }
-
- if ($search_for_videos_checkbox->get_active) {
- push @types, 'video';
- }
-
- my $type = @types ? join(',', @types) : 'video';
+ my $type = $search_for_combobox->get_active_text;
display_results($yv_obj->search_for($type, $keywords));
return 1;
@@ -3127,18 +3067,12 @@ sub play_video {
}
sub list_category {
+
my $iter = $cat_treeview->get_selection->get_selected;
- my $cat_id = $cats_liststore->get($iter, 1) // return;
+ my $cat_id = $cats_liststore->get($iter, 1);
my $type = $cats_liststore->get($iter, 3);
- my $videos =
- $type eq 'edu-cat'
- ? $yv_obj->get_video_lectures_from_category($cat_id)
- : $yv_obj->videos_from_category($cat_id);
-
- if (not $yv_utils->has_entries($videos)) {
- $videos = $yv_obj->trending_videos_from_category($cat_id);
- }
+ my $videos = $yv_obj->trending_videos_from_category($cat_id);
if ($yv_utils->has_entries($videos)) {
$liststore->clear if $CONFIG{clear_search_list};
@@ -3150,6 +3084,7 @@ sub list_category {
}
sub list_tops {
+
my $iter = $tops_treeview->get_selection->get_selected;
my %top_opts;