All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2016, Alexandre Terrien
9 local helpers = require("lain.helpers")
10 local json = require("lain.util.dkjson")
11 local focused = require("awful.screen").focused
12 local pread = require("awful.util").pread
13 local naughty = require("naughty")
14 local wibox = require("wibox")
16 local os = { getenv = os.getenv }
18 local setmetatable = setmetatable
20 -- Google Play Music Desktop infos
21 -- lain.widget.contrib.gpmdp
22 local gpmdp = helpers.make_widget_textbox()
24 local function worker(args)
25 local args = args or {}
26 local timeout = args.timeout or 2
27 local notify = args.notify or "off"
28 local followtag = args.followtag or false
29 local file_location = args.file_location or
30 os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
31 local settings = args.settings or function() end
33 gpmdp_notification_preset = {
34 title = "Now playing",
38 helpers.set_map("gpmdp_current", nil)
40 function gpmdp.update()
41 local filelines = helpers.lines_from(file_location)
43 if not next(filelines) then
44 local gpm_now = { running = false, playing = false }
46 dict, pos, err = json.decode(table.concat(filelines), 1, nil)
48 gpm_now.artist = dict.song.artist
49 gpm_now.album = dict.song.album
50 gpm_now.title = dict.song.title
51 gpm_now.cover_url = dict.song.albumArt
52 gpm_now.playing = dict.playing
55 if pread("pidof 'Google Play Music Desktop Player'") ~= '' then
56 gpm_now.running = true
58 gpm_now.running = false
61 gpmdp_notification_preset.text = string.format("%s (%s) - %s", gpm_now.artist, gpm_now.album, gpm_now.title)
65 if gpm_now.playing then
66 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
67 helpers.set_map("gpmdp_current", gpm_now.title)
69 if followtag then gpmdp_notification_preset.screen = focused() end
71 helpers.async(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url),
73 gpmdp.id = naughty.notify({
74 preset = gpmdp_notification_preset,
75 icon = "/tmp/gpmcover.png",
76 replaces_id = gpmdp.id
80 elseif not gpm_now.running then
81 helpers.set_map("gpmdp_current", nil)
85 gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)
90 return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })