Kodi Community Forum

Full Version: JsonRpc best way To..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone, I wanted to know what is the best way to notice that something has changed at the database level.

I am using the JSONRPC from my app and I would like to see if the libraries have changed.
Example, if from the KODI interface I perform a scan of the libraries because I have added films and then I open my app, what call should I make to understand if i have to refresh the information?
Is there something like a call that gives me like a HASH of my libraries so that I can notice if they have changed?
Thanks so much
I usually just retrieve the list of songs and limits the results to 1 (Same thing works for tvshows and movies). In addition you could also include the "dateadded" field and verify if the last added song is still the same ( in case you removed 1 song and added another one )

Code:
{"jsonrpc":"2.0","method":"AudioLibrary.GetSongs","params":{"properties":["dateadded"],"limits":{"end":1,"start":0},"sort":{"ignorearticle":true,"method":"dateadded","order":"descending"}},"id":10}

The json-rpc call then returns the total number of items in your library which you can use to compare with the number of items in your local cache. In additon you could also check if your local cache contains the song with the most recently added songId

Code:
{
   "limits":{
      "end":1,
      "start":0,
      "total":17566
   },
   "songs":[
      {
         "dateadded":"2021-02-06 20:56:53",
         "label":"My song",
         "songid":217
      }
   ]
}

Keep in mind that the Kodi db also contains other metadata which gets updated all the time like play count, last played, resume points etc.. If you need up to date data for these fields your db will be outdated every time you played a media item
This is an area where the music library in v19 has moved ahead of the video library, see AudioLibrary.GetProperties which can be used to retrieve properties: "missingartistid", "librarylastupdated", "librarylastcleaned", "artistlinksupdated", "songslastadded", "albumslastadded", "artistslastadded", "genreslastadded", "songsmodified", "albumsmodified", "artistsmodified".

These values can use used to decide if the music library has changed, what way it has changed and  what new data needs to be requested. The ID are also not updated every time music is rescanned and hence are fixed while Kodi knows about a given source. So the entire music library does not need to be requested when things like playcount, last played etc. change, you can just fetch the songs modified since a date. See https://github.com/xbmc/xbmc/pull/18026
Thank you so much ti all,
I'll implement some of these solutions and i Will update you.