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) then
48 local gpm_now = { running = false, playing = false }
50 dict, pos, err = json.decode(table.concat(filelines), 1, nil)
52 gpm_now.artist = dict.song.artist
53 gpm_now.album = dict.song.album
54 gpm_now.title = dict.song.title
55 gpm_now.cover_url = dict.song.albumArt
56 gpm_now.playing = dict.playing
59 if pread("pidof 'Google Play Music Desktop Player'") ~= '' then
60 gpm_now.running = true
62 gpm_now.running = false
65 gpmdp_notification_preset.text = string.format("%s (%s) - %s", gpm_now.artist, gpm_now.album, gpm_now.title)
69 if gpm_now.playing then
70 if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
71 helpers.set_map("gpmdp_current", gpm_now.title)
72 os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url))
74 if followtag then gpmdp_notification_preset.screen = focused() end
76 gpmdp.id = naughty.notify({
77 preset = gpmdp_notification_preset,
78 icon = "/tmp/gpmcover.png",
79 replaces_id = gpmdp.id,
82 elseif not gpm_now.running
84 helpers.set_map("gpmdp_current", nil)
88 helpers.newtimer("gpmdp", timeout, gpmdp.update)
90 return setmetatable(gpmdp, { __index = gpmdp.widget })
93 return setmetatable(gpmdp, { __call = function(_, ...) return worker(...) end })