Hi there,
I am trying to add additional code to my script that interacts with my iTunes player.
At the moment the code listed below shows an image of LP from amazon, title, artist, LP and itunes link if available.
Now after this initial dispaly I would also like to be able to list additional listings from my XML file of other tracks I have listend to.
So first off is my main track then after that I would like to say something like:
Also been listening to:
song title by artist
song title by artist
song title by artist
song title by artist
Can anyone help me with this - it is somewhat out of my current knowledge base.
<?php
$file = "/home/public_html/itunes/now_playing.xml";
$xml_parser = xml_parser_create();
if ( is_file( $file ) )
{
$fp = fopen( $file, "r" );
$data = fread( $fp, filesize( $file ) );
fclose( $fp );
xml_parse_into_struct( $xml_parser, $data, $vals, $index );
xml_parser_free( $xml_parser );
# Uncomment the following lines for testing
if ( $debug )
{
echo "<pre>";
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
echo "</pre>\n\n";
}
$title = $vals[2]["value"];
$artist = $vals[5]["value"];
$album = $vals[8]["value"];
$genre = $vals[11]["value"];
$kind = $vals[14]["value"];
$track = $vals[17]["value"];
$numtracks = $vals[20]["value"];
$year = $vals[23]["value"];
$comments = $vals[26]["value"];
$songtime = $vals[29]["value"];
$bitrate = $vals[32]["value"];
$rating = $vals[35]["value"];
$disc = $vals[38]["value"];
$numdiscs = $vals[41]["value"];
$playcount = $vals[44]["value"];
$compilation = $vals[47]["value"];
$urlamazon = $vals[50]["value"];
$urlapple = $vals[53]["value"];
$imageurl = $vals[56]["value"];
if ( strlen( $title ) > 0 )
{
if ( strlen( $imageurl ) == 0 )
{
$imageurl = '/itunes/music-no-image.gif';
$AlbumArtCell = '';
}
else
{
list($width, $height, $type, $attr) = getimagesize( $imageurl );
if ( $width == 1 || $height == 1 )
{
$imageurl = '/itunes/music-no-image.gif';
$AlbumArtCell = '';
}
}
#
# If we couldn't find them at Amazon, let's just do an artist search at HMV
#
if ( strlen( $urlamazon ) == 0 )
{
$urlamazon = 'http://www2.hmv.co.uk/hmvweb/simpleSearch.do?pGroupID=1&simpleSearchString=' . urlencode( $artist ) . '&primaryID=1&btnSearchGo.x=2&btnSearchGo.y=12';
}
echo '<div id="iTunes">' . $AlbumArtCell . '<a href= ' . $urlamazon . ' target="new" class="noline"><img src=' . $imageurl . ' alt=' . urlencode( $artist ) . ' - ' . urlencode( $album ) . ' /></a></div>';
echo '<li><strong>Track:</strong> <a href=' . $urlamazon . ' target="new"><strong>' . $title . '</strong></a></li>';
if ( strlen( $comments ) > 0 )
{
echo '<li><strong>Remix:</strong> ' . $comments . '</li>';
}
echo '<li><strong>Artist:</strong> ' . $artist . '</li>';
if ( strlen( $album ) > 0 )
{
echo '<li><strong>CD:</strong> ' . $album . '</li>';
}
if ( strlen( $rating ) > 0 )
{
echo '<li><strong>My Star Rating </strong><img src=/itunes/stars-' . $rating . '.gif alt=Rating /></li>' . "\n";
}
if ( strlen( $urlapple ) > 0 )
{
echo '<li><a href=' . $urlapple . '>Buy from iTunes</a></li>' . "\n";
}
if ( $debug )
{
echo "</script>\n";
}
}
}
?>
Thank you