Skip to content

Commit

Permalink
Upd: adapt API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Jun 7, 2024
1 parent a413817 commit fc33ffd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ read_globals = {
"mympd_api",
"mympd_http_client",
"mympd_http_download",
"mympd_util_covercache_write",
"mympd_caches_images_write",
"mympd_caches_lyrics_write",
"mympd_caches_update_mtime",
"mympd_util_notify",
"mympd_util_log",
"mympd_util_hash",
Expand All @@ -26,4 +28,4 @@ read_globals = {
}

unused = false
max_line_length = 256
max_line_length = 1000
2 changes: 1 addition & 1 deletion Albumart/Albumart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end

-- Cache the fetched albumart and send it to the client
local filename
rc, filename = mympd.covercache_write(out, mympd_arguments.uri)
rc, filename = mympd.cache_cover_write(out, mympd_arguments.uri)
if rc == 0 then
return mympd.http_serve_file(filename)
end
Expand Down
28 changes: 21 additions & 7 deletions Covercache/CovercachePrepopulate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ local extensions = {
"jpg",
"jpeg",
"png",
"avif"
"avif",
"svg"
}

local function file_exists(name)
Expand All @@ -23,10 +24,20 @@ local function check_image(base)
for _, ext in ipairs(extensions) do
local p = base .. "." .. ext
if file_exists(p) then
return true
return p
end
end
return false
return nil
end

local function create_placeholder(filename)
local f = io.open(filename, "w")
if f == nil then
return false
end
io.write(f, '<?xml version="1.0" encoding="UTF-8"?><svg width="63.5mm" height="63.5mm" version="1.1" viewBox="0 0 63.5 63.5" xmlns="http://www.w3.org/2000/svg"><g transform="translate(21.167 -117.08)"><rect x="-21.167" y="117.08" width="63.5" height="63.5" fill="#b3b3b3"/><path d="m29.674 133.99v13.978l-6.3634-6.3846-8.4845 8.5057-8.4845-8.4845-8.4845 8.4845-6.3634-6.3846v-9.7148c0-2.3332 1.909-4.2423 4.2423-4.2423h29.696c2.3332 0 4.2423 1.909 4.2423 4.2423zm-6.3634 13.618 6.3634 6.3846v9.6936c0 2.3332-1.909 4.2423-4.2423 4.2423h-29.696c-2.3332 0-4.2423-1.909-4.2423-4.2423v-13.957l6.3634 6.3422 8.4845-8.4845 8.4845 8.4845z" fill="#fff" stroke-width=".26458"/></g></svg>')
io.close(f)
return true
end

local rc, result, code, headers
Expand All @@ -46,19 +57,22 @@ local downloaded = 0
for _, album in pairs(result.data) do
if album.uri and album.uri ~= "" then
local path = mympd_env.cachedir_cover .. "/" .. mympd.hash_sha1(album.uri) .. "-0"
if not check_image(path) then
local existing_file = check_image(path)
if existing_file ~= nil then
mympd.update_mtime(existing_file)
existing = existing + 1
else
local out = mympd.tmp_file()
local uri = mympd_state.mympd_uri .. 'albumart-thumb?offset=0&uri=' .. mympd.urlencode(album.uri)
rc, code, headers = mympd_http_download(uri, out)
if rc == 0 then
local name = mympd.covercache_write(out, album.uri)
local name = mympd.cache_cover_write(out, album.uri)
mympd.log(6, "Covercache: " .. name)
downloaded = downloaded + 1
else
errors = errors + 1
create_placeholder(path .. ".svg")
end
else
existing = existing + 1
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions Covercache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

## CovercachePrepopulate

This scripts downloads abumart from myMPD and stores it in the covercache. This script works only for the advanced album mode (default).


This scripts downloads abumart from myMPD and stores it in the covercache. This script works only for the advanced album mode (default). It writes a placeholder file for not found images.
2 changes: 1 addition & 1 deletion Lyrics/Lyrics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ local result = {
}

-- Cache the fetched lyrics and send the response
mympd.lyricscache_write(json.encode(entry), mympd_arguments.uri)
mympd.cache_lyrics_write(json.encode(entry), mympd_arguments.uri)
return mympd.http_jsonrpc_response(result)
2 changes: 1 addition & 1 deletion Tagart/Tagart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

-- Cache the fetched tagart and send it to the client
local filename
rc, filename = mympd.thumbscache_write(out, value)
rc, filename = mympd.cache_thumbs_write(out, value)
if rc == 0 then
return mympd.http_serve_file(filename)
end
Expand Down

0 comments on commit fc33ffd

Please sign in to comment.