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
24 local function factory(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.widget = wibox.widget.textbox()
35 gpmdp_notification_preset = {
36 title = "Now playing",
40 helpers.set_map("gpmdp_current", nil)
42 function gpmdp.update()
43 local filelines = helpers.lines_from(file_location)
45 if not next(filelines) then
46 local gpm_now = { running = false, playing = false }
48 dict, pos, err = json.decode(table.concat(filelines), 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)
67 if gpm_now.playing then
68 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
69 helpers.set_map("gpmdp_current", gpm_now.title)
71 if followtag then gpmdp_notification_preset.screen = focused() end
73 helpers.async(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url),
75 gpmdp.id = naughty.notify({
76 preset = gpmdp_notification_preset,
77 icon = "/tmp/gpmcover.png",
78 replaces_id = gpmdp.id
82 elseif not gpm_now.running then
83 helpers.set_map("gpmdp_current", nil)
87 gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)
92 return setmetatable(gpmdp, { __call = function(_, ...) return factory(...) end })