Skip to content

Commit

Permalink
- Added the video_min_seconds config option.
Browse files Browse the repository at this point in the history
When set to a positive integer `n`, it filters out from results videos with less than `n` seconds.
  • Loading branch information
trizen committed Feb 22, 2023
1 parent 89cd450 commit 8cebc0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 9 additions & 2 deletions bin/gtk-youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#-------------------------------------------------------
# GTK YouTube Viewer
# Created on: 12 September 2010
# Latest edit on: 08 February 2023
# Latest edit on: 22 February 2023
# https://github.com/trizen/youtube-viewer
#-------------------------------------------------------

Expand Down Expand Up @@ -250,6 +250,8 @@ my %CONFIG = (
autoscroll_to_end => 0,
single_click_play => 0,

video_min_seconds => 0,

# youtube-dl support
ytdl => 1,
ytdl_cmd => undef, # auto-detect
Expand Down Expand Up @@ -2860,7 +2862,7 @@ sub get_subscription_video_results {
}
}

my $prev_subscriptions_data = {channel_data => {},};
my $prev_subscriptions_data = {channel_data => {}};

require Storable;

Expand Down Expand Up @@ -3065,6 +3067,11 @@ sub display_results {
# Filter out videos with time '00:00'
$yv_utils->get_time($item) eq '00:00' and next;

# Skip too short videos
if ($CONFIG{video_min_seconds}) {
$yv_utils->get_duration($item) > $CONFIG{video_min_seconds} or next;
}

# Mark as video
$item->{__is_video__} = 1;

Expand Down
13 changes: 12 additions & 1 deletion bin/youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#-------------------------------------------------------
# youtube-viewer
# Created on: 02 June 2010
# Latest edit on: 08 February 2023
# Latest edit on: 22 February 2023
# https://github.com/trizen/youtube-viewer
#-------------------------------------------------------

Expand Down Expand Up @@ -284,6 +284,8 @@ my %CONFIG = (
bypass_age_gate_with_proxy => 0,
ignored_projections => [],

video_min_seconds => 0,

# Conversion options
convert_cmd => 'ffmpeg -i *IN* *OUT*',
convert_to => undef,
Expand Down Expand Up @@ -4779,6 +4781,11 @@ sub print_videos {
$yv_utils->get_video_id($_)
and $yv_utils->get_time($_) ne '00:00'
} @$videos;

# Filter out too short videos
@$videos = grep {
$yv_utils->get_duration($_) > $opt{video_min_seconds}
} @$videos if $opt{video_min_seconds};
#>>>

my @formatted;
Expand Down Expand Up @@ -5661,6 +5668,10 @@ The available special tokens are listed in:
youtube-viewer --tricks
=head2 video_min_seconds
Filter out from results videos with less than C<video_min_seconds> seconds.
=head2 video_player_selected
The selected video player defined the C<video_players> table.
Expand Down

0 comments on commit 8cebc0f

Please sign in to comment.