Exemplo n.º 1
0
function loadLogos($dir)
{
    if (!is_dir($dir)) {
        echo "Invalid directory";
    } else {
        global $nbInsert;
        global $_PATH;
        if ($handle = opendir($dir)) {
            while (($file = readdir($handle)) !== false) {
                ///---Extraction
                $parts = explode('.', $file);
                $ext = array_pop($parts);
                ///---Valid formats
                if (!($ext == 'gif' || $ext == 'jpg' || $ext == 'png')) {
                    continue;
                }
                ///---Name repack
                $name = join(".", $parts);
                $name = str_replace('__', '.', $name);
                $name = str_replace('_', '%', $name);
                ///---Extra Validations
                //Check for special caracters not encoded
                if (strpos($name, '_') !== false || strpos($name, ' ') !== false) {
                    echo "<b>" . $name . " sould be rename to " . str_replace(array('_', ' '), array('+', '+'), $name) . ".</b><br/>";
                    continue;
                } else {
                    if (strpos($name, '%') === false) {
                        $nameCheck = urlencode(str_replace(array('+'), array(''), $name));
                        //Char excludes
                        //Some caracter are not support yet
                        if (strpos($nameCheck, '%') !== false) {
                            echo "<b>" . $name . " is not properly parse.</b><br/>";
                            continue;
                        }
                    }
                }
                $prev = $name;
                ///---Insert in db
                if (artistExist($name)) {
                    continue;
                }
                echo $name . " - ";
                $newDate = filemtime(Config::FOLDER_LOGOS . $file);
                //Date of modification (new file)
                $newArtist = new Artist($name, $file, "", -1, $newDate);
                Artists::addArtist($newArtist);
                $nbInsert++;
            }
            closedir($handle);
        }
    }
}
Exemplo n.º 2
0
$fp = fopen($DS_LOGS_DIR . $logFile, "w+");
$warning_count = 0;
//////////////////////////////////////////////////////////////
// LAST FM API //
$var = '#text';
// Artist //
// Grabs artist information //
$dump = uwe_file_get_contents("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" . urlencode($artist) . "&api_key=" . $LASTFM_API_KEY . "&format=json");
if ($dump == NULL) {
    fprintf($fp, "No internet connection\n");
    fclose($fp);
    echo "Failed connection";
    exit;
}
$artist = json_decode($dump)->artist;
$exist = artistExist($dbHandle, addslashes($artist->name));
if ($exist) {
    fprintf($fp, "DUP artist, skipping artist\n");
    $warning_count++;
} else {
    $sql[0] = "INSERT INTO artist_list (artist_name) VALUES ('" . addslashes($artist->name) . "')";
    $sql[1] = "SELECT * FROM artist_list WHERE `artist_name`='" . addslashes($artist->name) . "'";
    if (!insertQuery($dbHandle, $sql)) {
        fprintf($fp, "Unable to add artist to database\n");
        fclose($fp);
        echo "Failed adding artist";
        exit;
    }
    if (!($artistId = getArtistId($dbHandle, addslashes($artist->name)))) {
        fprintf($fp, "Unable to retrieve artist id\n");
        fclose($fp);