aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2013-01-07 17:54:52 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2013-01-07 17:54:52 +0100
commitbaf404774723ba12c715850a075c12a9713ca8a4 (patch)
tree722974ddcb57c88c806a007d11b609506f4e5add
parentBasic ajax auth helper. (diff)
downloadoldgen-zmusic-Xor_Experiments.tar.xz
oldgen-zmusic-Xor_Experiments.zip
Add local tag mode to updater.Xor_Experiments
-rw-r--r--updatedatabase.php66
1 files changed, 46 insertions, 20 deletions
diff --git a/updatedatabase.php b/updatedatabase.php
index 87134df..f21f9d4 100644
--- a/updatedatabase.php
+++ b/updatedatabase.php
@@ -26,12 +26,16 @@ setupDatabase();
setupLogDatabase();
deleteBadEntries();
scanDirectory(MUSIC_DIRECTORY);
-echo $failCount." songs failed<br>".$removeCount." songs removed<br>".$updateCount." songs updated<br>".$addCount." songs added<br>".$excludeCount." songs excluded";
+echo $failCount." songs failed\n".$removeCount." songs removed\n".$updateCount." songs updated\n".$addCount." songs added\n".$excludeCount." songs excluded";
function isExcluded($file)
{
global $excludeList;
global $excludeCount;
+ if(substr_compare($file, ".tags", -strlen(".tags"), strlen("tags")) === 0)
+ {
+ return true;
+ }
if(!is_array($excludeList) || count($excludeList) == 0)
{
return false;
@@ -46,7 +50,7 @@ function isExcluded($file)
}
if(!strncmp($excludedPath, $file, $len))
{
- echo "Excluded ".$file."<br>";
+ echo "Excluded ".$file."\n";
$excludeCount++;
return true;
}
@@ -62,7 +66,7 @@ function deleteBadEntries()
{
if(!file_exists(filePath($row["sha1"])) || isExcluded(filePath($row["sha1"])))
{
- echo "Removed ".$row["sha1"]."<br>";
+ echo "Removed ".$row["sha1"]."\n";
mysql_query("DELETE FROM musictags WHERE sha1 = ".nullString($row["sha1"]));
$removeCount++;
}
@@ -117,23 +121,36 @@ function processFile($file)
}
mysql_free_result($result);
}
+ if ($_GET["localtags"] != "true")
+ {
+ $decoded = tempDecoded($file);
- $decoded = tempDecoded($file);
-
- $format = getFormat($decoded);
- if(!$format)
+ $format = getFormat($decoded);
+ if(!$format)
+ {
+ echo "Cannot read ".$file."\n";
+ $failCount++;
+ return;
+ }
+ rename($decoded, "$decoded.$format");
+ $decoded = "$decoded.$format";
+ $tags = getTags($decoded);
+ $tags["format"] = $format;
+ @unlink($decoded);
+ }
+ else
{
- echo "Cannot read ".$file."<br>";
- $failCount++;
- return;
+ $tags = getTags($file);
+ if ($tags === false)
+ {
+ echo "Cannot find local tags for ".$file."\n";
+ $failCount++;
+ return;
+ }
}
- rename($decoded, "$decoded.$format");
- $decoded = "$decoded.$format";
- $tags = getTags($decoded);
- @unlink($decoded);
$lastModified = nullInt($lastModified);
- $format = nullString($format);
+ $format = nullString($tags["format"]);
$artist = nullString($tags["artist"]);
$album = nullString($tags["album"]);
if (strlen($tags["title"]) == 0)
@@ -181,7 +198,7 @@ function processFile($file)
length=${length}
WHERE sha1=${sha1};"
);
- echo "Updated tags for ".$file."<br>";
+ echo "Updated tags for ".$file."\n";
$updateCount++;
}
else
@@ -195,15 +212,23 @@ function processFile($file)
${genre}, ${bpm}, ${composer}, ${compilation}, ${bitrate}, ${sampleRate}, ${channels}, ${length}
);"
);
- echo "Added ".$file."<br>";
+ echo "Added ".$file."\n";
$addCount++;
}
}
-
function getTags($file)
{
- exec("./tagreader ".escapeshellarg($file), $outputLines);
+ if ($_GET["localtags"] == "true")
+ {
+ $outputLines = explode("\n", @file_get_contents($file.".tags"));
+ if (count($outputLines) == 1)
+ return false;
+ }
+ else
+ {
+ exec("./tagreader ".escapeshellarg($file), $outputLines);
+ }
$tags = array();
foreach($outputLines as $line)
{
@@ -265,6 +290,7 @@ function setupDatabase()
PRIMARY KEY ( `sha1` )
) ENGINE = MYISAM CHARACTER SET utf8 COMMENT = 'music tag table';"
);
- echo "Connected to database<br>";
+ echo "Connected to database\n";
}
+echo "\n";
?>