Last FM plays import script
Not sure if anyone cares about this... but I thought I might as well post this just in case.
I've been on a mission for a while to make my Kodi music DB more cloud based with the track and album ratings script I previously posted. The next task was to write something that imported my play data into Kodi.
I've been using for over 10 years now and have a personal history of about 15,000 plays. I wanted to get this synced up with my music DB after I wiped it accidentally during testing.
These instructions are not for normal users, but someone with better Pyton skills than me (its my first attempt) can probably make an Add-on that works more integrated.

Step 1 - export your music history
I used this site to create a csv of all my plays

Step 2 - Edit the CSV
We need to add headers to the CSV file, I just added a new text line at the top with 

Step 3 - Import into a sqlite db
I then used db browser for sqlite to import the csv into a database.
Save the DB created as lastfm.db and copy it into a folder called "c:\script\databases"

Step 4 - grab your kodi db
I just copied my raw kodi music database to the same folder as above. in this case its MyMusic72.db

Step 5 - run the python script
Copy the python code into a new file called something like "" into "c:\script"
Assuming you have a python 2.x environment setup the script should match songs and update the mymusic72 with all your plays.

Step 6 - copy back the kodi music db
Simply copy the database back to kodi userdata folder.

The end result is 10 years of song play history in my Kodi Smile

Image Image
Thanks, for this, I have 127,476 plays on, this will finally make a nice most played tracks play list Smile
Great! glad this is useful to someone.

The Long term plan would be to make this into a Kodi Addon that you just select the user and it reads the API directly and updates your plays in Kodi.

But my Python skills are not quite there yet Smile
Image Image
hi, i tried to do this right know, but im getting this error

here is my lastfm.db maby i missed something?

did it need to be a raw kodi music database?
  File "C:\script\", line 72
    print"DEBUG:", sql
SyntaxError: invalid syntax
Last fm data looks good from the download. It should be called c:\script\databases\lastfm.db
The direct copy of the Kodi database from userdata needs to be named c:\script\databases\MyMusic72.db

Then run the python script in c:\script

Hopefully that works.
Image Image
This is exactly what it looks like.

The only thing is I use a kodi 17 db, I renamed it.
Could this be a problem? I upgrade to v18 and let kodi Update the db, and try again.

I will report back if it works.

still the same error :/

do you mind upgrade my db and send it back to me Smile

kodi v17db
Sorry yeh that database is 12 versions behind the current master... Filename on download is MyMusic60.db

It must be on the latest MyMusic72.db as I think the play count fields changed at some point. That probably explains the error.

I would need your upgraded database to do it for you.
Image Image

Thank you very much!
I just wanna throw this in here because its related...

I ask for this a few times already here in the Forum but never get a answer if its possible at all...
There is a Plugin for Foobar, Soft Playlist this let you create playlists based on your profil, for example the Top Tracks from the last 3 Months, last 500 songs you played, all loved songs and so on.
I like and use it alot, right now I create a playlist, need to edit it by hand so Kodi can read it, and copy it to the playlist folder...would be very nice to see this in an plugin  Smile
Cool all done for you Smile

It worked after a little fixing of the lastfm.db. Basically the table needed to be called "plays" and the python interpreter was 2.x which I of course forgot to mention Smile

Here is your database, all updated with data.!ApVfAvr-zU1_hdpQKJzZxGJTtDhFJQ


If anyone else needs me to do this, let me know...
Image Image
Thank you very much <3
(2018-10-10, 22:08)docwra Wrote: If anyone else needs me to do this, let me know...
Are you still willing to update databases with the playcounts?

Thanks in advance
I don't think I can update anyone else's databases manually, but the instructions in the 1st post should work.

I hope someone with more python skills than me can turn this into an Add-on as has a nice API and the actual matching and SQL is pretty simple.
Image Image
Thread Rating:
  • 0 Vote(s) - 0 Average

Logout Mark Read Team Forum Stats Members Help
Last FM plays import script00