Skip to content

Commit

Permalink
cli: fixed the stdin ":pp=i" option for local playlists (-lp)
Browse files Browse the repository at this point in the history
  • Loading branch information
trizen committed Mar 7, 2021
1 parent b46c3e2 commit 1a2e742
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions bin/youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -2276,15 +2276,18 @@ sub rate_videos {

sub get_and_play_video_ids {
(my @ids = grep { defined($_) } map { get_valid_video_id($_) } @_) || return;
my $info = $yv_obj->video_details(join(',', @ids), VIDEO_PART);

if ($yv_utils->has_entries($info)) {
if (not play_videos($info->{results}{items})) {
return;
while (@ids) {
my $info = $yv_obj->video_details(join(',', splice(@ids, 0, 50)), VIDEO_PART);

if ($yv_utils->has_entries($info)) {
if (not play_videos($info->{results}{items})) {
return;
}
}
else {
warn_cant_do('get info for', @ids);
}
}
else {
warn_cant_do('get info for', @ids);
}

return 1;
Expand Down Expand Up @@ -3633,8 +3636,18 @@ sub print_playlists {
# :pp=i
elsif ($opt =~ /^pp${digit_or_equal_re}(.*)/) {
if (my @ids = get_valid_numbers($#{$playlists}, $1)) {
my $arg = "--pp=" . join(q{,}, map { $yv_utils->get_playlist_id($_) } @{$playlists}[@ids]);
apply_input_arguments([$arg]);
foreach my $playlist (@{$playlists}[@ids]) {

my $id = $yv_utils->get_playlist_id($playlist);

if ($id =~ m{^/}) { # local playlist
my @ids = reverse $yv_utils->read_lines_from_file($id);
apply_input_arguments(["--id=" . join(",", @ids)]) if @ids;
}
else {
apply_input_arguments(["--pp=$id"]);
}
}
}
else {
warn_no_thing_selected('playlist');
Expand All @@ -3655,7 +3668,7 @@ sub print_playlists {
return $id;
}

if ($id =~ m{^/}) {
if ($id =~ m{^/}) { # local playlist
print_local_playlist($id);
}
else {
Expand Down

0 comments on commit 1a2e742

Please sign in to comment.