While my group worked on trying to get this command prompt demo going I started writing a PHP page to achieve a similar goal through an interactive website. Fortunately I know PHP relatively well and found the incorporation of the last.fm API easy after looking at a couple examples included in the download file.
I found that I really liked the API. The functions were all very similar, easily replicated in multiple places. The only trouble I had was with a couple API discrepancies, for example, the API doc states that you can search for similar tracks with just a track name and the artist was optional. I found this wasn't actually true, or I simply couldn't get it to work. Here is an example of how I figured out how to access the multidimensional array returned by the similarity functions:
if ($_POST['track'] != null){
$methodVars = array(
'track' => $_POST['track'],
'artist' => $_POST['trackArtist'],
);
$tracks = $trackClass->getSimilar($methodVars);
//$similar = array();
echo "Top 50 Similar Tracks for ".$_POST['track'].":
";
echo "< id="navlist">";
$count = 0;
foreach($tracks as $key){
echo "< class="navitem">";
echo "<>";
print "< src="'">";
print "<>".$key['name']."";
print "<>".$key['artist']['name']."";
echo "< /div>";
echo "< /li>";
$count++;
if ($count == 50){
break;
}
}
echo "< /ul>";
}
So this segment of code just checks for a post variable called track, which would indicate that the user has searched for similar tracks. I decided to just break the loop because i was pressed for time and didn't want like 6 million similar tracks, and for some reason couldn't think of a better way to do it in the moment. The formatting to make the page look decent is just some CSS applied to a couple html tags, such as the list and so on. Here is some of the CSS I wrote:
ul#navlist {
position: absolute;
top: 14em;
left: 15%;
background-color: gray;
list-style: none;
padding-top: 20px;
margin: 0;
max-width: 70%;
}
li.navitem {
display: inline;
float: left;
font: 12px arial;
margin: 8px;
width: 100px;
height: 135px;
}
li.navitem a {
text-decoration: none;
color: white;
}
li.navitem a.artist {
text-decoration: none;
color: black;
}
li.navitem img {
max-height: 64px;
max-width: 64px;
}
li.navitem a:hover {
color: #00FF99;
}
li.navitem a.artist:hover {
color: #00FF99;
}
li.navitem a.artist {
text-decoration: none;
color: black;
}
This basically just makes ever list item appear as a box on the page, within a bigger UL box. This accomplished with the float and display modifiers. The hover just makes the links more appealing.
I think the cool thing about this is I might actually use it. On last.fm I have to digg through so much fluff just to actually see what I could possible also be interested in based on my interests. This tool is simple, quick and dirty.
If I could write a message to the API creator I would tell them how much it sucks how not standardized their array output is. sometimes its [images], sometimes [image], sometimes [images-medium][artist] or [track][image-medium]. This isn't a showstopper but just aggravating, (output doesn't react as you expect it to after getting used to the system.)
Overall experience: I liked the API, found it remarkably easy to use. Great examples and cool use of inheritance in their PHP code, something not too often seen in PHP, since it seems pseudo OO to me. (objects do not persist past a single page, making singleton classes and things of this nature kind of difficult to realize.)
PEACE
No comments:
Post a Comment