Switch to composer getID3 lib. Add SIMULATE arg/mode. Add vim modeline.
This commit is contained in:
parent
d3d8e6c421
commit
7ad5c67a77
|
@ -1,8 +1,14 @@
|
|||
<?php
|
||||
|
||||
require_once 'getid3/getid3.php';
|
||||
//require_once 'getid3/getid3.php';
|
||||
require_once '../vendor/autoload.php';
|
||||
|
||||
$ini = parse_ini_file("/etc/homeaudio.ini");
|
||||
if ( isset($argv[1]) && ($argv[1] == "simulate") ) {
|
||||
define("SIMULATE", true);
|
||||
} else {
|
||||
define("SIMULATE", false);
|
||||
}
|
||||
|
||||
define("MP3ROOTDIR", $ini['MP3DIR']);
|
||||
define("ARTDIR", $ini['ARTDIR']);
|
||||
|
@ -40,7 +46,11 @@ function pruneDB() {
|
|||
if ( !file_exists(MP3ROOTDIR . $row['path'] . $row['song']) ) {
|
||||
$fieldsdel = array();
|
||||
$fieldsdel[':id'] = $row['id'];
|
||||
$sthdel->execute($fieldsdel);
|
||||
if ( SIMULATE ) {
|
||||
echo "Would have removed: {$row['song']}\n";
|
||||
} else {
|
||||
$sthdel->execute($fieldsdel);
|
||||
}
|
||||
$prunecount++;
|
||||
}
|
||||
}
|
||||
|
@ -59,13 +69,21 @@ function addNewSongs($path = "") {
|
|||
if ( substr($entry, -3) != "mp3" ) continue;
|
||||
$song = $path . $entry;
|
||||
$fields = array();
|
||||
$fields[':path'] = $path;
|
||||
$fields[':song'] = $entry;
|
||||
$sth_exists->execute($fields);
|
||||
$fields[':path'] = mb_convert_encoding($path, "UTF-8");
|
||||
$fields[':song'] = mb_convert_encoding($entry, "UTF-8");
|
||||
try {
|
||||
$sth_exists->execute($fields);
|
||||
} catch ( Exception $e ) {
|
||||
echo "Could not query database for song: {$path}/{$entry}\n";
|
||||
}
|
||||
if ( $sth_exists->fetchColumn() == 0 ) {
|
||||
$newcount++;
|
||||
if ( ($newcount % 1000) == 0 ) echo ".";
|
||||
$sth_addnew->execute($fields);
|
||||
if ( SIMULATE ) {
|
||||
echo "Would have added: {$fields[':path']}/{$fields[':song']}\n";
|
||||
} else {
|
||||
$sth_addnew->execute($fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,12 +136,14 @@ function parseSongs() {
|
|||
$fields[':artfile'] = $artmd5 . "." . $extbymimetypes[$mimetype];
|
||||
}
|
||||
}
|
||||
if ( ($fields[':artfile'] != "") && !file_exists(ARTDIR . $fields[':artfile']) ) {
|
||||
file_put_contents(ARTDIR . $fields[':artfile'], $info['comments']['picture'][0]['data']);
|
||||
if ( !SIMULATE ) {
|
||||
if ( ($fields[':artfile'] != "") && !file_exists(ARTDIR . $fields[':artfile']) ) {
|
||||
file_put_contents(ARTDIR . $fields[':artfile'], $info['comments']['picture'][0]['data']);
|
||||
}
|
||||
$sth_info->execute($fields);
|
||||
}
|
||||
$parsecount++;
|
||||
if ( ($parsecount % 1000) == 0 ) echo ".";
|
||||
$sth_info->execute($fields);
|
||||
}
|
||||
return $parsecount;
|
||||
}
|
||||
|
@ -157,7 +177,7 @@ addNewSongs();
|
|||
echo " ", $newcount, " songs added.\n";
|
||||
|
||||
echo "Parsing ID3 tags...";
|
||||
$parsecount = parseSongs();
|
||||
echo " ", $parsecount, " tags parsed.\n";
|
||||
//$parsecount = parseSongs();
|
||||
//echo " ", $parsecount, " tags parsed.\n";
|
||||
|
||||
?>
|
||||
// vim: set et ts=3 sw=3 ai mouse-=a:
|
||||
|
|
Loading…
Reference in New Issue
Block a user