Example #1
0
function json_request_retry($url, $parameters, $method = "GET")
{
    global $conf_json_max_retries;
    $result = json_request($url, $parameters, $method);
    if ($result !== FALSE) {
        return $result;
    }
    $try = 1;
    do {
        print "... try {$try} ...\n";
        $result = json_request($url, $parameters, $method);
        $try++;
    } while ($result === FALSE && $try < $conf_json_max_retries);
    if ($result === FALSE) {
        return -1;
    }
    return $result;
}
function sound_cloud_attachment($tag_attr)
{
    $trackId = get_sound_cloud_track_id($tag_attr['src']);
    $playlistId = get_sound_cloud_playlist_id($tag_attr['src']);
    $server = "shoutem";
    if ($trackId) {
        $tag_attr['provider_id'] = $trackId;
        $tag_attr['src'] = "";
        $sc_api_url = 'http://api.' . $server . '.com/api/scstream?method=track/get&id=' . $trackId;
        $response = json_request($sc_api_url);
        if ($response) {
            $tag_attr['duration'] = $response->duration;
            $tag_attr['src'] = $response->stream_url;
            if (property_exists($response, "title")) {
                $tag_attr['title'] = $response->title;
            }
        }
        return $tag_attr;
    } else {
        if ($playlistId) {
            $sc_api_url = 'http://api.' . $server . '.com/api/scstream?method=playlist/get/first&id=' . $playlistId;
            $response = json_request($sc_api_url);
            if ($response) {
                $tag_attr['provider_id'] = $response->id;
                $tag_attr['duration'] = $response->duration;
                $tag_attr['src'] = $response->stream_url;
                if (property_exists($response, "title")) {
                    $tag_attr['title'] = $response->title;
                }
                return $tag_attr;
            }
        }
    }
    return false;
}