Page 1 of 1

Script to Populate Play_Count and Last_Played from

Posted: 23 Mar 2016, 22:20
by baileyb622
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 I figured there should be a way to scrape that data and update the Madsonic database. Thus, I wrote the following python script: ...

What you will need:
- A API Key:
- Your 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`

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 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

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!

Re: Script to Populate Play_Count and Last_Played from Last.

Posted: 20 Feb 2017, 16:57
by Matt Zornig
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.