public function uploadToSoundCloud() { global $CC_CONFIG; $file = $this->_file; if (is_null($file)) { return "File does not exist"; } if (Application_Model_Preference::GetUploadToSoundcloudOption()) { for ($i = 0; $i < $CC_CONFIG['soundcloud-connection-retries']; $i++) { $description = $file->getDbTrackTitle(); $tag = array(); $genre = $file->getDbGenre(); $release = $file->getDbYear(); try { $soundcloud = new Application_Model_Soundcloud(); $soundcloud_res = $soundcloud->uploadTrack($this->getFilePath(), $this->getName(), $description, $tag, $release, $genre); $this->setSoundCloudFileId($soundcloud_res['id']); $this->setSoundCloudLinkToFile($soundcloud_res['permalink_url']); $this->setSoundCloudUploadTime(new DateTime("now"), new DateTimeZone("UTC")); break; } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { $code = $e->getHttpCode(); $msg = $e->getHttpBody(); // TODO : Do not parse JSON by hand $temp = explode('"error":', $msg); $msg = trim($temp[1], '"}'); $this->setSoundCloudErrorCode($code); $this->setSoundCloudErrorMsg($msg); // setting sc id to -3 which indicates error $this->setSoundCloudFileId(SOUNDCLOUD_ERROR); if (!in_array($code, array(0, 100))) { break; } } sleep($CC_CONFIG['soundcloud-connection-wait']); } } }