More Flexible Firefly Smart Playlists with Perl, sqlite3 and m3u

I use Firefly (previously called mt-daapd) as a media server for my Roku Soundbridge. It has a feature called ‘Smart Playlists’ that dynamically create playlists based on certain criteria, but they aren’t that powerful - they don’t support sorting or other more advanced query features.

Fortunately, underlying Firefly is a sqlite database, which can be queried using standard SQL syntax. This enables a technique of creating static playlists that are automatically re-generated periodically instead.

The prerequisites for the following technique are:

  • Perl, with the File::Spec module (to convert from absolute paths to relative ones, which is what Firefly expects).

  • The sqlite3 command-line interface.

The three commands that follow will create a standard .m3u playlist with the top 100 most-played songs from Firefly’s database, and another playlist with all the non-Podcasts added in the last month, ordered by the time they were added. Neither of these are possible using Firefly’s query language.

sqlite3 /var/cache/mt-daapd/songs3.db 'select path from songs order by play_count desc limit 100' | perl -nle 'require File::Spec; $_ = File::Spec->abs2rel($_, "$PLAYLIST_DIR"); print;' > "$PLAYLIST_DIR/Most-played songs.m3u"

MONTHAGO=$(perl -e 'use Date::Calc::Object qw(:all); $date = Date::Calc>now(); $date += [0,-1,0,0,0,0]; print $date->mktime();')

sqlite3 var/cache/mt-daapd/songs3.db "select path from songs where genre!='Podcast' and time_added > $MONTHAGO order by time_added desc" | perl -nle 'require File::Spec; $_ = File::Spec->abs2rel($_, "$PLAYLIST_DIR"); print;' > "$PLAYLIST_DIR/Music added in last month by most recent.m3u"

(obviously, if you use these, you’ll need to alter paths to suit, make sure the correct Perl modules are installed, remove line breaks to make it easier to read, etc.)

Firefly will read these .m3us if configured correctly during its next rescan, and use them as it would any other playlists. You can force a rescan with the following wget command:

wget --delete-after -q --http-user noone --http-password yourpasswd "http://localhost:3689/config-update.html?action=rescan"

Although not fully dynamic (they are not generated on request from the Soundbridge), if these commands are called from cron or similar, the playlist can be kept up-to-date ‘enough’.

Online Address Frustration

I’m surprised at the poor state of online contact management, given how mature the online e-mail market is. I’ve just spent a frustrating and mostly wasted morning with Plaxo, trying to see if it could fulfil my relatively simple needs (online contact management, syncing with something desktop-based, ideally Thunderbird, and syncing with my mobile phone as a nice to have). After struggling with the over-engineered Plaxo interface, a wobbly Thunderbird sync extension that loses critical bits of data, and a de-duper that misses obvious duplicates, I gave up. The latter service requires signing up to a free trial, which I’ve now cancelled.

At some point I’ll give Yahoo Address Book a go - initial investigations look good, it does away with the unnecessary social networking guff (I’m already signed up to Facebook and LinkedIn, thanks, Plaxo - try focusing a little harder on your core business), and is much speedier. Unfortunately, the Yahoo effort seems to be a bit basic - mainly a lack of sync points - but at least that does remove some of the potential for damage.

Does anyone know of any other solutions? I was willing to pay for Plaxo, and I can’t be the only one. I think there’s an unmet need here.

The Rescuers

The Rescuers is perfect for Christmas - it’s a lovely family movie without the irritating Christmas tat. From its basic yet beautiful introduction with static paintings. through the robust characterisation, rough animation and moving song, it’s a classic from start to finish, especially compared to some of the more recent Disney fare. It’s well plotted, with no parts that drag or bore. The voice talent, particularly Oscar-winning Geraldine Page as Madame Medusa is hilarious and well-timed. The well-named Evinrude (a real brand of motorboat engine) is very funny. It has the typical Disney blend of humour, drama, and sentiment that makes them such a good watch. Walt Disney would be proud.

Merry Christmas, everyone.

Subscribers on Google Reader

Tip for anyone who blogs and uses Google Reader:  the new ‘Discover’ feature of Google Reader enables you to see how many people are subscribed to your blog. Select ‘Browse’ and search for your blog using keywords. When you’ve found it, it’ll show how many subscribers there are. Take the number with a pinch of salt: it is, of course, only one of many blog readers, albeit a popular one.

Les Livres

Every time I get sad about the illiberal attitudes of the public sector in the UK, at least I can reassure myself that I don’t live in France.

subscribe via RSS