Amarok MySQL

Jun 16, 2011·
Julio Batista Silva
Julio Batista Silva
· 3 min read
blog Multimídia

On Linux, my favorite music player is MPD, for its simplicity, for running as a daemon and for letting me pick between several GUI options (or none at all). But sometimes I miss a few features, such as a play counter, playlist generators, cover fetching, Last.fm and Wikipedia integration, the “Various” artist, and many other functions.
The Linux player with the most features is probably Amarok.

Usually the only reason I do not install Amarok as my default player is that it is heavy, uses a lot of memory and depends on some QT libraries. Even so, at some point I abandon my principles of simplicity and install the wolf’s player (only to go back to MPD later…)

By default, Amarok uses an SQLite database, which is enough for anyone who only uses one computer and has few songs. That is not my case (my music folder is closing in on 600GB).
For people with large libraries like mine, using MySQL can improve performance considerably. I will try to detail the installation in the lines that follow.

Install Amarok2 and MySQL:

sudo pacman -S amarok mysql

Configure MySQL and add mysqld to the daemons in rc.conf.

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 'your_password';
  FLUSH PRIVILEGES;
  quit

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

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

Open Amarok, go to Settings… » Configure Amarok » Database and tick Use external MySQL database. Fill in the details and restart the program.

Explore the thousands of features.

Right after configuring and updating the library, I use a plugin that syncs my playcount with the one on Last.fm. The plugin is called Klastfm and can be found here.

The developer has not updated the script for a year, so I had to fix a few errors by hand.

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 of the klastfm.rb file:

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

On line 93, replace

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

with

[*@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 key, which can be found at http://www.last.fm/api/account.

ruby-1.8 klastfm.rb runs the program. It will download all your Last.fm scrobbles and merge them with Amarok’s database. This takes a good while, but it is 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 in sync is worthwhile, since it makes generating playlists easier, for example.

Julio Batista Silva
Authors
Senior Cloud Developer

I’m a Brazilian-German computer engineer based in Germany, passionate about tech, science, photography, and languages.

I’ve been programming for about two decades already, exploring everything from mobile apps and web development to machine learning. These days I focus on cloud SRE and data engineering.

I volunteer in the open source and Python communities, helping organize PyCon DE and PyData Berlin, serving on the PSF D&I Work Group, mentoring, and contributing code and translations.

On my blog, I share Linux tips, setup guides, and personal notes I’ve written for future reference. I hope others find them helpful as well. The content is available in multiple languages.

Browse my gallery for some of my photography.

Away from the keyboard, you’ll find me at concerts, playing clarinet, cycling, scuba diving, or exploring new places, cultures, and cuisines.

Always happy to connect! 🙂

comments powered by Disqus