By Dan Barrett - yesdevnull.net/lastfm
Easily get images for a top 10 list for your Last.fm profile.
I'm using this on my website to generate Last.fm album artwork - you can see it on my profile here.
Originally, my image generator was a pretty rushed job and didn't look very pretty. I started using Laravel recently and decided to port my code over to Laravel, with the goal of open sourcing this codebase.
I have limited the code to max out at the first 10 albums from the Last.fm API, but if you know what you're doing, you can modify it to pull down much more.
By providing your Last.fm username and the album number in a query string you'll get the image returned.
?user=yourusername&num=1
You can also get a link returned instead of an image so you can have a URL that will redirect users to the Last.fm album page. To do this, add the variable type
with the value link
- or &type=link
.
If you enter the address /generator
you'll land on an HTML form where you can enter your Last.fm username and get the BBCode required for Last.fm's profile page.
- PHP 5.4 or greater
While this codebase is based on Laravel 4 (laravel/framework), you'll also need a few other libraries. While these are listed in the composer.json
file, you'll find the list below:
- laravel/framework
- intervention/image
- nesbot/carbon
- pda/pheanstalk
- guzzle/guzzle
- phpunit/phpunit
- whatthejeff/nyancat-phpunit-resultprinter
You'll also need to be running Beanstalkd, a simple, fast work queue system if you want to use the queuing system in Laravel. If you don't have it installed and working, the queue system will process straight away, rather than being a proper queue system...
Once you've pulled down the codebase, it's important to do a few things. First off, using composer you should install the rest of the dependancies:
composer update
Or php composer.phar update
if Composer isn't in your bin path.
Next, you should run
php artisan key:generate
This will change the application key, as each installation should have a different, unique key. Composer should hopefully do this already for you, but there's no harm in running it again.
You may also find that you need to change the default Queue driver in app/config/queue.php
to sync
if you're not using Beanstalkd.
I've written some tests, but it's my first time doing unit tests and using PHPUnit. In its current state, there are 21 tests and 77 assertions, and all should pass. I also spent some time making sure it's mostly compliant with PSR-1 and PSR-2. As my codebase isn't namespaced, PHP_CodeSniffer will freak out a bit.