コード例 #1
0
 /**
  * get the next song in the playlist
  */
 private function nextSong()
 {
     $curl = new Curl();
     $songArray = $curl->getArray("http://8tracks.com/sets/" . $this->playToken . "/next?mix_id=" . $this->mixId . "&api_version=2&format=jsonh");
     $status = $songArray["status"];
     if (!preg_match('/(200)/', $status)) {
         if (preg_match('/(403)/', $status)) {
             $this->output->error("8tracks made a boo boo. (" . $status . ")", 403);
         } else {
             $this->output->error("8tracks made a boo boo. (" . $status . ")");
         }
     }
     if (isset($songArray["set"]["track"]["id"])) {
         $songId = $songArray["set"]["track"]["id"];
         $title = $songArray["set"]["track"]["name"];
         $artist = $songArray["set"]["track"]["performer"];
         $album = $songArray["set"]["track"]["release_name"];
         $duration = $songArray["set"]["track"]["play_duration"];
         $songUrl = $songArray["set"]["track"]["url"];
         $song = $this->db->select("SELECT mixId FROM 8tracks_playlists_songs WHERE mixId=? AND songId=? LIMIT 1", array($this->mixId, $songId), array("%d", "%d"));
         if (empty($song)) {
             $this->db->insert("8tracks_playlists_songs", array("mixId" => $this->mixId, "songId" => $songId, "trackNumber" => $this->trackNumber), array("%d", "%d", "%d"));
             $song = $this->db->select("SELECT songId FROM 8tracks_songs WHERE songId=? LIMIT 1", array($songId), array("%d"));
             if (empty($song)) {
                 $this->db->insert("8tracks_songs", array("songId" => $songId, "title" => $title, "artist" => $artist, "album" => $album, "duration" => $duration, "songUrl" => $songUrl), array("%d", "%s", "%s", "%s", "%d", "%s"));
             }
         }
     } else {
         $this->output->error("That's all we could find.");
     }
 }
コード例 #2
0
ファイル: Songza.php プロジェクト: nightley/omgcatz
 /**
  * Get song info from URL.
  */
 private function getNextSong()
 {
     // Grab song info.
     $curl = new Curl();
     $array = $curl->getArray("http://songza.com/api/1/station/" . $this->stationId . "/next", "sessionid=" . $this->sessionId . "; visitor-prompted:1");
     // Clean up array.
     $array = array("id" => $array["song"]["id"], "title" => $array["song"]["title"], "artist" => $array["song"]["artist"]["name"], "album" => $array["song"]["album"], "genre" => $array["song"]["genre"], "url" => $array["listen_url"], "coverUrls" => array("small" => $array["song"]["cover_url"], "medium" => $array["song"]["cover_url"], "large" => $array["song"]["cover_url"]), "duration" => $array["song"]["duration"]);
     // Add to output array.
     $this->outputArray["song"] = $array;
 }