#!/usr/bin/env perl sub show_player_meta { my $player = shift; my ($artist, $album, $title, $url) = split /\|/, `playerctl -p $player metadata --format '{{xesam:artist}}|{{xesam:album}}|{{xesam:title}}|{{xesam:url}}'`; $url = "" if $url =~ /^file:|spotify/; my $song = $album ? "$title - $album" : $title; my @lines; push @lines, $artist if $artist; push @lines, $song if $song; push @lines, $url if $url; my @args = qw"-t 4000 -u low"; push @args, shift @lines; push @args, join("\n", @lines); system "notify-send", @args; } sub players { map { chomp $_; [split /\|/, $_] } `bash -c "paste -d '|' <(playerctl -l) <(playerctl -a status)"` } for my $playerline (players()) { my ($player, $status) = @$playerline; show_player_meta($player) if ($status eq "Playing"); }