Last Sync

Amarok 1.x Scripts

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on


=> Lastsync? What the ... (the short way)
Lastsync is a ruby script to download your statistics like playcount of your music files and save it to your Amarok database. This is particular useful if you scrobble from many sources (Linux, Windows, iPod ...) but want to have a accurate Amarok statistic (e.g. for creating dynamic playlists).

=> What this script does (the long way) provides their complete information in a XML format for easy access (see for more details), but there's no way to see the complete playcount of all tracks ever listened (the "Top Tracks" stream only shows the Top 50). To solve this problem, the script downloads your complete "Weekly Chart List" history and processes week by week, summing up the playcount of all weeks. The script then searches for each track in your Amarok database and sets the playcount, score, last played and first played time of the appropriate files. This is not completely accurate, but works (for me it counted 23.000 of my 24.000 plays), to achieve the best results run it Sunday Noon, after updates their Weekly Chart.
Please note that the script currently only runs with a SQLite Amarok-backend.

=> Features
- Retrieve your stats (playcount, score, last played, first played) and save it to your Amarok
- Correct misstagged id3 tags
- Supported backend: SQLite
- More to come :D

=> Known Bugs
This is my first ruby script, so it is pretty hacked together and there will be bugs, so always make a backup of your collection.db! You have been warned!

I want to improve my Ruby skills, so comments or improvements are very welcome.
If you found a bug, want to make a feature request or just want to say "thank you", you can leave a comment, write an email or make a shout to my shoutbox under

For usage and more info see the README file.


11 years ago

all i get is this

chris@linux-y76din7PC:~/Desktop/lastsync> ./lastsync.rb "eagles500"
./amarok.rb:14:in `require': no such file to load -- sqlite3 (LoadError)
from ./amarok.rb:14
from ./lastsync.rb:18:in `require'
from ./lastsync.rb:18
any suggestions on how i can make it run through

im on openSuSE 11.1



12 years ago

Any plans for Amarok 2? That would be really great, especially because I have to rebuild my collection very often.



12 years ago

Hi there!

To fix the quotation error, just add this line

name = name.gsub('"', '""')

in the function getURL, at module amarok.rb, just after

if artist == nil or name == nil
return nil



12 years ago

I run the script but it doesn't affect my playcounts.

Here's what I get:

Backing up Amarok collection under /home/karl/.kde/share/apps/amarok/collection.db~
Loading Replace List ...
/usr/lib/ruby/1.8/rexml/source.rb:156:in `readline': end of file reached (EOFError)
from /usr/lib/ruby/1.8/rexml/source.rb:156:in `initialize'
from /usr/lib/ruby/1.8/rexml/source.rb:16:in `new'
from /usr/lib/ruby/1.8/rexml/source.rb:16:in `create_from'
from /usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:130:in `stream='
from /usr/lib/ruby/1.8/rexml/parsers/baseparser.rb:107:in `initialize'
from /usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `new'
from /usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:8:in `initialize'
from /usr/lib/ruby/1.8/rexml/document.rb:205:in `new'
from /usr/lib/ruby/1.8/rexml/document.rb:205:in `build'
from /usr/lib/ruby/1.8/rexml/document.rb:42:in `initialize'
from ./lastfm.rb:39:in `new'
from ./lastfm.rb:39:in `initialize'
from ./lastsync.rb:55:in `new'
from ./lastsync.rb:55



13 years ago

I'm trying to make this run on amarok 1.4.8 but I get the following error when I run it on the terminal

/usr/lib/ruby/site_ruby/1.8/sqlite3/errors.rb:94:in `check': near "weird": syntax error (SQLite3::SQLException)
from /usr/lib/ruby/site_ruby/1.8/sqlite3/statement.rb:71:in `initialize'
from /usr/lib/ruby/site_ruby/1.8/sqlite3/database.rb:184:in `new'
from /usr/lib/ruby/site_ruby/1.8/sqlite3/database.rb:184:in `prepare'
from /usr/lib/ruby/site_ruby/1.8/sqlite3/database.rb:211:in `execute'
from /usr/lib/ruby/site_ruby/1.8/sqlite3/database.rb:292:in `get_first_row'
from ./amarok.rb:32:in `getURL'
from ./amarok.rb:141:in `update'
from ./lastsync.rb:61
from ./lastsync.rb:60:in `each'
from ./lastsync.rb:60
from ./lastsync.rb:58:in `each'
from ./lastsync.rb:58

Any idea?



12 years ago

To fix this issue i pass the parameters to the query via the questionmark placeholders, in doing so i quote the variables using the database layer!

so... replace line 32 of amarok.rb with:

resultArtist = @db.get_first_row("SELECT * FROM artist WHERE LOWER(name) = ?", artist.downcase)

and also line 38 with:

result = @db.get_first_row("SELECT * FROM tags WHERE artist = ? AND LOWER(title) = ?", resultArtist[0], name.downcase)

and that should fix



12 years ago

The script fails any time it comes across a quotation mark in a song title... or an artist name, I guess. All you need to do is navigate to ~/.kde/share/apps/amarok/scripts/lastsync/data and find the .xml file that the script crashed on. Open it in gedit or whatever and then type ctrl+f to search and type " and delete the song entry (or entries) from the .xml file. I've found that restoring the backup collection.db file is wise prior to re-running the script, so delete the file home/user/.kde/share/apps/amarok/collection.db and rename home/user/.kde/share/apps/amarok/collection.db~ deleting the tilde and you should be good to go. Depending on how long you've been on you may have to repeat this process several times in order for the script to complete.



13 years ago

any chance for a MySql version some day?




13 years ago

Well it should be easy to do this, I will have a look into it ...


Be the first to comment
Dec 09 2009
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
0 Affiliates
0.1 *beta*
updated Sep 06 2007
added Sep 06 2007
downloads 24h
mediaviews 24h 0
pageviews 24h 0
System Tags addon