I’ll say right away - for people who do not know what
last.fm is (or for people who do not use this social network), this post will not necessarily be useless. You can make, based on my code, for example, a picture that displays the last ten topics on your forum.
Those who are familiar with the last.fm social network are probably aware of the presence of so-called
image charts . These are generated images that you can insert into your blog, in a signature or somewhere else. What did you listen to during the week, that you listened literally now, which performers do you most listen to ...
So, once I was not satisfied with such charts, despite the many ready-made styles (and the ability to create new ones). Well, I don’t like, I don’t like smoothed fonts! I decided to write a PHP script with a similar list of Recent Tracks / Top artists, which could be inserted as an image.
PHP setup
(If you didn’t work with the gd library for PHP before. If you’ve worked and everything is set up, feel free to skip this step.)
')
We need a web server with PHP and the gd library connected to it. There are no problems with PHP under Windows - you just need to uncomment one line in php.ini:
extension=php_gd2.dll
And, probably, it will be necessary to specify a directory in which all dll'ki lie:
extension_dir = "X:\php\ext\"
Under Linux - Ubuntu has already done everything for you - the official repositories have the php5-gd package. Look in the repositories of your distribution. As a last resort - you will have to compile PHP from source with the - with - gd option. Then similarly connect the gd library to PHP.
Learn more about working with the Audioscrobbler server.
The
site Audioscrobbler has a
table that lists all the available information and how to get it - Plain, XML, XSPF, iCal, RSS.
For me, so Plain is the easiest of all. For example, take the Recent tracks, that is, the last 10 tracks heard.
To check, go here:
http://ws.audioscrobbler.com/1.0/user/username/recenttracks.txt
(Where
username is your last.fm username)
Before the comma is the time when the track was played
(can be converted using the date function) . After the comma - what we need is the performer and the name of the track. Well, then you are limited only by your own fantasy :)
Oh yes. I warn you right away. Cyrillic has big problems with imagestring, so either convert Cyrillic to translit or use ttf for drawing.
Also, there may be a problem with various non-standard characters (such as aumlets). The problem can be solved either with the usual function str_replace, or with the non-standard function
html_to_utf8 together with str_replace.
Ready PHP script for recent tracks with comments
I hope it will be at least interesting / useful for someone. Constructive criticism on the design of habratopics is very welcome, since I'm still new. :)
Scripting can be viewed in my profile -
i0ngunn3r .