b24f6b1625792421d7c7d551f1d199ed6b79645a
1#!/usr/bin/perl
2
3# Requires playerctl binary in $PATH
4# If $instance is specified in i3blocks, playerctl will attempt to get data from this player
5
6use Env qw(BLOCK_INSTANCE);
7
8my @metadata = ();
9my $player_arg = "";
10
11if ($ARGV[0] =~ "--player=") {
12 $player_arg = $ARGV[0];
13 $player_arg =~ s/\s+//g;
14}
15
16# Check playback status and set appropriate colour
17$_ = qx(playerctl status);
18if (not m/Playing/) {
19 print("<span color='#586e75'>");
20}
21else {
22 print("<span>♪ ");
23}
24
25# Obtain & format metadata from playerctl
26my $artist = qx(playerctl $player_arg metadata artist);
27push(@metadata, $artist) if $artist;
28
29my $title = qx(playerctl $player_arg metadata title);
30$title =~ s/(\s|\s\()[Ff]([et]at[. ].*|t.*)//;
31$title =~ s/((\s(\(|\[).+(\)|\]).*)|(\s-\s.+))//;
32push(@metadata, $title) if $title;
33
34for (@metadata){
35 s/\n//; # remove newlines
36 s/&/&/; # fix ampersand rendering for i3bar
37}
38
39# Print stuff
40print(join(" - ", @metadata)) if @metadata;
41print("</span>");