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")
15 local next, getenv, table = next, os.getenv, table
17 -- Google Play Music Desktop infos
18 -- lain.widget.contrib.gpmdp
21 local function factory(args)
22 local gpmdp = { widget = wibox.widget.textbox() }
23 local args = args or {}
24 local timeout = args.timeout or 2
25 local notify = args.notify or "off"
26 local followtag = args.followtag or false
27 local file_location = args.file_location or
28 getenv("HOME") .. "/.config/Google Play Music Desktop Player/json_store/playback.json"
29 local settings = args.settings or function() end
31 gpmdp_notification_preset = {
32 title = "Now playing",
36 helpers.set_map("gpmdp_current", nil)
38 function gpmdp.update()
39 local filelines = helpers.lines_from(file_location)
41 if not next(filelines) then
42 local gpm_now = { running = false, playing = false }
44 dict, pos, err = json.decode(table.concat(filelines), 1, nil)
46 gpm_now.artist = dict.song.artist
47 gpm_now.album = dict.song.album
48 gpm_now.title = dict.song.title
49 gpm_now.cover_url = dict.song.albumArt
50 gpm_now.playing = dict.playing
53 if pread("pidof 'Google Play Music Desktop Player'") ~= '' then
54 gpm_now.running = true
56 gpm_now.running = false
59 gpmdp_notification_preset.text = string.format("%s (%s) - %s", gpm_now.artist, gpm_now.album, gpm_now.title)
63 if gpm_now.playing then
64 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
65 helpers.set_map("gpmdp_current", gpm_now.title)
67 if followtag then gpmdp_notification_preset.screen = focused() end
69 helpers.async(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url),
71 gpmdp.id = naughty.notify({
72 preset = gpmdp_notification_preset,
73 icon = "/tmp/gpmcover.png",
74 replaces_id = gpmdp.id
78 elseif not gpm_now.running then
79 helpers.set_map("gpmdp_current", nil)
83 gpmdp.timer = helpers.newtimer("gpmdp", timeout, gpmdp.update, true, true)