2 Tags: en, lastfm, last.fm, bandlogos, cli, free software, floss, image, php
4 Recently I discovered this very nice website to generate your most played band
5 in Last.fm__ called Bandlogos__. The first thing you want to do is generate
6 images with different layouts and colors to try it out, but unfortunately, you
7 hit a limit very quickly, and you can't generate new logos for 15 days, which is
8 a considerable amount of time. I also got the same problem after 15 days, so
9 I never managed to generate the kind of banner I wanted.
11 __ http://www.last.fm/
12 __ http://bandlogos.descentrecords.com/
14 The good news is the source code is available, and the author encourages people
15 hosting they own copy of the website, so I couldn't resisted the temptation and
16 downloaded the code. Again with the bad new, the code is pretty nasty (but you
17 don't have to be very surprised with PHP__ programmers =P). Don't get me wrong,
18 I love the guy who did this, the results are amazing, but I can't ignore this
19 little detail because trying to hack that code can be a traumatic experience.
21 __ http://www.php.net/
23 Anyway, I didn't wanted to make a whole website with this, I just wanted to cron
24 the banner generation to make a new banner daily, so I started hacking. Then
25 I found out this little thing needed a DB__, and not just any DB using one of
26 the tens of DB abstraction libraries, it only works with MySQL__. Of course
27 installing a MySQL server just for this was a ridiculous idea, so the first hack
28 was to implement a SQLite__ backend. It was fairly easy, except for the bits
29 that used some MySQL only features, so I had to cut down the cache functionality
30 (which I didn't wanted anyway).
32 __ http://en.wikipedia.org/wiki/Database
33 __ http://www.mysql.com/
34 __ http://www.sqlite.org/
36 But then, each time I wanted to add a new logo, I had to run a script to update
37 the DB with the new logo, instead of just throwing the new file in the logos
38 directories, so it came the time to be a butcher and completely chop that script
39 to cut off all the fat =P
41 The result is a small 500 SLOC__ CLI__ script (compared to the ~ 1700 SLOC of
42 the original script) that you can run directly from the console (or cron),
43 doesn't need a DB and support all the features of the original script (except
44 caching, which makes no sense for this) plus some goodies (like ability to make
45 a banner with the music you played last week or picking an arbitrary color or
46 using an arbitrary number of columns for the layout, or extra configurability
47 using command line options).
49 __ http://en.wikipedia.org/wiki/Source_lines_of_code
50 __ http://en.wikipedia.org/wiki/Command-line_interface
52 As an overview, take a look at the script command line help::
54 bandlogos-cli: generate last.fm most listened bands logos banner.
56 Usage: ./bandlogos-cli.php [options] LASTFM_USER
61 Period to use to get the most listened bands (possible values: 7day,
62 1month, 6month, 12month or overall; default: 7day).
65 Banner style/color (possible values: black, gray, blue, red, orange,
66 turquoise, trans, white or an arbitrary RGB value specified using 0-255
67 values separated with commas, 246,146,30 for example; default: black).
69 -n, --number-of-artists
70 Number of artists (logos) to put in the banner (natural number;
74 Number of columns of logos to display in the banner (natural number;
78 Force a width for the banner (in pixels; default: automatically
79 calculated based on the number of columns).
82 Last.fm API key to use to retrieve user statistics (you probably don't
83 need or want to change this; default: db109383394640f2b5e174b4514f0014).
86 Gray value to use to do some image filtering (number in the range
90 Margin to leave at the top of the banner (in pixels; default 4).
93 Separation between band logos (in pixels; default 5).
96 Directory where to search for band logos to build the banner
100 Show this help message.
104 .. vim: set et sw=3 sts=3 :