i3blocks-music.plon commit i3blocks-music.pl: remove line breaks and punctation-delimited postambles (599b422)
   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.+)//;
  32$title =~ s/&/&amp;/;
  33push(@metadata, $title) if $title;
  34
  35for (@metadata){
  36  s/\n//;
  37}
  38
  39# Print stuff
  40print(join(" - ", @metadata)) if @metadata;
  41print("</span>");