function getPreviewEcho($artistInfo, $track, $ApiKey) { $jsonDump = uwe_file_get_contents("http://developer.echonest.com/api/v4/song/search?api_key=" . $ApiKey . "&format=json&results=1&artist=" . urlencode($artistInfo['artist_name']) . "&title=" . urlencode($track) . "&bucket=id:7digital-US&bucket=audio_summary&bucket=tracks", false, $context); $returnData = json_decode($jsonDump); if (!strlen($returnData->response->songs[0]->tracks[0]->preview_url)) { return false; } else { echo "<audio controls><source src=\"" . $returnData->response->songs[0]->tracks[0]->preview_url . "\" type=\"audio/ogg\"></audio>"; return true; } }
function getPreviewEcho($artist, $track, $ApiKey, $flag) { // Grabs the data dump from echonest // $jsonDump = uwe_file_get_contents("http://developer.echonest.com/api/v4/song/search?api_key=" . $ApiKey . "&format=json&results=1&artist=" . urlencode($artist) . "&title=" . urlencode($track) . "&bucket=id:7digital-US&bucket=audio_summary&bucket=tracks"); $returnData = json_decode($jsonDump); // Checks the validity of the responce, returns boolean // if (!strlen($returnData->response->songs[0]->tracks[0]->preview_url)) { return false; } else { return $returnData->response->songs[0]->tracks[0]->preview_url; } }
<head> <title>SoundBox widget</title> <link rel="stylesheet" type="text/css" href="resources/stylesheets/widget.css"> <script src="resources/js/comms.js"></script> <script src="resources/js/script.js"></script> </head> <body> <?php include 'constants.php'; include 'functions.php'; include 'uweproxy.php'; // Grabs track information for the artist // $results = json_decode(uwe_file_get_contents("http://developer.echonest.com/api/v4/artist/songs?api_key=" . $ECHONEST_API_KEY . "&name=" . urlencode($_POST['artist']) . "&format=json&start=0&results=" . $MAX_LIST)); echo '<div class="artistlist">'; $i = 0; echo '<div class="title text">Tracks</div><hr />'; // Loops all tracks and checks if the track has a preview avaliable // foreach ($results->response->songs as $child) { if (($url = getPreviewEcho($_POST['artist'], $child->title, $ECHONEST_API_KEY, false)) != false) { echo "<div class=\"text\"><a href=\"song.php?url=" . $url . "&title=" . $child->title . "\">" . $child->title . "</a></div>"; echo "<hr />"; $i++; } } if (!$i) { echo "No tracks available"; } echo '</div>';
include 'uweproxy.php'; ?> <html> <head> <title>SoundBox widget</title> <link rel="stylesheet" type="text/css" href="resources/stylesheets/widget.css"> <script src="resources/js/comms.js"></script> <script src="resources/js/script.js"></script> </head> <body> <?php // Grabs data for the similar artists depending on the users input // $return = uwe_file_get_contents("http://developer.echonest.com/api/v4/artist/similar?api_key=" . $ECHONEST_API_KEY . "&name=" . urlencode($_POST['artist']) . "&format=json&results=" . $MAX_LIST . "&start=0"); $results = json_decode($return); echo '<div class="artistlist">'; $i = 1; echo '<div class="title text">Similar artists</div><hr />'; // Loops all similar artists and displays in list // foreach ($results->response->artists as $child) { // Link links to a javascript to get the tracks // echo "<div class=\"text\"><a href=\"javascript: getTracks('" . $child->name . "');\">" . $child->name . "</a></div>"; echo '<hr />'; $i++; } ?> <div class="reset"><a href="index.php"><img src="resources/images/reset.png" class="image" /></a></div>
exit; } if (!albumExist($dbHandle, $artistId, addslashes($albumInfo['name']))) { fprintf($fp, "Unable to retrieve album from database\n"); fclose($fp); echo "Failed getting album info"; exit; } if (!($albumId = getAlbumId($dbHandle, $artistId, addslashes($albumInfo['name'])))) { fprintf($fp, "Unable to getting album id\n"); fclose($fp); echo "Failed getting album id"; exit; } // Track // $dataDump = uwe_file_get_contents("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=" . $LASTFM_API_KEY . "&artist=" . urlencode($artist->name) . "&album=" . urlencode($albumInfo['name']) . "&format=json"); $trackList = json_decode($dataDump)->album; $trackLength = getTrackLength($trackList); $imageLength = getImageListLength($trackList->image); insertImageUrl($dbHandle, $trackList->image, $imageLength, 0, $albumId, $ALBUM_ARTWORK_FLAG, array(0 => $ARTIST_ARTWORK_FLAG, 1 => $ALBUM_ARTWORK_FLAG), $MAX_IMAGE_COUNT); saveBio($albumId . "-album_bio.txt", $trackList->wiki->content, $fp, $DATABASE_SCRIPT_DIR, $DS_ALBUM_REVIEW_DIR, $DS_LOGS_DIR); $sql[0] = "UPDATE album_list SET `review_file`='" . $albumId . "-album_bio.txt' WHERE artist_id='" . $artistId . "' AND `album_title`='" . addslashes($albumInfo['name']) . "'"; $sql[1] = "SELECT * FROM album_list WHERE artist_id='" . $artistId . "' AND `album_title`='" . addslashes($albumInfo['name']) . "'"; if (!updateQuery($dbHandle, $sql)) { fprintf($fp, "Unable to update released information\n"); fclose($fp); echo "Failed <a href=\"javascript:window.open('" . $DATABASE_SCRIPT_DIR . $DS_LOGS_DIR . $logFile . "');\">view log</a> or <a href=\"javascript:resetForm();\">add another</a>"; exit; } for ($l = 0; $l < $trackLength; $l++) { $trackAddedTime = mt_rand($albumAddedTime, time(null));
//"http://stackoverflow.com/questions/10114926/rss-and-php-merging" //SET XML HEADER header('Content-type: text/xml'); //CONSTRUCT RSS FEED HEADERS $output = '<rss version="2.0">'; $output .= '<channel>'; $output .= '<title>HouseMD</title>'; $output .= '<description>RSS feed for most recent ' . $rssType . "'s</description>"; $output .= '<link>http://cems.uwe.ac.uk/~dj2-foley</link>'; $output .= '<copyright>Daniel Foley, Daniel Hamilton, Stuart Gray</copyright>'; //file_get_contents('database_script/album_review/' . $array[$startPoint]['album_review']) //This is the main dynamic bit, temporary data for now for ($i = 0; $i < $size; $i++) { $description = "Track"; if ($rssType == "album") { $description = uwe_file_get_contents($DATABASE_SCRIPT_DIR . $DS_ALBUM_REVIEW_DIR . $array[$i]['review_file']); } //BODY OF RSS FEED $output .= '<item>'; $output .= "<title>" . checkString($array[$i][$rssType . $fieldName]) . "</title>"; $output .= '<description>' . $description . '</description>'; $output .= '<link>http://cems.uwe.ac.uk/~dj2-foley/tracklist.php?album=' . urlencode($array[$i][$rssType . $fieldName]) . '</link>'; $output .= '</item> '; } //CLOSE RSS FEED $output .= '</channel>'; $output .= '</rss>'; //SEND COMPLETE RSS FEED TO BROWSER echo $output; // Function for removing illegal characters // function checkString($inputString)