Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print string only if metadata is set #296

Open
UtkarshVerma opened this issue Jan 23, 2023 · 1 comment
Open

Print string only if metadata is set #296

UtkarshVerma opened this issue Jan 23, 2023 · 1 comment

Comments

@UtkarshVerma
Copy link

I wish to replicate the following mpc format in playerctl:

mpc -f "%title%[ - %artist%]" current

It only prints - %artist% if artist is set. How do I achieve this with playerctl?

@UtkarshVerma UtkarshVerma changed the title Print string only is metadata is set Print string only if metadata is set Jan 23, 2023
@hseg
Copy link

hseg commented Aug 28, 2023

Same here - am currently hackily using a combination of default() and stripping the default substitution I'm setting.

my $metadata = qx(playerctl $player_arg metadata \\
        --format '{{default(artist, "\004\005")}} - {{title}}' 2>/dev/null);
chomp $metadata;
$metadata =~ s/^\004\005 - //;

(that pair of characters is STX/ETX, probably semantically invalid but it makes some sense to me)

hseg added a commit to hseg/i3blocks-contrib that referenced this issue Aug 28, 2023
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
hseg added a commit to hseg/i3blocks-contrib that referenced this issue Feb 11, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants