Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Cache album art for playerctl module #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions helpers/filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ function _filesystem.list_directory_files(path, exts, recursive)
return files
end

function _filesystem.save_image_async_curl(url, filepath, callback)
awful.spawn.with_line_callback(string.format("curl -L -s %s -o %s", url, filepath),
function _filesystem.save_image_async_curl(redownload, create_dirs, url, filepath, callback)
if not redownload and Gio.File.query_exists(Gio.File.new_for_path(filepath)) then
callback()
return
end

awful.spawn.with_line_callback(string.format("curl -L -s %s -o %s %s", url, filepath, (create_dirs and "--create-dirs" or "")),
{
exit=callback
})
Expand Down
5 changes: 3 additions & 2 deletions signal/playerctl/playerctl_cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local gobject = require("gears.object")
local gtable = require("gears.table")
local gtimer = require("gears.timer")
local gstring = require("gears.string")
local gfs = require("gears.filesystem")
local beautiful = require("beautiful")
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
local setmetatable = setmetatable
Expand Down Expand Up @@ -184,8 +185,8 @@ local function emit_player_metadata(self)
callback = function()
if title and title ~= "" then
if art_url ~= "" then
local art_path = os.tmpname()
helpers.filesystem.save_image_async_curl(art_url, art_path, function()
local art_path = gfs.get_cache_dir() .. "bling_album_art/" .. art_url:gsub("https://", ""):gsub("http://", "")
helpers.filesystem.save_image_async_curl(false, true, art_url, art_path, function()
self:emit_signal("metadata", title, artist, art_path, album, player_name)
capi.awesome.emit_signal("bling::playerctl::title_artist_album", title, artist, art_path)
end)
Expand Down
5 changes: 3 additions & 2 deletions signal/playerctl/playerctl_lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local gobject = require("gears.object")
local gtable = require("gears.table")
local gtimer = require("gears.timer")
local gstring = require("gears.string")
local gfs = require("gears.filesystem")
local beautiful = require("beautiful")
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
local setmetatable = setmetatable
Expand Down Expand Up @@ -190,8 +191,8 @@ local function emit_metadata_signal(self, title, artist, artUrl, album, new, pla
end

if artUrl ~= "" then
local art_path = os.tmpname()
helpers.filesystem.save_image_async_curl(artUrl, art_path, function()
local art_path = gfs.get_cache_dir() .. "bling_album_art/" .. artUrl:gsub("https://", ""):gsub("http://", "")
helpers.filesystem.save_image_async_curl(false, true, artUrl, art_path, function()
self:emit_signal("metadata", title, artist, art_path, album, new, player_name)
capi.awesome.emit_signal("bling::playerctl::title_artist_album", title, artist, art_path, player_name)
end)
Expand Down