if ($url)
{
header ("Location: $url");
} else {
// no artist found -- send them to Taro Sound!
header ('Location: http://www.emusic.com/album/Quasar-Wut-Wut-Taro-Sound-MP3-Download/11266990.html?fref=400072');
}
} else {
exit('Failed to open.');
}
} else {
// no artist passed -- send them to Taro Sound!
header ('Location: http://www.emusic.com/album/Quasar-Wut-Wut-Taro-Sound-MP3-Download/11266990.html?fref=400072');
}
I needed something to take an artist name and redirect to their emusic page. Here's what I came up with. Any feedback would be appreciated:
<?php
// This page expects Artist Name to be included in the querystring: ?a=Wilco
parse_str(($_SERVER['QUERY_STRING']));
if ( $a )
{
if ( $xml = simplexml_load_file('http://api.emusic.com/artist/search?apiKey=myKey&term=' . $a .'&fref=400072', 'SimpleXMLElement', LIBXML_NOCDATA) )
{
$url = $xml->artists->artist[0]['url'];
if ($url)
{
header ("Location: $url");
} else {
// no artist found -- send them to Taro Sound!
header ('Location: http://www.emusic.com/album/Quasar-Wut-Wut-Taro-Sound-MP3-Download/11266990.html?fref=400072');
}
} else {
exit('Failed to open.');
}
} else {
// no artist passed -- send them to Taro Sound!
header ('Location: http://www.emusic.com/album/Quasar-Wut-Wut-Taro-Sound-MP3-Download/11266990.html?fref=400072');
}
?>
Message edited by gloriousnoise 8 months ago
Tags
Nicolas Chevallier – 1 year ago
Thanks for sharing, I use some code to developp a future webservice based on emusic.
juliston – 8 months ago
Thanks for your code