Skip to content

Commit

Permalink
Merge pull request #23 from mayanez/feat/composer-tagart
Browse files Browse the repository at this point in the history
feat(Tagart): Open Opus Composer Tag Provider
  • Loading branch information
jcorporation authored Jul 20, 2024
2 parents c71adef + 0e84863 commit f0991ae
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Tagart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ This script fetches tagart. You must create a directory in the `/var/lib/mympd/p
# Enable display of tags Artist and AlbumArtist
mkdir /var/lib/mympd/pics/Artist
mkdir /var/lib/mympd/pics/AlbumArtist
# Enable display of tags Composer
mkdir /var/lib/mympd/pics/Composer
```

## Usage

1. Create a new variable `fanart_tv_api_key` with your API key for Fanart.tv.
2. Import the `Tagart.lua` and the `TagartProviders.lua` scripts.
3. Create a new trigger
- Event: `mympd_albumart`
- Event: `mympd_tagart`
- Script: above script

## Available providers

| PROVIDER | SUPPORTED TAGS | REQUIRED TAGS |
| -------- | -------------- | ------------- |
| [Fanart.tv](https://fanart.tv/) | Artist, AlbumArtist | Artist, AlbumArtist, MUSICBRAINZ_ARTISTID |
| [Open Opus](https://openopus.org/) | Composer | Composer |
52 changes: 51 additions & 1 deletion Tagart/TagartProviders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,58 @@ local p_fanart_tv = {
end
}

local p_openopus = {
name = "Open Opus",
tags = {
Composer = true
},
get = function(tag, value, out)
local rc, code, header, body, song
rc, song = mympd.api("MYMPD_API_DATABASE_SEARCH", {
expression = "((" .. tag .. " == '" .. value .. "'))",
sort = "Title",
sortdesc = false,
offset = 0,
limit = 1,
fields = {
"composer"
}
})
if rc ~= 0 or
not song.data or
not song.data[1] or
not song.data[1].Composer or
song.data[1].Composer[1] == ""
then
mympd.log(7, "Composer not found")
return 1
end

local uri = "https://api.openopus.org/composer/list/search/" .. mympd.urlencode(song.data[1].Composer[1]) .. ".json"
rc, code, header, body = mympd.http_client("GET", uri, "", "")
if rc == 1 then
return 1
end
local data = json.decode(body)
if not data then
mympd.log(7, "Invalid json data received")
return 1
end
if not data.composers or
not data.composers[1] or
not data.composers[1].portrait
then
mympd.log(7, "Tagart not found")
return 1
end
return mympd.http_download(data.composers[1].portrait, "", out)

end
}

-- Return the providers as lua table
-- You can use this table to sort or disable providers
return {
p_fanart_tv
p_fanart_tv,
p_openopus
}

0 comments on commit f0991ae

Please sign in to comment.