summary refs log tree commit diff
path: root/.config/waybar/modules/mpris.awk
blob: 194aa736e0b0bd754676bba569c1278a0e892645 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{
  gsub(/"/,"")
  gsub(/'/,"\047")
  # print "DEBUG: " $0

  artist=$1
  album=$2
  title=$3
  position=$4
  player=$5
  status=$6
}

($0 == "") || (status ~ /stopped/) {
  system("jq -Mnc {}")
  next
}

(status ~ /playing/) {
  icon="󰲸"
}
(status ~ /paused/) {
  icon="󰏤"
}
(artist != "") && (album != "") {
  text=sprintf("%s - %s - %s (%s)", artist, album, title, position)
  tooltip=sprintf("%s\nby %s\nfrom %s\n(%s)", title, artist, album, player)
}
(artist == "") {
  text=sprintf("%s - %s (%s)", album, title, position)
  tooltip=sprintf("%s\nfrom %s\n(%s)", title, album, player)
}
(album == "") {
  text=sprintf("%s - %s (%s)", artist, title, position)
  tooltip=sprintf("%s\nby %s\n(%s)", title, artist, player)
}
(artist == "") && (album == "") {
  text=sprintf("%s (%s)", title, position)
  tooltip=sprintf("%s\n(%s)", title, player)
}
# edge cases to beautify the output
(player == "tdesktop") && (title ~ /Unknown Track/) {
  text="telegram voice message"
}

{
  system(sprintf("jq -rMnc --arg class \"%s\" --arg text \"%s %s\" --arg tt \"%s\" '{ class: $class, text: $text|@html, tooltip: $tt|@html }'", \
         status,
         icon,
         text,
         tooltip))
}

END {}