Skip to content

Commit

Permalink
[mediaplayer] use playerctl's formatting support
Browse files Browse the repository at this point in the history
Ignores artist if absent (the hack of giving a control character default
and stripping it is unfortunately necessary at the moment, cf
altdesktop/playerctl#296)

Closes: vivien#498
  • Loading branch information
hseg committed Aug 28, 2023
2 parents 1171335 + dff3dca commit 8460a79
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions mediaplayer/mediaplayer
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@ if ($ENV{'BLOCK_BUTTON'} == 1) {
system("playerctl $player_arg volume 0.01-");
}

my $artist = qx(playerctl $player_arg metadata artist 2>/dev/null);
chomp $artist;
my $metadata = qx(playerctl $player_arg metadata \\
--format '{{default(artist, "\004\005")}} - {{title}}' 2>/dev/null);
chomp $metadata;
$metadata =~ s/^\004\005 - //;
# exit status will be nonzero when playerctl cannot find your player
exit(0) if $? || $artist eq '(null)';
exit(0) if $? || $metadata eq '(null)';

push(@metadata, $artist) if $artist;

my $title = qx(playerctl $player_arg metadata title);
exit(0) if $? || $title eq '(null)';

push(@metadata, $title) if $title;

print(join(" - ", @metadata)) if @metadata;
print($metadata) if $metadata;
print("\n");

0 comments on commit 8460a79

Please sign in to comment.