Querying the music db for art when using the AIF
#1
It has struck me, that once I have finished the re-organisation of my music files into a more human-friendly structure, my streaming radio helper addon will no longer function correctly with local art, as it relies upon an artist/album type structure.  For instance, once it has an artist name, it will look in 'path to music/artist' to see if there is a local 'logo.png' to display. Similarly, for album artwork, it will attempt to find local art in 'path to music/artist/album', where it will try to find local cdart and a cover.

So, 1st question :

How can I obtain the path that a user has set for the AIF ? Is there an easier method than getting it from guisettings.xml ?

Secondly, given that all the local art should now be in the db, how would I get the paths to the art using an album title ?

Basically, I suppose I'm asking how I query the db to get associated art for a given artist and/or album.  Apologies if this is covered elsewhere and if so, please point me in the right direction.

Cheers.
Learning Linux the hard way !!
Reply
#2
Great you are getting stuck into this @black_eagle Smile
The answer for addons getting anything from the db is going to be use JSON API (and if a suitable call doesn't already exist then I'll add it).

Historically all kinds of assumptions may have been made about folder layout, but I'm happy to support addon authors to move to using JSON instead. Also looking for a folder could only use local art and not that fetched by scrapers and cached unless it was also saved locally too - scraped art isn't saved in a folder unless you export it. I know other addons fetch art and put it in a folder, but that can get messy if they use different locations for example. Far better that the existance and location of art is in db, and that addons (and skins) use that.

To answer your specific questions:
Quote:How can I obtain the path that a user has set for the AIF ? Is there an easier method than getting it from guisettings.xml ?
The AIF path is held in settings.xml,  and can be accessed using JSON
Code:
[{"jsonrpc":"2.0","id": 1,
"method":"Settings.GetSettingValue",
"params":{"setting":"musiclibrary.artistsfolder"}}]
 
Quote:Secondly, given that all the local art should now be in the db, how would I get the paths to the art using an album title ?
My first thought is that album name is often not unique e.g. "Greatest Hits".
If you know the album ID then
Code:
{"jsonrpc":"2.0","id":1,"method":"audioLibrary.GetAlbumDetails",
"params":{"albumid":1413, "properties":["art"]}}
The "art"  property will return not only all the types of album art but that of the album artist(s) too. Properties "thumbnail" and "fanart" are supported historically too they just return one image file URL each.
 
Or for all the albums with that name use GetAlbums with a suitable filter, for example
Code:
{"jsonrpc": "2.0", "id": 1, "method": "AudioLibrary.GetAlbums",
"params": { "filter": {"operator": "contains", "field": "album", "value": "Greatest Hits"},
"properties": [ "title", "displayartist", "artistid", "art"] }}

AudioLibrary.GetArtists and GetArtistDeatils can be used similarly for artist art specifcally. Have a play with JSON and see what it returns.
Reply
#3
@DaveBlake , yeah the album name could be an issue unless it's tied/filtered by artist also.  Basically, the addon parses the metadata in the stream by grabbing Kodi's infoLabels to get track & artist of whatever is currently playing.  It then tries to find an associated album (album by that artist with that track on) and looks for artist logo, albumart, discart and track info.  All of this is saved into its own db.  It uses local art where possible, but falls back to art from theaudioDB if available.

Because of the way it works, initially the only info it has to work with is a track name and an artist name.  It does an initial lookup on musicbrainz for the artist mbid, then looks for a local logo for the artist.  It then does a search on theaudioDB for an album by that artist containing that track (this is cached so subsequent lookups are much faster) but it can cause issues because it takes the first result from the search.  It might for instance ask for a Bryan Adams track and get a result of Anthology (which would technically be correct) although the track might have appeared first on 'Waking up the Neighbours'.  I don't see an easy or fast way of actually determining this so I just use the first returned album.  In some cases, this is indeed a 'greatest hits' compilation.

Now, obviously at this point, I won't know the musicdb artistid or the albumid (if it even exists) so I guess I'll need to use a JSON query to get the artistid (which I'll cache for the future) and then another to look for the album title, flitered by artistid.

OR

Can I look up the relevant data with mbids ?  At the point I need to lookup the art, I've already got the artist mbid and tadb returns an album mbid (which I don't currently use, but it's trivial to get).  I looked at the json spec for Leia, but it appears that I would need the internal artist and album id's rather than the mbids to search on.

With regard to your first point, yes I had to make assumptions about how the actual music files were laid out and where particular graphics would be located.  Scraped stuff would have indeed been missed and the addon would have downloaded and cached (what it considered missing items) itself, even though they might actually have been available to kodi via other addons or scrapers.

Just as an afterthought, does the musicdb contain any track info ?  My addon scrapes theaudiodb and last.fm for info on the currently playing track and sets a window property so that a skin can display it.  EG, for 'Alive' by Pearl Jam it would display this -

"Alive" is a song by the American rock band Pearl Jam. "Alive" was Pearl Jam's first single, and appeared on the band's debut album, Ten (1991). Written by guitarist Stone Gossard, "Alive" originated as an instrumental titled "Dollar Short" and was included on a demo tape circulated in hopes of finding a singer for the group. Vocalist Eddie Vedder obtained a copy of the tape and wrote lyrics that describe a true account of the time when he was told that the man he thought was his father was not actually his biological parent. It's guitar solo is ranked 44 on Guitar World's "100 Greatest Guitar Solos".

To be honest, I don't even know if the scrapers return this level of detail but it's easily available online so my addon grabs and caches it.  If it's in the musicdb, then that's a lookup I won't need to do if a local album exists as the data will already be there, I'll just cache data for non-local albums.

I'm aware that my use-case here is probably quite niche, but Kodi is our only means of media consumption, be that live TV, films, radio, music or whatever.  It's all shared around the house and runs on every TV.  So, if I listen to the radio (and in some rooms, the TV needs to stay on) I like it to look as good as possible.

I'll shut up now, but I'll probably be back with more questions !!
Learning Linux the hard way !!
Reply
#4
OK, so what you really want is song art, use audioLibrary.GetSongs filtering on title and artist
Code:
{"jsonrpc":"2.0","id":1,"method":"audioLibrary.GetSongs",
"params":{
    "filter": {"and": [{"field": "artist", "operator": "is", "value": "Pearl Jam"},
               {"field": "title", "operator": "contains", "value": "Alive"}]},
"properties":["artist","sortartist", "displayartist","artistid","art", "musicbrainzartistid","musicbrainzalbumid","albumartist", "album"]}}
The "art" property will return the album, song artist(s) and album artist(s) art of all types.

Historically the filter fields match those available to users making smart playlists, so mbids are not included, but you could examine the resulting list of songs and pick the "best match" (however you want to prioritise that). Or widen the filter crieria to get more results.
 
Quote:does the musicdb contain any track info?
No, song data is all from tags no scraping of additional song info is done. However an addon could use JSON to add song information using SetSongDetails for subsequent repeated use, the comment field is an obvious place for such descriptive  text. Of course it would not change the music file, and the data would be wiped (replaced with the probably empty comment tag value) if you ever rescan the related music file into the library.

It is possible to make an addon that fetchs lastfm song data, saves it in library and has a export/import facility (to/from single xml say, a file per song would be bonkers!) to cover the music file rescanning situation. Using JSON for all the db access.
Reply
#5
Marvellous !!

I've been playing around with some python to grab the artwork locations, and I'm pleased to report that it all seems to be working fine.  I added a sort order to the query in an attempt to better match a track to an album.

json:
'{"jsonrpc":"2.0","id":1,"method":"audioLibrary.GetSongs","params": {"sort":{"method":"year","order":"ascending"},"filter": {"and": [{"field": "artist", "operator": "is", "value": '+ '"' + artist +'"' + '},{"field": "title", "operator":"contains", "value": ' + '"' + track + '"' +'}]},"properties":["artist","sortartist", "displayartist","artistid","art", "musicbrainzartistid","musicbrainzalbumid","albumartist", "album"]}}'

That correctly returns Hysteria first, followed by Vault: Greatest Hits 1980-1995.  Of course, that totally depends upon everything having the right year locally, but it should match a track with an album more accurately if the album is in the local library.

My addon already grabs track info from theaudioDB and falls back to last.fm in the event tadb has no info.  Currently it puts it into it's own db for re-use, but it makes more sense to me to put it into the music db if the track is in there.  That also means it will then be available to a skin when the track is played back from the library, rather than only being available if the track is being streamed.

Thank you once again for all the help.  It's much appreciated.

Lastly, I doubt I need to know where the AIF is located. As long as art is added to the db regardless of whether or not it's in use, then the queries will return the correct paths anyway.  I was going to use it to determine whether or not to use an artist/album hierarchy but if all the art is in the db, it doesn't matter anyway.

~~~ EDIT ~~~

Quick question - A fair few of my albums are re-releases of original vinyl LP's, such as all my Led Zepplin stuff.  Picard has original release date and original year tags in addition to the date tag, which is the release date of the CD.  Does Kodi use either of the original date tags, and if so, what tag(s) would I need to return in a query ?

~~~ EDIT 2 ~~~

Looking in the db, I see the following ;
sql:
mysql> desc album;
+-----------------------+--------------+------+-----+---------+----------------+
| Field                 | Type         | Null | Key | Default | Extra          |
+-----------------------+--------------+------+-----+---------+----------------+
| idAlbum               | int(11)      | NO   | PRI | NULL    | auto_increment |
| strAlbum              | varchar(256) | YES  | MUL | NULL    |                |
| strMusicBrainzAlbumID | text         | YES  | UNI | NULL    |                |
| strArtistDisp         | text         | YES  |     | NULL    |                |
| strArtistSort         | text         | YES  |     | NULL    |                |
| strGenres             | text         | YES  |     | NULL    |                |
| iYear                 | int(11)      | YES  |     | NULL    |                |
| bCompilation          | int(11)      | NO   | MUL | 0       |                |
| strMoods              | text         | YES  |     | NULL    |                |
| strStyles             | text         | YES  |     | NULL    |                |
| strThemes             | text         | YES  |     | NULL    |                |
| strReview             | text         | YES  |     | NULL    |                |
| strImage              | text         | YES  |     | NULL    |                |
| strLabel              | text         | YES  |     | NULL    |                |
| strType               | text         | YES  |     | NULL    |                |
| fRating               | float        | NO   |     | 0       |                |
| iUserrating           | int(11)      | NO   |     | 0       |                |
| lastScraped           | varchar(20)  | YES  |     | NULL    |                |
| strReleaseType        | text         | YES  |     | NULL    |                |
| iVotes                | int(11)      | NO   |     | 0       |                |
| bScrapedMBID          | int(11)      | NO   |     | 0       |                |
| strReleaseGroupMBID   | text         | YES  |     | NULL    |                |
| idInfoSetting         | int(11)      | NO   | MUL | 0       |                |
+-----------------------+--------------+------+-----+---------+----------------+
23 rows in set (0.00 sec)

So the answer would appear to be no at the moment Sad

I do think there is a use case for it though.  It would be useful to sort by release date in a skin as re-releases may not have been released in the same order as the originals.  I'm currently in the process of updating all my tags so I already have a lot of files that contain those tags.  I could force picard to use the original release date as the date, but I'd rather not if there is a chance that this could make it into v19.  What do you think @DaveBlake ?
Learning Linux the hard way !!
Reply
#6
No, not at the moment (v18), and yes there is a use case. A review of how Kodi uses the various date tags (at the moment it doesn't) it is in my sights for v19.  It has been on my mind (list) since v17 so there is a fair chance.  Smile

In fact had not the sun been shining in the UK, and had I not vanished down a SQL building rabbit hole wanting to get <group> and song rules filtering in album and artists smartplaylists finally working properly (applyng the combo criteria to the same song rather than any song ) I could even have something for you to try.

Leave your tagged dates correct, and let Kodi come to you Smile
Reply
#7
(2019-07-23, 20:24)DaveBlake Wrote: No, not at the moment (v18), and yes there is a use case. A review of how Kodi uses the various date tags (at the moment it doesn't) it is in my sights for v19.  It has been on my mind (list) since v17 so there is a fair chance.  Smile

Well, that is indeed excellent news Big Grin
(2019-07-23, 20:24)DaveBlake Wrote: In fact had not the sun been shining in the UK, and had I not vanished down a SQL building rabbit hole wanting to get <group> and song rules filtering in album and artists smartplaylists finally working properly (applyng the combo criteria to the same song rather than any song ) I could even have something for you to try.

Yeah, been rather warm recently !! Too warm in fact to sit in front of a keyboard with my head buried in python code. Although, I do have some code running alongside Kodi that performs searches on live streams, with very pleasing results so far. No rush for anything to test with, I still have to finish fixing all the tags for all the current stuff. I have realized that many albums have not had the tags updated since they were originally ripped (and in many cases, that was around 2000 - 2001) and the tags on those were very often just based upon filenames, so they aren't/weren't exactly the best set of tags. The music db was originally built on Frodo (v12) and has been upgraded version by version since then. Newer stuff has been added with better tagging but most of the core stuff has remained the same, a fact I am now rectifying, due to in a large part to you adding the ability to only scan and update changed files. A full tag scan of the library takes several hours to say the least, but at least it's now a background task.
(2019-07-23, 20:24)DaveBlake Wrote: Leave your tagged dates correct, and let Kodi come to you Smile

I will. You have already improved the music db no end and I am impressed by the fact that I can query it with a string containing multiple artists and a track name and get back all the albums that that particular track is on, plus the artistid's of those artists (assuming they are in the db) so that I can get the bio's for them. The skeleton code I have so far is working well and can pull out albums for tracks with single or multiple artists with just one call (previously I would have had to look up each artist individually).

Oh, that brings me to a question !! If an artist exists locally (but is not an albumartist) but there is no clearlogo for them, if I download a clearlogo (or indeed, other art) for them, do I need to download it into the AIF, creating any necessary directories as I go, or can I download it anywhere and use AudioLibrary.SetArtistDetails to add it ? I ask because there doesn't appear to be any art related fields for the parameters in the wiki (https://kodi.wiki/view/JSON-RPC_API/v9#A...istDetails) and I hate figuring out JSON calls !!
Learning Linux the hard way !!
Reply
#8
Quote:If an artist exists locally (but is not an albumartist) but there is no clearlogo for them, if I download a clearlogo (or indeed, other art) for them, do I need to download it into the AIF, creating any necessary directories as I go, or can I download it anywhere and use AudioLibrary.SetArtistDetails to add it ?
If you are setting the art using JSON then it can be anywhere, or even remote like the fanart.tv art. The AIF is where Kodi will find automatically pick up local artist art from when that artist is first scanned, or when scraped and it does not already have any art. Putting art you have fetched locally (or later exporting it to put a copy locally) is useful if you want to use that art on a new Kodi install etc., it would avoid the fetching and re-setting. Having a common location for art is also good if multiple addons are likely to use it, so it is something I would encourage as a final destination for local art.
 
Quote:I ask because there doesn't appear to be any art related fields for the parameters in the wiki (https://kodi.wiki/view/JSON-RPC_API/v9#A...istDetails) and I hate figuring out JSON calls !!
I wish someone would delete that wiki page, it has not been adequately maintained or updated and so worse than nothng. Also v9 was a dev version of the API anyway and no v9 (a temp pre-release version) page should even exist, Leia has v10. It is better to look at the description JSON itself produces, the wiki has only ever been a manually created (hence errors likely) version of the same text.

I hate figuring out JSON calls too. An update of wiki JSON examples would be a really useful, there are many on the forum but they are often hard to find when you want them.

EDIT:
OK here are some JSON hints.

Forget the wiki use schema files instead, on Github here
https://github.com/xbmc/xbmc/blob/Leia/x...thods.json
https://github.com/xbmc/xbmc/blob/Leia/x...types.json

JSON also self documents. With Kodi running, you can ask via JSON with command
Code:
{"jsonrpc":"2.0","id":1,"method":"JSONRPC.Introspect"}
or filter for just specific methods
Code:
{ "jsonrpc":"2.0", "id":1, "method": "JSONRPC.Introspect",
"params": { "filter": { "id": "AudioLibrary.SetArtistDetails", "type": "method" } }}

But want you really want is a working setting art example, right? Try this
Code:
{"jsonrpc": "2.0", "id": 1, "method": "AudioLibrary.SetArtistDetails",
"params": {"artistid": 2, "art":{"fanart": "image://N%3a%5cMusic%5cLib%5cPrime%5c10cc%5cfanart.jpg/"}}}
Any art type is supported (not just "fanart"), and to clear art use artist parameters "fanart": null.
You can set more than one art type at a time too.
Reply
#9
Yay, thanks for the working example Big Grin

I had already managed to figure out that

json:
{"jsonrpc":"2.0","id":1,"method":"audioLibrary.SetArtistDetails","params": {"artistid": 9999,"description":"Put your text here"}}

will update an artist bio. Next step is to add song details into 'comments' if it doesn't already exist.  I guess I could look at how artwork beef does it, but it's more fun painful to figure it out for myself.  At least this way I actually learn something rather than blindly copy/paste stuff.

Right, I'm off to bash my head against an Annie Lennox track, namely No More "I Love You's" which is causing me major headaches in getting those quotes properly escaped so that my json query doesn't throw an error !!

EDIT

Figured it !!!
Learning Linux the hard way !!
Reply

Logout Mark Read Team Forum Stats Members Help
Querying the music db for art when using the AIF0