9bee37a5e2ae3deb956e30041f705dd8cc16f900
   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/(?:[ ][( ][Ff]eat[. ].*)|(?:[( ][Ff]t[. ].*)//;
  31push(@metadata, $title) if $title;
  32
  33# Print stuff
  34print(join(" - ", @metadata)) if @metadata;
  35print("</span>");