Skip to content

Commit

Permalink
- Added the autolike_watched config-option (disabled by default).
Browse files Browse the repository at this point in the history
When enabled, watched videos (if not already watched) will be automatically liked.

Implements and closes #356

Thanks to @allanlaal for feature request!
  • Loading branch information
trizen committed Feb 24, 2021
1 parent f67c1db commit c9621c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 10 additions & 2 deletions bin/gtk-youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ my %CONFIG = (
fullscreen => 0,
audio_only => 0,

autolike_watched => 0,
autoscroll_to_end => 0,

# youtube-dl support
Expand Down Expand Up @@ -1180,7 +1181,7 @@ sub menu_popup {
$item->set_property(tooltip_text => "Send a positive rating");
$item->signal_connect(
activate => sub {
$yv_obj->send_rating_to_video($video_id, 'like')
$yv_obj->like_video($video_id)
or warn "Failed to send a positive rating to <$video_id>: $!";
}
);
Expand All @@ -1195,7 +1196,7 @@ sub menu_popup {
$item->set_property(tooltip_text => "Send a negative rating");
$item->signal_connect(
activate => sub {
$yv_obj->send_rating_to_video($video_id, 'dislike')
$yv_obj->dislike_video($video_id)
or warn "Failed to send a negative rating to <$video_id>: $!";
}
);
Expand Down Expand Up @@ -3287,6 +3288,13 @@ sub get_player_command {
sub save_watched_video {
my ($video_id) = @_;

if (not exists $WATCHED_VIDEOS{$video_id}) {
if ($CONFIG{autolike_watched}) {
say ":: Sending a positive rating to video ID: $video_id";
$yv_obj->like_video($video_id) // do { say ":: Failed!" };
}
}

$WATCHED_VIDEOS{$video_id} = 1;

if ($CONFIG{watch_history}) {
Expand Down
11 changes: 10 additions & 1 deletion bin/youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ my %CONFIG = (
highlight_watched => 1,
highlight_color => 'bold',
skip_watched => 0,
autolike_watched => 0,

# youtube-dl support
ytdl => 1,
Expand Down Expand Up @@ -864,7 +865,8 @@ usage: $execname [options] ([url] | [keywords])
--min-seconds=i : ignore videos shorter than i seconds
--get-term-width! : allow $execname to read your terminal width
--skip-watched! : don't play already watched videos
--highlight! : remember and highlight selected videos
--highlight! : remember and highlight watched videos
--autolike! : automatically like videos after watching them
--confirm! : show a confirmation message after each play
--prefer-mp4! : prefer videos in MP4 format, instead of WEBM
--prefer-av1! : prefer videos in AV1 format, instead of WEBM
Expand Down Expand Up @@ -1760,6 +1762,7 @@ sub parse_arguments {
'page=i' => \$opt{page},
'novideo|no-video|n|audio!' => \$opt{novideo},
'highlight!' => \$opt{highlight_watched},
'autolike!' => \$opt{autolike_watched},
'skip-watched!' => \$opt{skip_watched},
'results=i' => \$opt{maxResults},
'shuffle|s!' => \$opt{shuffle},
Expand Down Expand Up @@ -3965,6 +3968,12 @@ sub download_video {
sub save_watched_video {
my ($video_id) = @_;

if (not exists $WATCHED_VIDEOS{$video_id}) {
if ($opt{autolike_watched}) {
rate_videos('like', $video_id);
}
}

$WATCHED_VIDEOS{$video_id} = 1;

if ($opt{watch_history}) {
Expand Down
2 changes: 2 additions & 0 deletions lib/WWW/YoutubeViewer/Videos.pm
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Send rating to a video. $rating can be either 'like' or 'dislike'.
sub send_rating_to_video {
my ($self, $video_id, $rating) = @_;

$self->get_access_token() // return;

if ($rating eq 'none' or $rating eq 'like' or $rating eq 'dislike') {
my $url = $self->_simple_feeds_url('videos/rate', id => $video_id, rating => $rating);
return defined($self->lwp_post($url, $self->_auth_lwp_header()));
Expand Down

0 comments on commit c9621c3

Please sign in to comment.