Ejemplo n.º 1
0
function nextSong(&$playToken, $mixId, $trackNumber, $con)
{
    $authToken = "3557239;13ede75e207a2348e6482b3bb4da509096e3d3e9";
    $retries = 0;
    do {
        $ch = curl_init("http://8tracks.com/sets/" . $playToken . "/next?mix_id=" . $mixId . "&format=jsonh&api_version=2");
        curl_setopt($ch, CURLOPT_COOKIE, "auth_token=" . $authToken);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $jsonSongArray = json_decode(curl_exec($ch), true);
        curl_close($ch);
        $status = $jsonSongArray['status'];
        $retries++;
        if ($retries > 1) {
            if (preg_match('/(403)/', $status)) {
                bail_out(403, "8tracks denied our request.");
            } else {
                bail_out(1, "8tracks denied our request. (Error: " . $status . ")");
            }
        }
    } while (!preg_match('/(200)/', $status));
    if (isset($jsonSongArray['set']['track']['id']) && $jsonSongArray['set']['track']['id'] > 0) {
        $songId = $jsonSongArray['set']['track']['id'];
        $title = addslashes($jsonSongArray['set']['track']['name']);
        $artist = addslashes($jsonSongArray['set']['track']['performer']);
        $album = addslashes($jsonSongArray['set']['track']['release_name']);
        $duration = $jsonSongArray['set']['track']['play_duration'];
        $songUrl = $jsonSongArray['set']['track']['url'];
    } else {
        bail_out(2, "That's all we could find.");
    }
    // if 8tracks_songs table doesn't exist, create it and 8tracks_playlists_songs
    $result = mysqli_query($con, "SHOW TABLES LIKE '8tracks_songs'");
    if (mysqli_num_rows($result) == 0) {
        $query = "CREATE TABLE `8tracks_songs` (\n      `songId` tinyblob NOT NULL,\n      `title` tinyblob NOT NULL,\n      `artist` tinyblob,\n      `album` tinyblob,\n      `duration` int(11) NOT NULL,\n      `songUrl` varchar(2083) NOT NULL DEFAULT '',\n      PRIMARY KEY (`songId`(255))\n      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        mysqli_query($con, $query);
        $query = "CREATE TABLE `8tracks_playlists_songs` (\n      `mixId` tinyblob NOT NULL,\n      `songId` int(11) NOT NULL,\n      `trackNumber` tinyblob NOT NULL\n      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        mysqli_query($con, $query);
    }
    // if songId isn't in the table, add a new row
    $query = "SELECT songId FROM 8tracks_songs\n    WHERE songId='{$songId}' \n    LIMIT 1";
    $result = mysqli_query($con, $query);
    if (mysqli_num_rows($result) == 0) {
        $query = "INSERT INTO 8tracks_songs\n      (songId,title,artist,album,duration,songUrl)\n      VALUES ('{$songId}','{$title}','{$artist}','{$album}','{$duration}','{$songUrl}')";
        mysqli_query($con, $query);
        // or die(mysqli_error($con))
    }
    $query = "INSERT INTO 8tracks_playlists_songs\n    (mixId,songId,trackNumber)\n    VALUES ('{$mixId}','{$songId}','{$trackNumber}')";
    mysqli_query($con, $query);
}
Ejemplo n.º 2
0
<?php

/* this script downloads a file in the browser */
include '../include/functions.php';
// get directory name
$pathParts = pathinfo($_GET['p']);
$dirName = $pathParts['dirname'];
// prevent arbitrary files from being downloaded
if (!preg_match('|^archives/[^/\\.]+/[^/\\.]+$|', $dirName) && $dirName != "songs") {
    bail_out(403, "Not acceptable.");
}
$fileSize = filesize($_GET['p']);
header('Content-Length: ' . $fileSize);
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . $_GET['t'] . '"');
readfile($_GET['p']);
Ejemplo n.º 3
0
/**
 * Runs given shell command, exists with error-code after echoing the output of the failed command (if not already running verbose)
 *
 * @param string $cmd
 * @param array &$output=null $output of command
 * @param int|array|true $no_bailout=null exit code(s) to NOT bail out, or true to never bail out
 * @return int exit code of $cmd
 */
function run_cmd($cmd, array &$output = null, $no_bailout = null)
{
    global $verbose;
    if ($verbose) {
        echo $cmd . "\n";
        system($cmd, $ret);
    } else {
        $output[] = $cmd;
        exec($cmd, $output, $ret);
    }
    if ($ret && $no_bailout !== true && !in_array($ret, (array) $no_bailout)) {
        bail_out($ret, $verbose ? null : $output);
    }
    return $ret;
}