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")
12 local focused = require("awful.screen").focused
13 local pread = require("awful.util").pread
14 local naughty = require("naughty")
15 local wibox = require("wibox")
18 local os = { getenv = os.getenv }
19 local setmetatable = setmetatable
22 -- Google Play Music Desktop infos
23 -- lain.widget.contrib.gpmdp
26 local function worker(args)
27 local args = args or {}
28 local timeout = args.timeout or 2
29 local notify = args.notify or "off"
30 local followtag = args.followtag or false
31 local file_location = args.file_location or
32 os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
33 local settings = args.settings or function() end
35 gpmdp.widget = wibox.widget.textbox('')
37 gpmdp_notification_preset = {
38 title = "Now playing",
42 helpers.set_map("gpmdp_current", nil)
44 function gpmdp.update()
45 local filelines = helpers.lines_from(file_location)
47 if not next(filelines)
49 local gpm_now = { running = false, playing = false }
51 dict, pos, err = json.decode(table.concat(filelines), 1, nil)
53 gpm_now.artist = dict.song.artist
54 gpm_now.album = dict.song.album
55 gpm_now.title = dict.song.title
56 gpm_now.cover_url = dict.song.albumArt
57 gpm_now.playing = dict.playing
60 if pread("pidof 'Google Play Music Desktop Player'") ~= '' then
61 gpm_now.running = true
63 gpm_now.running = false
66 gpmdp_notification_preset.text = string.format("%s (%s) - %s", gpm_now.artist, gpm_now.album, gpm_now.title)
72 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current")
74 helpers.set_map("gpmdp_current", gpm_now.title)
75 os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url))
78 gpmdp_notification_preset.screen = focused()
81 gpmdp.id = naughty.notify({
82 preset = gpmdp_notification_preset,
83 icon = "/tmp/gpmcover.png",
84 replaces_id = gpmdp.id,
87 elseif not gpm_now.running
89 helpers.set_map("gpmdp_current", nil)
93 helpers.newtimer("gpmdp", timeout, gpmdp.update)
95 return setmetatable(gpmdp, { __index = gpmdp.widget })
98 return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })