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 pread = require("awful.util").pread
14 local naughty = require("naughty")
15 local wibox = require("wibox")
19 local setmetatable = setmetatable
21 -- Google Play Music Desktop infos
22 -- lain.widget.contrib.gpmdp
25 local function worker(args)
26 local args = args or {}
27 local timeout = args.timeout or 2
28 local notify = args.notify or "off"
29 local followmouse = args.followmouse or false
30 local file_location = args.file_location or
31 os.getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
32 local settings = args.settings or function() end
34 gpmdp.widget = wibox.widget.textbox('')
36 gpmdp_notification_preset = {
37 title = "Now playing",
41 helpers.set_map("gpmpd_current", nil)
43 function gpmdp.update()
44 file, err = io.open(file_location, "r")
52 dict, pos, err = json.decode(file:read "*a", 1, nil)
55 gpm_now.artist = dict.song.artist
56 gpm_now.album = dict.song.album
57 gpm_now.title = dict.song.title
58 gpm_now.cover_url = dict.song.albumArt
59 gpm_now.playing = dict.playing
61 if (pread("pidof 'Google Play Music Desktop Player'") ~= '') then
62 gpm_now.running = true
64 gpm_now.running = false
67 gpmdp_notification_preset.text = string.format(
77 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmpd_current")
79 helpers.set_map("gpmpd_current", gpm_now.title)
81 current_icon = "/tmp/gpmcover.png"
82 os.execute("curl " .. gpm_now.cover_url .. " -o " .. current_icon)
85 gpmdp_notification_preset.screen = mouse.screen
88 gpmdp.id = naughty.notify({
89 preset = gpmdp_notification_preset,
91 replaces_id = gpmdp.id,
94 elseif (not gpm_now.running)
96 helpers.set_map("current mpd track", nil)
100 helpers.newtimer("gpmdp", timeout, gpmdp.update)
102 return setmetatable(gpmdp, { __index = gpmdp.widget })
105 return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })