Script to Populate Play_Count and Last_Played from Last.fm

Frequently asked questions. Tutorials, tips and tricks.

Script to Populate Play_Count and Last_Played from Last.fm

Unread postby baileyb622 » 23 Mar 2016, 22:20

So over the weekend I managed to really mess up my madsonic install, db, and backup db. The ultimate solution was a completely fresh install. Unfortunately this meant I lost all of my play statistics. Since I scrobble everything to Last.fm I figured there should be a way to scrape that data and update the Madsonic database. Thus, I wrote the following python script: https://github.com/philosowaffle/script ... c_query.py

What you will need:
- A Last.fm API Key: http://www.last.fm/api
- Your Last.fm Username
- Python 2.7.11

1) In the script, replace YOUR_API_KEY_HERE and YOUR_USER_NAME_HERE with the correct values respectively.

2) From the command line run `python lastfm_to_madsonic_query.py`

3) Be patient, depending on your number of scrobbles this could take a while. If you find it takes too long, or you exceed your API queries you can adjust how far back in time to look by changing the for-loops at lines 77 and 97.

4) When the script completes you will find a file called 'temp.txt' in the same directory. Inside of this file should be a long list of UPDATE statements, one for every song you have ever scrobbled to Last.fm. Now you may not have all of these songs in your Madsonic library, but that is ok, the database will simply ignore any songs it cannot find. These statements will set the play_count and last_played fields in your database for each of the songs listed. IMPORTANT - These statements will REPLACE any previous data in these two fields.

5) Go to you database view http://my.madsonic.com/db.view

6) Copy and paste the UPDATE statements into the DB console and click OK. IMPORTANT - These statements will REPLACE any previous data in these two fields. If you copy too many statements into the console at once it may error out, that's ok. Just refresh the page and try doing fewer queries at a time. I found that about 1000 queries at once was the threshold.

And that's it! You should now have playcount and lastplayed data re-populated in your database!
baileyb622
Contributor
Contributor
 
Posts: 9
Joined: 14 Jan 2016, 18:26
Has thanked: 2 times
Been thanked: 7 times

Re: Script to Populate Play_Count and Last_Played from Last.

Unread postby Matt Zornig » 20 Feb 2017, 16:57

I don't think, I will ever use this, but I'd like to thank you for contributing this script to the community!
I find your explanation and hints very useful for people looking for such an easy way to get their playcounts back.
User avatar
Matt Zornig
Contributor
Contributor
 
Posts: 121
Joined: 14 Feb 2017, 12:03
Has thanked: 21 times
Been thanked: 13 times


Return to Info

Who is online

Users browsing this forum: No registered users and 1 guest