Sinusbot_song_renamer/umwandler.php
2021-03-25 21:43:23 +01:00

25 lines
670 B
PHP

<?php
session_start();
$db = new SQLite3("db.db");
$result = $db->query("SELECT trackinfo FROM storage_files");
while($datalist = $result->fetchArray(SQLITE3_ASSOC)) {
$content = json_decode($datalist['trackinfo'], true);
$path = $content['path'];
if(file_exists("storage/".$path)) {
$filelocation = "storage/".$path;
$name = $content['title'];
nameFile($filelocation, $name);
}
echo "<h1>All files in /storage renamed and fixed up. \n <p>Output is in /output/songnames/";
$db->close();
}
function nameFile($file, $name) {
$fname = preg_replace('/[^A-Za-z0-9- \-]/', '', $name);
rename($file, "output/".utf8_decode($fname).".mp3");
}
?>