Last FM plays import script
#1
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 Last.fm play data into Kodi.
I've been using Last.fm 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 last.fm music history
I used this site to create a csv of all my plays https://benjaminbenben.com/lastfm-to-csv/

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 
Code:
Artist,Album,Title,DatePlayed

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 "last_fm_import.py" into "c:\script"
Assuming you have a python 2.x environment setup the script should match songs and update the mymusic72 with all your last.fm plays.
https://gist.github.com/zag2me/9b8625100...bc1c580b50

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
Reply
#2
Thanks, for this, I have 127,476 plays on last.fm, this will finally make a nice most played tracks play list Smile
Reply
#3
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 last.fm API directly and updates your plays in Kodi.

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

here is my lastfm.db maby i missed something?
https://drive.google.com/open?id=1u7fQTD...vTzhEnok3n

did it need to be a raw kodi music database?
Quote:C:\script>lastfmscript.py
  File "C:\script\lastfmscript.py", line 72
    print"DEBUG:", sql
                ^
SyntaxError: invalid syntax
Reply
#5
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.
Reply
#6
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
https://drive.google.com/open?id=1z8y7ge...ZgSX9DllC7
Reply
#7
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.
Reply
#8
https://drive.google.com/file/d/17H3NrcM...p=drivesdk

Thank you very much!
Reply
#9
I just wanna throw this in here because its Last.fm 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 https://www.foobar2000.org/components/vi...tplaylists this let you create playlists based on your last.fm 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 Last.fm plugin  Smile
Reply
#10
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 last.fm data. https://1drv.ms/u/s!ApVfAvr-zU1_hdpQKJzZxGJTtDhFJQ

Image

If anyone else needs me to do this, let me know...
Reply
#11
Thank you very much <3
Reply
#12
(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 last.fm playcounts?

Thanks in advance
Reply
#13
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 Last.fm has a nice API and the actual matching and SQL is pretty simple.
Reply
#14
Hello :-) I'm trying to play this game, but....

can you please give more detailed information to step 3?

I downloaded Version 3.11.2 from https://sqlitebrowser.org/

but it has no CSV import and I don't have any idea how to create a suitable database to put the CSV in.
 
(2018-09-28, 23:08)docwra Wrote: 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"
Reply
#15
(2019-07-29, 04:37)xbozzo Wrote: but it has no CSV import and I don't have any idea how to create a suitable database to put the CSV in.
Sounds like you have not created the Database first.

Select File then select New database... and name it lastfm.db

Once created a box will pop up asking to Edit table definition. Cancel this.

The Import from csv should now be available.
My Signature
Links to : Official:Forum rules (wiki) | Official:Forum rules/Banned add-ons (wiki) | Debug Log (wiki)
Links to : HOW-TO:Create Music Library (wiki) | HOW-TO:Create_Video_Library (wiki)  ||  Artwork (wiki) | Basic controls (wiki) | Import-export library (wiki) | Movie sets (wiki) | Movie universe (wiki) | NFO files (wiki) | Quick start guide (wiki)
Reply

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