about summary refs log tree commit diff
path: root/.config/luastatus/playerctl.lua
blob: a3e743c5ef7215f9d19eee27b4184165a40dd0c5 (plain)
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
local player = 'jellyfin-tui'

widget = {
  plugin = 'timer',
  opts = { period = 2 },
  cb = function()

    local handle = io.popen('playerctl -p ' .. player .. ' status')
    local playerctl_status = string.sub(handle:read("*a"), 1, -2)
    handle:close()

    local symbol = '󰏤'

    if (playerctl_status == 'Playing') or (playerctl_status == 'Paused') then
      local handle = io.popen('playerctl -p ' .. player ..' metadata title')
      local playerctl_title = string.sub(handle:read("*a"), 1, -2)
      handle:close()

      local handle = io.popen('playerctl -p ' .. player .. ' metadata artist')
      local playerctl_artist = string.sub(handle:read("*a"), 1, -2)
      handle:close()

      if playerctl_status == 'Playing' then
        symbol = '󰐊'
      end

      return {
        { full_text = string.format('%s - %s %s', playerctl_artist, playerctl_title, symbol), color = "#f2cdcd" }
      }
    end

    return {
      { full_text = " "}
    }
  end,
  -- TODO: Figure out if this can stop being hardcoded
  event = [[
        local t = ...
        if t.button == 1 then
            os.execute('playerctl -p jellyfin-tui play-pause')
        end
    ]],
}