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 0f66009 commit a413817
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
7 changes: 4 additions & 3 deletions Albumart/Albumart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ if rc == 1 then
end

-- Cache the fetched albumart and send it to the client
local file = mympd.covercache_write(out, mympd_arguments.uri)
if file then
return mympd.http_serve_file(file)
local filename
rc, filename = mympd.covercache_write(out, mympd_arguments.uri)
if rc == 0 then
return mympd.http_serve_file(filename)
end

return mympd.http_redirect("/assets/coverimage-notavailable")
19 changes: 10 additions & 9 deletions Covercache/CovercachePrepopulate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ local function check_image(base)
return false
end

local rc, result = mympd.api("MYMPD_API_DATABASE_ALBUM_LIST", {
local rc, result, code, headers

rc, result = mympd.api("MYMPD_API_DATABASE_ALBUM_LIST", {
offset = 0,
limit = 10000,
expression = "",
Expand All @@ -42,23 +44,22 @@ local existing = 0
local errors = 0
local downloaded = 0
for _, album in pairs(result.data) do
local path = mympd_env.cachedir_cover .. "/" .. mympd.hash_sha1(album.uri) .. "-0"
if not check_image(path) then
if not pcall(function()
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 out = mympd.tmp_file()
local uri = mympd_state.mympd_uri .. 'albumart-thumb?offset=0&uri=' .. mympd.urlencode(album.uri)
if mympd_http_download(uri, out) == 0 then
rc, code, headers = mympd_http_download(uri, out)
if rc == 0 then
local name = mympd.covercache_write(out, album.uri)
mympd.log(6, "Covercache: " .. name)
downloaded = downloaded + 1
else
errors = errors + 1
end
end) then
errors = errors + 1
else
existing = existing + 1
end
else
existing = existing + 1
end
end

Expand Down
4 changes: 3 additions & 1 deletion Covercache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

## CovercachePrepopulate

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


6 changes: 3 additions & 3 deletions Lyrics/Lyrics.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- {"order":1,"arguments":["uri"]}
-- Import lyrics provider configuration
local providers = require "scripts/LyricsProviders"
local rc, code, header, body, song, lyrics_text, desc
local rc, code, headers, body, song, lyrics_text, desc

local function strip_html(str)
str = str:gsub("<!%[CDATA%[.-%]%]>", "")
Expand Down Expand Up @@ -37,7 +37,7 @@ end

local function get_lyrics_uri(provider, artist, title)
local identity_uri = replace_vars_uri(provider.identity_uri, artist, title)
rc, code, header, body = mympd.http_client("GET", identity_uri, "", "")
rc, code, headers, body = mympd.http_client("GET", identity_uri, "", "")
if rc == 0 and #body > 0 then
local identity_pattern = replace_vars_pattern(provider.identity_pattern, artist, title)
local lyrics_path = body:match(identity_pattern)
Expand Down Expand Up @@ -66,7 +66,7 @@ for _, provider in pairs(providers) do
lyrics_uri = replace_vars_uri(provider.lyrics_uri, artist, title)
end
if lyrics_uri then
rc, code, header, body = mympd.http_client("GET", lyrics_uri, "", "")
rc, code, headers, body = mympd.http_client("GET", lyrics_uri, "", "")
if rc == 0 then
local lyrics_pattern = replace_vars_pattern(provider.lyrics_pattern, artist, title)
lyrics_text = body:match(lyrics_pattern)
Expand Down
7 changes: 4 additions & 3 deletions Tagart/Tagart.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ if rc == 1 then
end

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

return mympd.http_redirect("/assets/coverimage-notavailable")

0 comments on commit a413817

Please sign in to comment.