Amarok MySQL

In Linux, my favorite music player is MPD for its simplicity, for running as a daemon, and for allowing me to choose between various GUI options (or none), but sometimes I miss some features, such as play count, playlist generators, fetching covers, integration with Last.fm and Wikipedia, artist “Various,” among many other functions.
The feature-rich player for Linux is probably Amarok.

Usually, I don’t install Amarok as my default player because it is heavy, consumes a lot of memory, and depends on some QT libraries. But even so, at some point, I abandon my principles of simplicity and install the wolf player (to go back to using MPD later…)

By default, Amarok uses an SQLite database, which is sufficient for those who only use one computer and have few songs. That’s not my case (my music folder is close to 600GB).
For people with large libraries like mine, using MySQL can significantly improve performance. I will try to detail the installation in the following lines.

Install Amarok2 and MySQL:

sudo pacman -S amarok mysql

Configure MySQL and add mysqld to the rc.conf daemons

Create the amarokdb database, create the amarok user, and set a password:

sudo mysql -p -u root
  CREATE DATABASE amarokdb;
  USE amarokdb;
  GRANT ALL ON amarokdb.* TO amarok@'%' IDENTIFIED BY 'sua_senha';
  FLUSH PRIVILEGES;
  quit

With this configuration, I can share the database with other machines. To allow only local access, change the fourth line to:

GRANT ALL ON amarokdb.* TO amarok@localhost IDENTIFIED BY 'your_password';

Open Amarok, go to Setings… » Configure Amarok » Database, and check Use external MySQL database. Fill in the information and restart the program.

Explore the thousands of features.

After setting up and updating the library, I use a plugin that synchronizes my playcount with Last.fm’s. The plugin is called Klastfm and can be found here.

It has been a year since the developer last updated the script, so I had to manually fix some errors.

First, install Ruby 1.8.7 and rubygems-1.8:

Install the following Ruby packages:

sudo gem-1.8 install activerecord mysql httparty progressbar ya2yaml —no-rdoc —no-ri

Comment out line #27 in the klastfm.rb file:

line 27: #ActiveRecord::Base.logger = Logger.new('log/database.log')

On line 93, change

@lastfm.tracks_in_week(week['from'], week['to']).each do |track|

to

[*@lastfm.tracks_in_week(week['from'], week['to'])].each do |track|

Copy the file /config/config.yaml.example to /config/config.yaml and add your Last.fm API, which can be found at http://www.last.fm/api/account.

ruby-1.8 klastfm.rb runs the program. It will download all your scrobbles from Last.fm and merge them with the Amarok database. This process takes a while, but it’s worth it.

creating a statistic entry for every track
creating stat: 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 00:00:57

getting all tracks you ever submitted to last.fm (ca. 15050)
get playcount: 100% |ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 01:05:29

getting all tracks played in the last 163 weeks
klastfm.rb:93:in `date_tracks': undefined method `each' for nil:NilClass (NoMethodError)oooooooooooooooooooooooooooooooooooooooooooo          | ETA:  00:01:55
        from klastfm.rb:91:in `each'
        from klastfm.rb:91:in `date_tracks'
        from klastfm.rb:144

Keeping the database synchronized is beneficial as it makes generating playlists easier, for example.

Julio Batista Silva
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus