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 pread = require("awful.util").pread
12 local naughty = require("naughty")
13 local wibox = require("wibox")
15 local os = { getenv = os.getenv }
17 local setmetatable = setmetatable
19 -- Google Play Music Desktop infos
20 -- lain.widget.contrib.gpmdp
23 local function worker(args)
24 local args = args or {}
25 local timeout = args.timeout or 2
26 local notify = args.notify or "off"
27 local followmouse = args.followmouse or false
28 local file_location = args.file_location or
29 os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
30 local settings = args.settings or function() end
32 gpmdp.widget = wibox.widget.textbox('')
34 gpmdp_notification_preset = {
35 title = "Now playing",
39 helpers.set_map("gpmdp_current", nil)
41 function gpmdp.update()
42 file, err = io.open(file_location, "r")
45 gpm_now = { running = false, playing = false }
47 dict, pos, err = json.decode(file:read "*a", 1, nil)
50 gpm_now.artist = dict.song.artist
51 gpm_now.album = dict.song.album
52 gpm_now.title = dict.song.title
53 gpm_now.cover_url = dict.song.albumArt
54 gpm_now.playing = dict.playing
57 if (pread("pidof 'Google Play Music Desktop Player'") ~= '') then
58 gpm_now.running = true
60 gpm_now.running = false
63 gpmdp_notification_preset.text = string.format("%s (%s) - %s", gpm_now.artist, gpm_now.album, gpm_now.title)
69 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current")
71 helpers.set_map("gpmdp_current", gpm_now.title)
72 os.execute("curl " .. gpm_now.cover_url .. " -o /tmp/gpmcover.png")
75 gpmdp_notification_preset.screen = mouse.screen
78 gpmdp.id = naughty.notify({
79 preset = gpmdp_notification_preset,
80 icon = "/tmp/gpmcover.png",
81 replaces_id = gpmdp.id,
84 elseif not gpm_now.running
86 helpers.set_map("gpmdp_current", nil)
90 helpers.newtimer("gpmdp", timeout, gpmdp.update)
92 return setmetatable(gpmdp, { __index = gpmdp.widget })
95 return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })