//
// available at https://github.com/JamesHeinrich/getID3 //
// or https://www.getid3.org //
// or http://getid3.sourceforge.net //
// //
// /demo/demo.mysqli.php - part of getID3() //
// Sample script for recursively scanning directories and //
// storing the results in a database //
// see readme.txt for more details //
// updated to mysqli by sarang ///
/////////////////////////////////////////////////////////////////
die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
// OPTIONS:
$getid3_demo_mysqli_encoding_getid3 = 'UTF-8';
$getid3_demo_mysqli_encoding_mysqli = 'utf8'; // https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html
$getid3_demo_mysqli_md5_data = false; // All data hashes are by far the slowest part of scanning, recommended to leave disabled
$getid3_demo_mysqli_md5_file = false;
define('GETID3_DB_HOST', 'localhost');
define('GETID3_DB_USER', 'root');
define('GETID3_DB_PASS', 'password');
define('GETID3_DB_DB', 'getid3');
define('GETID3_DB_TABLE', 'files');
// CREATE DATABASE `getid3`;
ob_start();
if ($con = mysqli_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)){
// great
} else {
$errormessage = ob_get_contents();
ob_end_clean();
die('Could not connect to MySQL host:
'.mysqli_error($con).'
');
}
if (mysqli_select_db($con, GETID3_DB_DB)){
// great
} else {
$errormessage = ob_get_contents();
ob_end_clean();
die('Could not select database: '.mysqli_error($con).'
');
}
ob_end_clean();
if (!mysqli_set_charset($con, $getid3_demo_mysqli_encoding_mysqli)) {
die('Could not mysqli_set_charset('.htmlentities($getid3_demo_mysqli_encoding_mysqli).')');
}
$getid3PHP_filename = realpath('../getid3/getid3.php');
if (!file_exists($getid3PHP_filename) || !include_once($getid3PHP_filename)) {
die('Cannot open '.$getid3PHP_filename);
}
// Initialize getID3 engine
$getID3 = new getID3;
$getID3->setOption(array(
'option_md5_data' => $getid3_demo_mysqli_md5_data,
'encoding' => $getid3_demo_mysqli_encoding_getid3,
));
function RemoveAccents($string) {
// Revised version by markstewardØhotmail*com
return strtr(strtr($string, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', '' => 'OE', '' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
}
function BitrateColor($bitrate, $BitrateMaxScale=768) {
// $BitrateMaxScale is bitrate of maximum-quality color (bright green)
// below this is gradient, above is solid green
$bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256
$bitrate = round(min(max($bitrate, 1), 256));
$bitrate--; // scale from 1-256kbps to 0-255kbps
$Rcomponent = max(255 - ($bitrate * 2), 0);
$Gcomponent = max(($bitrate * 2) - 255, 0);
if ($bitrate > 127) {
$Bcomponent = max((255 - $bitrate) * 2, 0);
} else {
$Bcomponent = max($bitrate * 2, 0);
}
return str_pad(dechex($Rcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Gcomponent), 2, '0', STR_PAD_LEFT).str_pad(dechex($Bcomponent), 2, '0', STR_PAD_LEFT);
}
function BitrateText($bitrate, $decimals=0) {
return ''.number_format($bitrate, $decimals).' kbps';
}
function fileextension($filename, $numextensions=1) {
if (strstr($filename, '.')) {
$reversedfilename = strrev($filename);
$offset = 0;
for ($i = 0; $i < $numextensions; $i++) {
$offset = strpos($reversedfilename, '.', $offset + 1);
if ($offset === false) {
return '';
}
}
return strrev(substr($reversedfilename, 0, $offset));
}
return '';
}
function RenameFileFromTo($from, $to, &$results) {
$success = true;
if ($from === $to) {
$results = 'Source and Destination filenames identical
FAILED to rename';
} elseif (!file_exists($from)) {
$results = 'Source file does not exist
FAILED to rename';
} elseif (file_exists($to) && (strtolower($from) !== strtolower($to))) {
$results = 'Destination file already exists
FAILED to rename';
} else {
ob_start();
if (rename($from, $to)) {
ob_end_clean();
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $from).'")';
mysqli_query_safe($con, $SQLquery);
$results = 'Successfully renamed';
} else {
$errormessage = ob_get_contents();
ob_end_clean();
$results = '
FAILED to rename';
$success = false;
}
}
$results .= ' from:
'.$from.'
to:
'.$to.'
';
return $success;
}
if (!empty($_REQUEST['renamefilefrom']) && !empty($_REQUEST['renamefileto'])) {
$results = '';
RenameFileFromTo($_REQUEST['renamefilefrom'], $_REQUEST['renamefileto'], $results);
echo $results;
exit;
} elseif (!empty($_REQUEST['m3ufilename'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
echo WindowsShareSlashTranslate($_REQUEST['m3ufilename'])."\n";
exit;
} elseif (!isset($_REQUEST['m3u']) && !isset($_REQUEST['m3uartist']) && !isset($_REQUEST['m3utitle'])) {
echo '';
echo 'getID3() demo - /demo/mysql.php';
}
function WindowsShareSlashTranslate($filename) {
if (substr($filename, 0, 2) == '//') {
return str_replace('/', '\\', $filename);
}
return $filename;
}
function mysqli_query_safe($con, $SQLquery) {
static $TimeSpentQuerying = 0;
if ($SQLquery === null) {
return $TimeSpentQuerying;
}
$starttime = microtime(true);
$result = mysqli_query($con, $SQLquery);
$TimeSpentQuerying += (microtime(true) - $starttime);
if (mysqli_error($con)) {
die('SQL error:
'.htmlentities(mysqli_error($con)).'
'.htmlentities($SQLquery, ENT_SUBSTITUTE).'
');
}
return $result;
}
function mysqli_table_exists($con, $tablename) {
return (bool) mysqli_query($con, 'DESCRIBE '.$tablename);
}
function AcceptableExtensions($fileformat, $audio_dataformat='', $video_dataformat='') {
static $AcceptableExtensionsAudio = array();
if (empty($AcceptableExtensionsAudio)) {
$AcceptableExtensionsAudio['mp3']['mp3'] = array('mp3');
$AcceptableExtensionsAudio['mp2']['mp2'] = array('mp2');
$AcceptableExtensionsAudio['mp1']['mp1'] = array('mp1');
$AcceptableExtensionsAudio['asf']['asf'] = array('asf');
$AcceptableExtensionsAudio['asf']['wma'] = array('wma');
$AcceptableExtensionsAudio['riff']['mp3'] = array('wav');
$AcceptableExtensionsAudio['riff']['wav'] = array('wav');
}
static $AcceptableExtensionsVideo = array();
if (empty($AcceptableExtensionsVideo)) {
$AcceptableExtensionsVideo['mp3']['mp3'] = array('mp3');
$AcceptableExtensionsVideo['mp2']['mp2'] = array('mp2');
$AcceptableExtensionsVideo['mp1']['mp1'] = array('mp1');
$AcceptableExtensionsVideo['asf']['asf'] = array('asf');
$AcceptableExtensionsVideo['asf']['wmv'] = array('wmv');
$AcceptableExtensionsVideo['gif']['gif'] = array('gif');
$AcceptableExtensionsVideo['jpg']['jpg'] = array('jpg');
$AcceptableExtensionsVideo['png']['png'] = array('png');
$AcceptableExtensionsVideo['bmp']['bmp'] = array('bmp');
}
if (!empty($video_dataformat)) {
return (isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : array());
} else {
return (isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : array());
}
}
if (!empty($_REQUEST['scan'])) {
if (mysqli_table_exists($con, GETID3_DB_TABLE)) {
$SQLquery = 'DROP TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
mysqli_query_safe($con, $SQLquery);
}
}
if (!mysqli_table_exists($con, GETID3_DB_TABLE)) {
$SQLquery = "CREATE TABLE `".mysqli_real_escape_string($con, GETID3_DB_TABLE)."` (";
$SQLquery .= "`ID` int(11) unsigned NOT NULL auto_increment";
$SQLquery .= ", `filename` text NOT NULL";
$SQLquery .= ", `last_modified` int(11) NOT NULL default '0'";
$SQLquery .= ", `md5_file` varchar(32) NOT NULL default ''";
$SQLquery .= ", `md5_data` varchar(32) NOT NULL default ''";
$SQLquery .= ", `md5_data_source` varchar(32) NOT NULL default ''";
$SQLquery .= ", `filesize` int(10) unsigned NOT NULL default '0'";
$SQLquery .= ", `fileformat` varchar(255) NOT NULL default ''";
$SQLquery .= ", `audio_dataformat` varchar(255) NOT NULL default ''";
$SQLquery .= ", `video_dataformat` varchar(255) NOT NULL default ''";
$SQLquery .= ", `audio_bitrate` float NOT NULL default '0'";
$SQLquery .= ", `video_bitrate` float NOT NULL default '0'";
$SQLquery .= ", `playtime_seconds` varchar(255) NOT NULL default ''";
$SQLquery .= ", `tags` varchar(255) NOT NULL default ''";
$SQLquery .= ", `artist` varchar(255) NOT NULL default ''";
$SQLquery .= ", `title` varchar(255) NOT NULL default ''";
$SQLquery .= ", `remix` varchar(255) NOT NULL default ''";
$SQLquery .= ", `album` varchar(255) NOT NULL default ''";
$SQLquery .= ", `genre` varchar(255) NOT NULL default ''";
$SQLquery .= ", `comment` text NOT NULL";
$SQLquery .= ", `track` varchar(7) NOT NULL default ''";
$SQLquery .= ", `comments_all` longblob NOT NULL";
$SQLquery .= ", `comments_id3v2` longblob NOT NULL";
$SQLquery .= ", `comments_ape` longblob NOT NULL";
$SQLquery .= ", `comments_lyrics3` longblob NOT NULL";
$SQLquery .= ", `comments_id3v1` blob NOT NULL";
$SQLquery .= ", `warning` longtext NOT NULL";
$SQLquery .= ", `error` longtext NOT NULL";
$SQLquery .= ", `track_volume` float NOT NULL default '0'";
$SQLquery .= ", `encoder_options` varchar(255) NOT NULL default ''";
$SQLquery .= ", `vbr_method` varchar(255) NOT NULL default ''";
$SQLquery .= ", PRIMARY KEY (`ID`)";
$SQLquery .= ")";
mysqli_query_safe($con, $SQLquery);
}
$ExistingTableFields = array();
$result = mysqli_query_safe($con, 'DESCRIBE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
while ($row = mysqli_fetch_array($result)) {
$ExistingTableFields[$row['Field']] = $row;
}
if (!isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2
echo 'adding field `encoder_options`
';
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `encoder_options` VARCHAR(255) default "" NOT NULL AFTER `error`');
mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
}
if (isset($ExistingTableFields['track']) && ($ExistingTableFields['track']['Type'] != 'varchar(7)')) { // Changed in 1.7.0b2
echo 'changing field `track` to VARCHAR(7)
';
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `track` `track` VARCHAR(7) default "" NOT NULL');
mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
}
if (!isset($ExistingTableFields['track_volume'])) { // Added in 1.7.0b5
echo 'WARNING! You should erase your database and rescan everything because the comment storing has been changed since the last version
';
echo 'adding field `track_volume`
';
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `track_volume` FLOAT NOT NULL AFTER `error`');
mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
}
if (!isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1
echo 'adding field `encoder_options`, `alternate_name`, `parody`
';
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `remix` VARCHAR(255) default "" NOT NULL AFTER `title`');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `alternate_name` VARCHAR(255) default "" NOT NULL AFTER `track`');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `parody` VARCHAR(255) default "" NOT NULL AFTER `alternate_name`');
mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
}
if (isset($ExistingTableFields['comments_all']) && ($ExistingTableFields['comments_all']['Type'] != 'longblob')) { // Changed to "longtext" in 1.9.0, changed to "longblob" in 1.9.20-202010140821
echo 'changing comments fields from text to longtext
';
// no need to change id3v1
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_all` `comments_all` LONGBLOB NOT NULL');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_id3v2` `comments_id3v2` LONGBLOB NOT NULL');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_ape` `comments_ape` LONGBLOB NOT NULL');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_lyrics3` `comments_lyrics3` LONGBLOB NOT NULL');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_id3v1` `comments_id3v1` BLOB NOT NULL');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `warning` `warning` LONGTEXT NOT NULL');
mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `error` `error` LONGTEXT NOT NULL');
}
function SynchronizeAllTags($filename, $synchronizefrom='all', $synchronizeto='A12', &$errors = array()) {
global $getID3;
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($filename);
$getID3->CopyTagsToComments($ThisFileInfo);
if ($synchronizefrom == 'all') {
$SourceArray = (!empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : array());
} elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) {
$SourceArray = (!empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : array());
} else {
die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist');
}
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $filename).'")';
mysqli_query_safe($con, $SQLquery);
$TagFormatsToWrite = array();
if ((strpos($synchronizeto, '2') !== false) && ($synchronizefrom != 'id3v2')) {
$TagFormatsToWrite[] = 'id3v2.3';
}
if ((strpos($synchronizeto, 'A') !== false) && ($synchronizefrom != 'ape')) {
$TagFormatsToWrite[] = 'ape';
}
if ((strpos($synchronizeto, 'L') !== false) && ($synchronizefrom != 'lyrics3')) {
$TagFormatsToWrite[] = 'lyrics3';
}
if ((strpos($synchronizeto, '1') !== false) && ($synchronizefrom != 'id3v1')) {
$TagFormatsToWrite[] = 'id3v1';
}
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true);
$tagwriter = new getid3_writetags;
$tagwriter->filename = $filename;
$tagwriter->tagformats = $TagFormatsToWrite;
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding = $getID3->encoding;
$tagwriter->tag_data = $SourceArray;
if ($tagwriter->WriteTags()) {
$errors = $tagwriter->errors;
return true;
}
$errors = $tagwriter->errors;
return false;
}
$IgnoreNoTagFormats = array('', 'png', 'jpg', 'gif', 'bmp', 'swf', 'pdf', 'zip', 'rar', 'mid', 'mod', 'xm', 'it', 's3m');
if (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan']) || !empty($_REQUEST['rescanerrors'])) {
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` = "")';
mysqli_query_safe($con, $SQLquery);
$FilesInDir = array();
if (!empty($_REQUEST['rescanerrors'])) {
echo 'abort
';
echo 'Re-scanning all media files already in database that had errors and/or warnings in last scan
';
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`error` <> "")';
$SQLquery .= ' OR (`warning` <> "")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
while ($row = mysqli_fetch_array($result)) {
if (!file_exists($row['filename'])) {
echo 'File missing: '.$row['filename'].'
';
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
mysqli_query_safe($con, $SQLquery);
} else {
$FilesInDir[] = $row['filename'];
}
}
} elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) {
echo 'abort
';
echo 'Scanning all media files in '.str_replace('\\', '/', realpath(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan'])).' (and subdirectories)
';
$SQLquery = 'SELECT COUNT(*) AS `num`, `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' GROUP BY `filename`';
$SQLquery .= ' HAVING (`num` > 1)';
$SQLquery .= ' ORDER BY `num` DESC';
$result = mysqli_query_safe($con, $SQLquery);
$DupesDeleted = 0;
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE `filename` LIKE "'.mysqli_real_escape_string($con, $row['filename']).'"';
mysqli_query_safe($con, $SQLquery);
$DupesDeleted++;
}
if ($DupesDeleted > 0) {
echo 'Deleted '.number_format($DupesDeleted).' duplicate filenames
';
}
if (!empty($_REQUEST['newscan'])) {
$AlreadyInDatabase = array();
set_time_limit(60);
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
while ($row = mysqli_fetch_array($result)) {
//$AlreadyInDatabase[] = strtolower($row['filename']);
$AlreadyInDatabase[] = $row['filename'];
}
}
$DirectoriesToScan = array(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan']);
$DirectoriesScanned = array();
while (count($DirectoriesToScan) > 0) {
foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) {
if ($dir = opendir($startingdir)) {
set_time_limit(30);
echo ''.str_replace('\\', '/', $startingdir).'
';
flush();
while (($file = readdir($dir)) !== false) {
if (($file != '.') && ($file != '..')) {
$RealPathName = realpath($startingdir.'/'.$file);
if (is_dir($RealPathName)) {
if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName, $DirectoriesToScan)) {
$DirectoriesToScan[] = $RealPathName;
}
} elseif (is_file($RealPathName)) {
if (!empty($_REQUEST['newscan'])) {
if (!in_array(str_replace('\\', '/', $RealPathName), $AlreadyInDatabase)) {
$FilesInDir[] = $RealPathName;
}
} elseif (!empty($_REQUEST['scan'])) {
$FilesInDir[] = $RealPathName;
}
}
}
}
closedir($dir);
} else {
echo 'Failed to open directory "'.htmlentities($startingdir).'"
';
}
$DirectoriesScanned[] = $startingdir;
unset($DirectoriesToScan[$DirectoryKey]);
}
}
echo 'List of files to scan complete (added '.number_format(count($FilesInDir)).' files to scan)
';
flush();
}
$FilesInDir = array_unique($FilesInDir);
sort($FilesInDir);
$starttime = time();
$rowcounter = 0;
$totaltoprocess = count($FilesInDir);
foreach ($FilesInDir as $filename) {
set_time_limit(300);
echo '
'.date('H:i:s').' ['.number_format(++$rowcounter).' / '.number_format($totaltoprocess).'] '.str_replace('\\', '/', $filename);
$ThisFileInfo = $getID3->analyze($filename);
$getID3->CopyTagsToComments($ThisFileInfo);
if (file_exists($filename)) {
$ThisFileInfo['file_modified_time'] = filemtime($filename);
$ThisFileInfo['md5_file'] = ($getid3_demo_mysqli_md5_file ? md5_file($filename) : '');
}
if (empty($ThisFileInfo['fileformat'])) {
echo ' (unknown file type)';
} else {
if (!empty($ThisFileInfo['error'])) {
echo ' (errors)';
} elseif (!empty($ThisFileInfo['warning'])) {
echo ' (warnings)';
} else {
echo ' (OK)';
}
$this_track_track = '';
if (!empty($ThisFileInfo['comments']['track_number'])) {
foreach ($ThisFileInfo['comments']['track_number'] as $key => $value) {
if (strlen($value) > strlen($this_track_track)) {
$this_track_track = str_pad($value, 2, '0', STR_PAD_LEFT);
}
}
if (preg_match('#^([0-9]+)/([0-9]+)$#', $this_track_track, $matches)) {
// change "1/5"->"01/05", "3/12"->"03/12", etc
$this_track_track = str_pad($matches[1], 2, '0', STR_PAD_LEFT).'/'.str_pad($matches[2], 2, '0', STR_PAD_LEFT);
}
}
$this_track_remix = '';
$this_track_title = '';
if (!empty($ThisFileInfo['comments']['title'])) {
foreach ($ThisFileInfo['comments']['title'] as $possible_title) {
if (strlen($possible_title) > strlen($this_track_title)) {
$this_track_title = $possible_title;
}
}
}
$ParenthesesPairs = array('()', '[]', '{}');
foreach ($ParenthesesPairs as $pair) {
if (preg_match_all('/(.*) '.preg_quote($pair[0]).'(([^'.preg_quote($pair).']*[\- '.preg_quote($pair[0]).'])?(cut|dub|edit|version|live|reprise|[a-z]*mix))'.preg_quote($pair[1]).'/iU', $this_track_title, $matches)) {
$this_track_title = $matches[1][0];
$this_track_remix = implode("\t", $matches[2]);
}
}
if (!empty($_REQUEST['rescanerrors'])) {
$SQLquery = 'UPDATE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` SET ';
$SQLquery .= ' `last_modified` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"';
$SQLquery .= ', `md5_file` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"';
$SQLquery .= ', `md5_data` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"';
$SQLquery .= ', `md5_data_source` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"';
$SQLquery .= ', `filesize` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"';
$SQLquery .= ', `fileformat` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"';
$SQLquery .= ', `audio_dataformat` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"';
$SQLquery .= ', `video_dataformat` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"';
$SQLquery .= ', `vbr_method` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['mpeg']['audio']['VBR_method'] ) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '').'"';
$SQLquery .= ', `audio_bitrate` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"';
$SQLquery .= ', `video_bitrate` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"';
$SQLquery .= ', `playtime_seconds` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"';
$SQLquery .= ', `track_volume` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"';
$SQLquery .= ', `comments_all` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"';
$SQLquery .= ', `comments_id3v2` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"';
$SQLquery .= ', `comments_ape` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"';
$SQLquery .= ', `comments_lyrics3` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"';
$SQLquery .= ', `comments_id3v1` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"';
$SQLquery .= ', `warning` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"';
$SQLquery .= ', `error` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"';
$SQLquery .= ', `album` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"';
$SQLquery .= ', `genre` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"';
$SQLquery .= ', `comment` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"';
$SQLquery .= ', `artist` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"';
$SQLquery .= ', `tags` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"';
$SQLquery .= ', `encoder_options` = "'. mysqli_real_escape_string($con, trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"';
$SQLquery .= ', `title` = "'. mysqli_real_escape_string($con, $this_track_title).'"';
$SQLquery .= ', `remix` = "'. mysqli_real_escape_string($con, $this_track_remix).'"';
$SQLquery .= ', `track` = "'. mysqli_real_escape_string($con, $this_track_track).'"';
$SQLquery .= ' WHERE (`filename` = "'. mysqli_real_escape_string($con, isset($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'")';
} elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) {
$SQLquery = 'INSERT INTO `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `tags`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `track_volume`, `encoder_options`, `vbr_method`) VALUES (';
$SQLquery .= '"'.mysqli_real_escape_string($con, !empty($ThisFileInfo['filenamepath'] ) ? $ThisFileInfo['filenamepath'] : '').'"'; // filename
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"'; // last_modified
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"'; // md5_file
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"'; // md5_data
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"'; // md5_data_source
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"'; // filesize
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"'; // fileformat
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; // audio_dataformat
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"'; // video_dataformat
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; // audio_bitrate
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; // video_bitrate
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; // playtime_seconds
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; // tags
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; // artist
$SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_title ).'"'; // title
$SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_remix ).'"'; // remix
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; // album
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; // genre
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; // comment
$SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_track ).'"'; // track
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"'; // comments_all
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; // comments_id3v2
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; // comments_ape
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; // comments_lyrics3
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; // comments_id3v1
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; // warning
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"'; // error
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; // track_volume
$SQLquery .= ', "'.mysqli_real_escape_string($con, trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; // encoder_options
$SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : (!empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '')).'"'; // vbr_method
$SQLquery .= ')';
}
flush();
mysqli_query_safe($con, $SQLquery);
}
}
$SQLquery = 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
mysqli_query_safe($con, $SQLquery);
echo '
Done scanning!
';
} elseif (!empty($_REQUEST['missingtrackvolume'])) {
$MissingTrackVolumeFilesScanned = 0;
$MissingTrackVolumeFilesAdjusted = 0;
$MissingTrackVolumeFilesDeleted = 0;
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`track_volume` = 0)';
$SQLquery .= ' AND (`audio_bitrate` > 0)';
$result = mysqli_query_safe($con, $SQLquery);
echo 'Scanning 0 / '.number_format(mysqli_num_rows($result)).' files for track volume information:
';
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
echo '. ';
flush();
if (file_exists($row['filename'])) {
$ThisFileInfo = $getID3->analyze($row['filename']);
if (!empty($ThisFileInfo['replay_gain']['track']['volume'])) {
$MissingTrackVolumeFilesAdjusted++;
$SQLquery = 'UPDATE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"';
$SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
mysqli_query_safe($con, $SQLquery);
}
} else {
$MissingTrackVolumeFilesDeleted++;
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
mysqli_query_safe($con, $SQLquery);
}
}
echo '
Scanned '.number_format($MissingTrackVolumeFilesScanned).' files with no track volume information.
';
echo 'Found track volume information for '.number_format($MissingTrackVolumeFilesAdjusted).' of them (could not find info for '.number_format($MissingTrackVolumeFilesScanned - $MissingTrackVolumeFilesAdjusted).' files; deleted '.number_format($MissingTrackVolumeFilesDeleted).' records of missing files)
';
} elseif (!empty($_REQUEST['deadfilescheck'])) {
$SQLquery = 'SELECT COUNT(*) AS `num`, `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' GROUP BY `filename`';
$SQLquery .= ' ORDER BY `num` DESC';
$result = mysqli_query_safe($con, $SQLquery);
$DupesDeleted = 0;
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
if ($row['num'] <= 1) {
break;
}
echo '
'.htmlentities($row['filename']).' (duplicate)';
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE `filename` LIKE "'.mysqli_real_escape_string($con, $row['filename']).'"';
mysqli_query_safe($con, $SQLquery);
$DupesDeleted++;
}
if ($DupesDeleted > 0) {
echo '
Deleted '.number_format($DupesDeleted).' duplicate filenames
';
}
$SQLquery = 'SELECT `filename`, `filesize`, `last_modified`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
$totalchecked = 0;
$totalremoved = 0;
$previousdir = '';
while ($row = mysqli_fetch_array($result)) {
$totalchecked++;
set_time_limit(30);
$reason = '';
if (!file_exists($row['filename'])) {
$reason = 'deleted';
} elseif (filesize($row['filename']) != $row['filesize']) {
$reason = 'filesize changed';
} elseif (filemtime($row['filename']) != $row['last_modified']) {
if (abs(filemtime($row['filename']) - $row['last_modified']) != 3600) {
// off by exactly one hour == daylight savings time
$reason = 'last-modified time changed';
}
}
$thisdir = dirname($row['filename']);
if ($reason) {
$totalremoved++;
echo '
'.htmlentities($row['filename']).' ('.$reason.')';
flush();
$SQLquery = 'DELETE';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
mysqli_query_safe($con, $SQLquery);
} elseif ($thisdir != $previousdir) {
echo '. ';
flush();
}
$previousdir = $thisdir;
}
echo '
'.number_format($totalremoved).' of '.number_format($totalchecked).' files in database no longer exist, or have been altered since last scan. Removed from database.
';
} elseif (!empty($_REQUEST['encodedbydistribution'])) {
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
$SQLquery = 'SELECT `filename`, `comments_id3v2`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`encoder_options` = "'.mysqli_real_escape_string($con, $_REQUEST['encodedbydistribution']).'")';
$result = mysqli_query_safe($con, $SQLquery);
$NonBlankEncodedBy = '';
$BlankEncodedBy = '';
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$CommentArray = unserialize($row['comments_id3v2']);
if (isset($CommentArray['encoded_by'][0])) {
$NonBlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n";
} else {
$BlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n";
}
}
echo $NonBlankEncodedBy;
echo $BlankEncodedBy;
exit;
} elseif (!empty($_REQUEST['showfiles'])) {
echo 'show all
';
echo '';
$SQLquery = 'SELECT `filename`, `comments_id3v2`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$result = mysqli_query_safe($con, $SQLquery);
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$CommentArray = unserialize($row['comments_id3v2']);
if (($_REQUEST['encodedbydistribution'] == '%') || (!empty($CommentArray['encoded_by'][0]) && ($_REQUEST['encodedbydistribution'] == $CommentArray['encoded_by'][0]))) {
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' |
';
}
}
echo '
';
} else {
$SQLquery = 'SELECT `encoder_options`, `comments_id3v2`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC';
$result = mysqli_query_safe($con, $SQLquery);
$EncodedBy = array();
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$CommentArray = unserialize($row['comments_id3v2']);
if (isset($CommentArray['encoded_by'][0])) {
if (isset($EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]])) {
$EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]]++;
} else {
$EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]] = 1;
}
}
}
echo '.m3u version
';
echo 'm3u | Encoder Options | Encoded By (ID3v2) |
';
foreach ($EncodedBy as $key => $value) {
echo 'm3u | ';
echo ''.$key.' | ';
echo '';
arsort($value);
foreach ($value as $string => $count) {
echo ''.number_format($count).' | | ';
echo ''.$string.' | ';
}
echo ' |
';
}
echo '
';
}
} elseif (!empty($_REQUEST['audiobitrates'])) {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
$BitrateDistribution = array();
$SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`audio_bitrate` > 0)';
$SQLquery .= ' GROUP BY `RoundBitrate`';
$result = mysqli_query_safe($con, $SQLquery);
while ($row = mysqli_fetch_array($result)) {
$this_bitrate = getid3_mp3::ClosestStandardMP3Bitrate($row['RoundBitrate'] * 1000);
if (isset($BitrateDistribution[$this_bitrate])) {
$BitrateDistribution[$this_bitrate] += $row['num'];
} else {
$BitrateDistribution[$this_bitrate] = $row['num'];
}
}
echo '';
echo 'Bitrate | Count |
';
foreach ($BitrateDistribution as $Bitrate => $Count) {
echo '';
echo ''.round($Bitrate / 1000).' kbps | ';
echo ''.number_format($Count).' | ';
echo '
';
}
echo '
';
} elseif (!empty($_REQUEST['emptygenres'])) {
$SQLquery = 'SELECT `fileformat`, `filename`, `genre`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`genre` = "")';
$SQLquery .= ' OR (`genre` = "Unknown")';
$SQLquery .= ' OR (`genre` = "Other")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
}
exit;
} else {
echo '.m3u version
';
$EmptyGenreCounter = 0;
echo '';
echo 'm3u | filename |
';
while ($row = mysqli_fetch_array($result)) {
if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) {
$EmptyGenreCounter++;
echo '';
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' | ';
echo '
';
}
}
echo '
';
echo ''.number_format($EmptyGenreCounter).' files with empty genres';
}
} elseif (!empty($_REQUEST['nonemptycomments'])) {
$SQLquery = 'SELECT `filename`, `comment`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`comment` <> "")';
$SQLquery .= ' ORDER BY `comment` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
$NonEmptyCommentsCounter = 0;
echo '.m3u version
';
echo '';
echo 'm3u | filename | comments |
';
while ($row = mysqli_fetch_array($result)) {
$NonEmptyCommentsCounter++;
echo '';
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' | ';
if (strlen(trim($row['comment'])) > 0) {
echo ''.htmlentities($row['comment']).' | ';
} else {
echo 'space | ';
}
echo '
';
}
echo '
';
echo ''.number_format($NonEmptyCommentsCounter).' files with non-empty comments';
}
} elseif (!empty($_REQUEST['trackzero'])) {
$SQLquery = 'SELECT `filename`, `track`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`track` <> "")';
$SQLquery .= ' AND ((`track` < "1")';
$SQLquery .= ' OR (`track` > "99"))';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
if ((strlen($row['track_number']) > 0) && ($row['track_number'] < 1) || ($row['track_number'] > 99)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
}
exit;
} else {
echo '.m3u version
';
$TrackZeroCounter = 0;
echo '';
echo 'm3u | filename | track |
';
while ($row = mysqli_fetch_array($result)) {
if ((strlen($row['track_number']) > 0) && ($row['track_number'] < 1) || ($row['track_number'] > 99)) {
$TrackZeroCounter++;
echo '';
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' | ';
echo ''.htmlentities($row['track_number']).' | ';
echo '
';
}
}
echo '
';
echo ''.number_format($TrackZeroCounter).' files with track "zero"';
}
} elseif (!empty($_REQUEST['titlefeat'])) {
$SQLquery = 'SELECT `filename`, `title`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`title` LIKE "%feat.%")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
echo ''.number_format(mysqli_num_rows($result)).' files with "feat." in the title (instead of the artist)
';
echo '.m3u version
';
echo '';
echo 'm3u | filename | title |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' | ';
echo ''.preg_replace('#(feat\. .*)#i', '\\1', htmlentities($row['title'])).' | ';
echo '
';
}
echo '
';
}
} elseif (!empty($_REQUEST['tracknoalbum'])) {
$SQLquery = 'SELECT `filename`, `track`, `album`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`track` <> "")';
$SQLquery .= ' AND (`album` = "")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
echo ''.number_format(mysqli_num_rows($result)).' files with a track number, but no album
';
echo '.m3u version
';
echo '';
echo 'm3u | filename | track | album |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' | ';
echo ''.htmlentities($row['track_number']).' | ';
echo ''.htmlentities($row['album']).' | ';
echo '
';
}
echo '
';
}
} elseif (!empty($_REQUEST['synchronizetagsfrom']) && !empty($_REQUEST['filename'])) {
echo 'Applying new tags from '.$_REQUEST['synchronizetagsfrom'].' in '.htmlentities($_REQUEST['filename']).'';
$errors = array();
if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) {
echo '- Sucessfully wrote tags
';
} else {
echo '- Tag writing had errors:
';
}
echo '
';
} elseif (!empty($_REQUEST['unsynchronizedtags'])) {
$NotOKfiles = 0;
$Autofixedfiles = 0;
$FieldsToCompare = array('title', 'artist', 'album', 'year', 'genre', 'comment', 'track_number');
$TagsToCompare = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false);
$ID3v1FieldLengths = array('title'=>30, 'artist'=>30, 'album'=>30, 'year'=>4, 'genre'=>99, 'comment'=>28);
if (strpos($_REQUEST['unsynchronizedtags'], '2') !== false) {
$TagsToCompare['id3v2'] = true;
}
if (strpos($_REQUEST['unsynchronizedtags'], 'A') !== false) {
$TagsToCompare['ape'] = true;
}
if (strpos($_REQUEST['unsynchronizedtags'], 'L') !== false) {
$TagsToCompare['lyrics3'] = true;
}
if (strpos($_REQUEST['unsynchronizedtags'], '1') !== false) {
$TagsToCompare['id3v1'] = true;
}
echo 'Auto-fix empty tags
';
echo '';
echo '';
echo '';
echo 'View | ';
echo 'Filename | ';
echo 'Combined | ';
if ($TagsToCompare['id3v2']) {
echo 'ID3v2 | ';
}
if ($TagsToCompare['ape']) {
echo 'APE | ';
}
if ($TagsToCompare['lyrics3']) {
echo 'Lyrics3 | ';
}
if ($TagsToCompare['id3v1']) {
echo 'ID3v1 | ';
}
echo '
';
$SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` = "mp3")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
$lastdir = '';
$serializedCommentsFields = array('all', 'id3v2', 'ape', 'lyrics3', 'id3v1');
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
if ($lastdir != dirname($row['filename'])) {
echo '';
flush();
}
$FileOK = true;
$Mismatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false);
$SemiMatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false);
$EmptyTags = array('id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true);
foreach ($serializedCommentsFields as $field) {
$Comments[$field] = array();
ob_start();
if ($unserialized = unserialize($row['comments_'.$field])) {
$Comments[$field] = $unserialized;
}
$errormessage = ob_get_contents();
ob_end_clean();
}
if (isset($Comments['ape']['tracknumber'])) {
$Comments['ape']['track_number'] = $Comments['ape']['tracknumber'];
unset($Comments['ape']['tracknumber']);
}
if (isset($Comments['ape']['track'])) {
$Comments['ape']['track_number'] = $Comments['ape']['track'];
unset($Comments['ape']['track']);
}
if (!empty($Comments['all']['track'])) {
$besttrack = '';
foreach ($Comments['all']['track'] as $key => $value) {
if (strlen($value) > strlen($besttrack)) {
$besttrack = $value;
}
}
$Comments['all']['track_number'] = array(0=>$besttrack);
}
$ThisLine = '';
$ThisLine .= 'view | ';
$ThisLine .= ''.htmlentities($row['filename']).' | ';
$tagvalues = '';
foreach ($FieldsToCompare as $fieldname) {
$tagvalues .= $fieldname.' = '.(!empty($Comments['all'][$fieldname]) ? implode(" \n", $Comments['all'][$fieldname]) : '')." \n";
}
$ThisLine .= 'all | ';
foreach ($TagsToCompare as $tagtype => $CompareThisTagType) {
if ($CompareThisTagType) {
$tagvalues = '';
foreach ($FieldsToCompare as $fieldname) {
if ($tagtype == 'id3v1') {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
if (($fieldname == 'genre') && !empty($Comments['all'][$fieldname][0]) && !getid3_id3v1::LookupGenreID($Comments['all'][$fieldname][0])) {
// non-standard genres can never match, so just ignore
$tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
} elseif ($fieldname == 'comment') {
if (isset($Comments[$tagtype][$fieldname][0]) && isset($Comments['all'][$fieldname][0]) && (rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 28)) != rtrim(substr($Comments['all'][$fieldname][0], 0, 28)))) {
$tagvalues .= $fieldname.' = [['.$Comments[$tagtype][$fieldname][0].']]'."\n";
if (trim(strtolower(RemoveAccents(substr($Comments[$tagtype][$fieldname][0], 0, 28)))) == trim(strtolower(RemoveAccents(substr($Comments['all'][$fieldname][0], 0, 28))))) {
$SemiMatched[$tagtype] = true;
} else {
$Mismatched[$tagtype] = true;
}
$FileOK = false;
} else {
$tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
}
} elseif ($fieldname == 'track_number') {
// intval('01/20') == intval('1')
$trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '');
$trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '');
if (intval($trackA) != intval($trackB)) {
$tagvalues .= $fieldname.' = [['.$trackA.']]'."\n";
$Mismatched[$tagtype] = true;
$FileOK = false;
} else {
$tagvalues .= $fieldname.' = '.$trackA."\n";
}
} elseif ((isset($Comments[$tagtype][$fieldname][0]) ? rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 30)) : '') != (isset($Comments['all'][$fieldname][0]) ? rtrim(substr($Comments['all'][$fieldname][0], 0, 30)) : '')) {
$tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n";
if (strtolower(RemoveAccents(trim(substr((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''), 0, 30)))) == strtolower(RemoveAccents(trim(substr((isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''), 0, 30))))) {
$SemiMatched[$tagtype] = true;
} else {
$Mismatched[$tagtype] = true;
}
$FileOK = false;
if (!empty($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
} else {
$tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
}
} elseif (($tagtype == 'ape') && ($fieldname == 'year')) {
if (((isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : '')) && ((isset($Comments['ape']['year'][0]) ? $Comments['ape']['year'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : ''))) {
$tagvalues .= $fieldname.' = [['.(isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '').']]'."\n";
$Mismatched[$tagtype] = true;
$FileOK = false;
if (isset($Comments['ape']['date'][0]) && (strlen(trim($Comments['ape']['date'][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
} else {
$tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
}
} elseif (($fieldname == 'genre') && !empty($Comments['all'][$fieldname]) && !empty($Comments[$tagtype][$fieldname]) && in_array($Comments[$tagtype][$fieldname][0], $Comments['all'][$fieldname])) {
$tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
} elseif ((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '') != (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '')) {
$skiptracknumberfield = false;
switch ($fieldname) {
case 'track':
case 'tracknumber':
case 'track_number':
$trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '');
$trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '');
if (intval($trackA) == intval($trackB)) {
$skiptracknumberfield = true;
}
break;
}
if (!$skiptracknumberfield) {
$tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n";
$tagA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '');
$tagB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '');
if (trim(strtolower(RemoveAccents($tagA))) == trim(strtolower(RemoveAccents($tagB)))) {
$SemiMatched[$tagtype] = true;
} else {
$Mismatched[$tagtype] = true;
}
$FileOK = false;
if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
}
} else {
$tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
$EmptyTags[$tagtype] = false;
}
}
}
if ($EmptyTags[$tagtype]) {
$FileOK = false;
$ThisLine .= '';
} elseif ($SemiMatched[$tagtype]) {
$ThisLine .= ' | ';
} elseif ($Mismatched[$tagtype]) {
$ThisLine .= ' | ';
} else {
$ThisLine .= ' | ';
}
$ThisLine .= ''.$tagtype.'';
$ThisLine .= ' | ';
}
}
$ThisLine .= '
';
if (!$FileOK) {
$NotOKfiles++;
echo '';
flush();
if (!empty($_REQUEST['autofix'])) {
$AnyMismatched = false;
foreach ($Mismatched as $key => $value) {
if ($value && ($EmptyTags["$key"] === false)) {
$AnyMismatched = true;
}
}
if ($AnyMismatched && empty($_REQUEST['autofixforcesource'])) {
echo $ThisLine;
} else {
$TagsToSynch = '';
foreach ($EmptyTags as $key => $value) {
if ($value) {
switch ($key) {
case 'id3v1':
$TagsToSynch .= '1';
break;
case 'id3v2':
$TagsToSynch .= '2';
break;
case 'ape':
$TagsToSynch .= 'A';
break;
}
}
}
$autofixforcesource = (!empty($_REQUEST['autofixforcesource']) ? $_REQUEST['autofixforcesource'] : 'all');
$TagsToSynch = (!empty($_REQUEST['autofixforcedest']) ? $_REQUEST['autofixforcedest'] : $TagsToSynch);
$errors = array();
if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) {
$Autofixedfiles++;
echo '';
} else {
echo '
';
}
echo ' ';
echo ' | '.htmlentities($row['filename']).' | ';
echo '';
echo ''.$TagsToSynch.' | ';
echo ' |
';
}
} else {
echo $ThisLine;
}
}
}
echo '
';
echo '';
echo 'Found '.number_format($NotOKfiles).' files with unsynchronized tags, and auto-fixed '.number_format($Autofixedfiles).' of them.';
} elseif (!empty($_REQUEST['filenamepattern'])) {
$patterns['A'] = 'artist';
$patterns['T'] = 'title';
$patterns['M'] = 'album';
$patterns['N'] = 'track';
$patterns['G'] = 'genre';
$patterns['R'] = 'remix';
$FieldsToUse = explode(' ', wordwrap(preg_replace('#[^A-Z]#i', '', $_REQUEST['filenamepattern']), 1, ' ', 1));
//$FieldsToUse = explode(' ', wordwrap($_REQUEST['filenamepattern'], 1, ' ', 1));
foreach ($FieldsToUse as $FieldID) {
$FieldNames[] = $patterns["$FieldID"];
}
$SQLquery = 'SELECT `filename`, `fileformat`, '.implode(', ', $FieldNames);
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'Files that do not match naming pattern: (auto-fix)
';
echo '';
echo 'view | Why | Actual filename (click to play/edit file) | Correct filename (based on tags)'.(empty($_REQUEST['autofix']) ? ' (click to rename file to this)' : '').' |
';
$nonmatchingfilenames = 0;
$Pattern = $_REQUEST['filenamepattern'];
$PatternLength = strlen($Pattern);
while ($row = mysqli_fetch_array($result)) {
set_time_limit(10);
$PatternFilename = '';
for ($i = 0; $i < $PatternLength; $i++) {
if (isset($patterns[$Pattern[$i]])) {
$PatternFilename .= trim(strtr($row[$patterns[$Pattern[$i]]], ':\\*<>|', ';-¤«»¦'), ' ');
} else {
$PatternFilename .= $Pattern[$i];
}
}
// Replace "~" with "-" if characters immediately before and after are both numbers,
// "/" has been replaced with "~" above which is good for multi-song medley dividers,
// but for things like 24/7, 7/8ths, etc it looks better if it's 24-7, 7-8ths, etc.
$PatternFilename = preg_replace('#([ a-z]+)/([ a-z]+)#i', '\\1~\\2', $PatternFilename);
$PatternFilename = str_replace('/', '×', $PatternFilename);
$PatternFilename = str_replace('?', '¿', $PatternFilename);
$PatternFilename = str_replace(' "', ' ', $PatternFilename);
$PatternFilename = str_replace('("', '(', $PatternFilename);
$PatternFilename = str_replace('-"', '-', $PatternFilename);
$PatternFilename = str_replace('" ', ' ', $PatternFilename.' ');
$PatternFilename = str_replace('"', '', $PatternFilename);
$PatternFilename = str_replace(' ', ' ', $PatternFilename);
$ParenthesesPairs = array('()', '[]', '{}');
foreach ($ParenthesesPairs as $pair) {
// multiple remixes are stored tab-seperated in the database.
// change "{2000 Version\tSomebody Remix}" into "{2000 Version} {Somebody Remix}"
while (preg_match('#^(.*)'.preg_quote($pair[0]).'([^'.preg_quote($pair[1]).']*)('."\t".')([^'.preg_quote($pair[0]).']*)'.preg_quote($pair[1]).'#', $PatternFilename, $matches)) {
$PatternFilename = $matches[1].$pair[0].$matches[2].$pair[1].' '.$pair[0].$matches[4].$pair[1];
}
// remove empty parenthesized pairs (probably where no track numbers, remix version, etc)
$PatternFilename = preg_replace('#'.preg_quote($pair).'#', '', $PatternFilename);
// "[01] - Title With No Artist.mp3" ==> "[01] Title With No Artist.mp3"
$PatternFilename = preg_replace('#'.preg_quote($pair[1]).' +\- #', $pair[1].' ', $PatternFilename);
}
// get rid of leading & trailing spaces if end items (artist or title for example) are missing
$PatternFilename = trim($PatternFilename, ' -');
if (!$PatternFilename) {
// no tags to create a filename from -- skip this file
continue;
}
$PatternFilename .= '.'.$row['fileformat'];
$ActualFilename = basename($row['filename']);
if ($ActualFilename != $PatternFilename) {
$NotMatchedReasons = '';
if (strtolower($ActualFilename) === strtolower($PatternFilename)) {
$NotMatchedReasons .= 'Aa ';
} elseif (RemoveAccents($ActualFilename) === RemoveAccents($PatternFilename)) {
$NotMatchedReasons .= 'ée ';
}
$actualExt = '.'.fileextension($ActualFilename);
$patternExt = '.'.fileextension($PatternFilename);
$ActualFilenameNoExt = (($actualExt != '.') ? substr($ActualFilename, 0, 0 - strlen($actualExt)) : $ActualFilename);
$PatternFilenameNoExt = (($patternExt != '.') ? substr($PatternFilename, 0, 0 - strlen($patternExt)) : $PatternFilename);
if (strpos($PatternFilenameNoExt, $ActualFilenameNoExt) !== false) {
$DifferenceBoldedName = str_replace($ActualFilenameNoExt, ''.$ActualFilenameNoExt.'', $PatternFilenameNoExt);
} else {
$ShortestNameLength = min(strlen($ActualFilenameNoExt), strlen($PatternFilenameNoExt));
for ($DifferenceOffset = 0; $DifferenceOffset < $ShortestNameLength; $DifferenceOffset++) {
if ($ActualFilenameNoExt[$DifferenceOffset] !== $PatternFilenameNoExt[$DifferenceOffset]) {
break;
}
}
$DifferenceBoldedName = ''.substr($PatternFilenameNoExt, 0, $DifferenceOffset).''.substr($PatternFilenameNoExt, $DifferenceOffset);
}
$DifferenceBoldedName .= (($actualExt == $patternExt) ? ''.$patternExt.'' : $patternExt);
echo '';
echo 'view | ';
echo ' '.$NotMatchedReasons.' | ';
echo ''.htmlentities($ActualFilename).' | ';
if (!empty($_REQUEST['autofix'])) {
$results = '';
if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) {
echo '';
} else {
echo ' | ';
}
echo ''.$DifferenceBoldedName.' | ';
} else {
echo '';
echo ''.$DifferenceBoldedName.' | ';
}
echo '
';
$nonmatchingfilenames++;
}
}
echo '
';
echo 'Found '.number_format($nonmatchingfilenames).' files that do not match naming pattern
';
} elseif (!empty($_REQUEST['encoderoptionsdistribution'])) {
if (isset($_REQUEST['showtagfiles'])) {
$SQLquery = 'SELECT `filename`, `encoder_options` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['showtagfiles']).'")';
$SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
echo 'Show all Encoder Options
';
echo 'Files with Encoder Options '.htmlentities($_REQUEST['showtagfiles']).':
';
echo '';
}
} elseif (!isset($_REQUEST['m3u'])) {
$SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' GROUP BY `encoder_options`';
$SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC, `num` DESC, `encoder_options` ASC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'Files with Encoder Options:
';
echo '';
echo 'Encoder Options | Count | M3U |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo ''.$row['encoder_options'].' | ';
echo ''.number_format($row['num']).' | ';
echo 'm3u | ';
echo '
';
}
echo '
';
}
} elseif (!empty($_REQUEST['tagtypes'])) {
if (!isset($_REQUEST['m3u'])) {
$SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' GROUP BY `tags`';
$SQLquery .= ' ORDER BY `num` DESC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'Files with tags:
';
echo '';
echo 'Tags | Count | M3U |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo ''.$row['tags'].' | ';
echo ''.number_format($row['num']).' | ';
echo 'm3u | ';
echo '
';
}
echo '
';
}
if (isset($_REQUEST['showtagfiles'])) {
$SQLquery = 'SELECT `filename`, `tags` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`tags` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['showtagfiles']).'")';
$SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
echo '';
}
}
} elseif (!empty($_REQUEST['md5datadupes'])) {
$OtherFormats = '';
$AVFormats = '';
$SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`md5_data` <> "")';
$SQLquery .= ' GROUP BY `md5_data`';
$SQLquery .= ' ORDER BY `num` DESC';
$result = mysqli_query_safe($con, $SQLquery);
while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) {
set_time_limit(30);
$filenames = array();
$tags = array();
$md5_data = array();
$SQLquery = 'SELECT `fileformat`, `filename`, `tags`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`md5_data` = "'.mysqli_real_escape_string($con, $row['md5_data']).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result2 = mysqli_query_safe($con, $SQLquery);
while ($row2 = mysqli_fetch_array($result2)) {
$thisfileformat = $row2['fileformat'];
$filenames[] = $row2['filename'];
$tags[] = $row2['tags'];
$md5_data[] = $row['md5_data'];
}
$thisline = '';
$thisline .= ''.implode(' ', $md5_data).' | ';
$thisline .= ''.implode(' ', $tags).' | ';
$thisline .= ''.implode(' ', $filenames).' | ';
$thisline .= '
';
if (in_array($thisfileformat, $IgnoreNoTagFormats)) {
$OtherFormats .= $thisline;
} else {
$AVFormats .= $thisline;
}
}
echo 'Duplicated MD5_DATA (Audio/Video files):
';
echo 'Duplicated MD5_DATA (Other files):
';
} elseif (!empty($_REQUEST['artisttitledupes'])) {
if (isset($_REQUEST['m3uartist']) && isset($_REQUEST['m3utitle'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $_REQUEST['m3uartist']).'")';
$SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $_REQUEST['m3utitle']).'")';
$SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
}
$SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`artist` <> "")';
$SQLquery .= ' AND (`title` <> "")';
$SQLquery .= ' GROUP BY `artist`, `title`'.(!empty($_REQUEST['samemix']) ? ', `remix`' : '');
$SQLquery .= ' ORDER BY `num` DESC, `artist` ASC, `title` ASC, `playtime_seconds` ASC, `remix` ASC';
$result = mysqli_query_safe($con, $SQLquery);
$uniquetitles = 0;
$uniquefiles = 0;
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) {
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $row['artist']).'")';
$SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $row['title']).'")';
if (!empty($_REQUEST['samemix'])) {
$SQLquery .= ' AND (`remix` = "'.mysqli_real_escape_string($con, $row['remix']).'")';
}
$SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC';
$result2 = mysqli_query_safe($con, $SQLquery);
while ($row2 = mysqli_fetch_array($result2)) {
echo WindowsShareSlashTranslate($row2['filename'])."\n";
}
}
exit;
} else {
echo 'Duplicated aritst + title: (Identical Mix/Version only)
';
echo '(.m3u version)
';
echo '';
echo ' | Artist | Title | Version | | | Filename |
';
while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) {
$uniquetitles++;
set_time_limit(30);
$filenames = array();
$artists = array();
$titles = array();
$remixes = array();
$bitrates = array();
$playtimes = array();
$SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $row['artist']).'")';
$SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $row['title']).'")';
$SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC';
$result2 = mysqli_query_safe($con, $SQLquery);
while ($row2 = mysqli_fetch_array($result2)) {
$uniquefiles++;
$filenames[] = $row2['filename'];
$artists[] = $row2['artist'];
$titles[] = $row2['title'];
$remixes[] = $row2['remix'];
if ($row2['vbr_method']) {
$bitrates[] = ''.BitrateText($row2['audio_bitrate'] / 1000).'';
} else {
$bitrates[] = BitrateText($row2['audio_bitrate'] / 1000);
}
$playtimes[] = getid3_lib::PlaytimeString($row2['playtime_seconds']);
}
echo '';
echo '';
foreach ($filenames as $file) {
echo 'delete ';
}
echo ' | ';
echo '';
foreach ($filenames as $file) {
echo 'play ';
}
echo ' | ';
echo 'play all | ';
echo ''.implode(' ', $artists).' | ';
echo ''.implode(' ', $titles).' | ';
echo ''.implode(' ', $remixes).' | ';
echo ''.implode(' ', $bitrates).' | ';
echo ''.implode(' ', $playtimes).' | ';
echo ' | ';
echo '
';
}
}
echo '
';
echo number_format($uniquefiles).' files with '.number_format($uniquetitles).' unique aritst + title
';
echo '
';
} elseif (!empty($_REQUEST['filetypelist'])) {
list($fileformat, $audioformat) = explode('|', $_REQUEST['filetypelist']);
$SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` = "'.mysqli_real_escape_string($con, $fileformat).'")';
$SQLquery .= ' AND (`audio_dataformat` = "'.mysqli_real_escape_string($con, $audioformat).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'Files of format '.$fileformat.'.'.$audioformat.':';
echo 'file | audio | filename |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo ''.$row['fileformat'].' | ';
echo ''.$row['audio_dataformat'].' | ';
echo ''.htmlentities($row['filename']).' | ';
echo '
';
}
echo '
';
} elseif (!empty($_REQUEST['trackinalbum'])) {
$SQLquery = 'SELECT `filename`, `album`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`album` LIKE "% [%")';
$SQLquery .= ' ORDER BY `album` ASC, `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} elseif (!empty($_REQUEST['autofix'])) {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($filename);
$getID3->CopyTagsToComments($ThisFileInfo);
if (!empty($ThisFileInfo['tags'])) {
$Album = trim(str_replace(strstr($ThisFileInfo['comments']['album'][0], ' ['), '', $ThisFileInfo['comments']['album'][0]));
$Track = (string) intval(str_replace(' [', '', str_replace(']', '', strstr($ThisFileInfo['comments']['album'][0], ' ['))));
if ($Track == '0') {
$Track = '';
}
if ($Album && $Track) {
echo '
'.htmlentities($row['filename']).'
';
echo ''.htmlentities($Album).' (track #'.$Track.')
';
echo 'ID3v2: '.(RemoveID3v2($row['filename'], false) ? 'removed' : 'REMOVAL FAILED!').', ';
$WriteID3v1_title = (isset($ThisFileInfo['comments']['title'][0]) ? $ThisFileInfo['comments']['title'][0] : '');
$WriteID3v1_artist = (isset($ThisFileInfo['comments']['artist'][0]) ? $ThisFileInfo['comments']['artist'][0] : '');
$WriteID3v1_year = (isset($ThisFileInfo['comments']['year'][0]) ? $ThisFileInfo['comments']['year'][0] : '');
$WriteID3v1_comment = (isset($ThisFileInfo['comments']['comment'][0]) ? $ThisFileInfo['comments']['comment'][0] : '');
$WriteID3v1_genreid = (isset($ThisFileInfo['comments']['genreid'][0]) ? $ThisFileInfo['comments']['genreid'][0] : '');
echo 'ID3v1: '.(WriteID3v1($row['filename'], $WriteID3v1_title, $WriteID3v1_artist, $Album, $WriteID3v1_year, $WriteID3v1_comment, $WriteID3v1_genreid, $Track, false) ? 'updated' : 'UPDATE FAILED').'
';
} else {
echo ' . ';
}
} else {
echo '
FAILED
'.htmlentities($row['filename']).'
';
}
flush();
}
} else {
echo ''.number_format(mysqli_num_rows($result)).' files with [??]-format track numbers in album field:
';
if (mysqli_num_rows($result) > 0) {
echo '(.m3u version)
';
echo 'Try to auto-fix
';
echo '';
}
echo '
';
}
} elseif (!empty($_REQUEST['fileextensions'])) {
$SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
$invalidextensionfiles = 0;
$invalidextensionline = '';
$invalidextensionline .= 'file | audio | video | tags | actual | correct | filename |
';
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$acceptableextensions = AcceptableExtensions($row['fileformat'], $row['audio_dataformat'], $row['video_dataformat']);
$actualextension = strtolower(fileextension($row['filename']));
if ($acceptableextensions && !in_array($actualextension, $acceptableextensions)) {
$invalidextensionfiles++;
$invalidextensionline .= '';
$invalidextensionline .= ''.$row['fileformat'].' | ';
$invalidextensionline .= ''.$row['audio_dataformat'].' | ';
$invalidextensionline .= ''.$row['video_dataformat'].' | ';
$invalidextensionline .= ''.$row['tags'].' | ';
$invalidextensionline .= ''.$actualextension.' | ';
$invalidextensionline .= ''.implode('; ', $acceptableextensions).' | ';
$invalidextensionline .= ''.htmlentities($row['filename']).' | ';
$invalidextensionline .= '
';
}
}
$invalidextensionline .= '
';
echo number_format($invalidextensionfiles).' files with incorrect filename extension:
';
echo $invalidextensionline;
} elseif (isset($_REQUEST['genredistribution'])) {
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (BINARY `genre` = "'.$_REQUEST['genredistribution'].'")';
$SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
if ($_REQUEST['genredistribution'] == '%') {
$SQLquery = 'SELECT COUNT(*) AS `num`, `genre`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
$SQLquery .= ' GROUP BY `genre`';
$SQLquery .= ' ORDER BY `num` DESC';
$result = mysqli_query_safe($con, $SQLquery);
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
echo '';
echo 'Count | Genre | m3u |
';
while ($row = mysqli_fetch_array($result)) {
$GenreID = getid3_id3v1::LookupGenreID($row['genre']);
if (is_numeric($GenreID)) {
echo '';
} else {
echo '
';
}
echo ''.number_format($row['num']).' | ';
echo ''.str_replace("\t", ' ', $row['genre']).' | ';
echo '.m3u | ';
echo '
';
}
echo '
';
} else {
$SQLquery = 'SELECT `filename`, `genre`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`genre` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['genredistribution']).'")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'All Genres
';
echo '';
echo 'Genre | m3u | Filename |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo ''.str_replace("\t", ' ', $row['genre']).' | ';
echo 'm3u | ';
echo ''.htmlentities($row['filename']).' | ';
echo '
';
}
echo '
';
}
}
} elseif (!empty($_REQUEST['formatdistribution'])) {
$SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`';
$SQLquery .= ' ORDER BY `num` DESC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'File format distribution:
';
} elseif (!empty($_REQUEST['errorswarnings'])) {
$SQLquery = 'SELECT `filename`, `error`, `warning`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`error` <> "")';
$SQLquery .= ' OR (`warning` <> "")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
if (!empty($_REQUEST['m3u'])) {
header('Content-type: audio/x-mpegurl');
echo '#EXTM3U'."\n";
while ($row = mysqli_fetch_array($result)) {
echo WindowsShareSlashTranslate($row['filename'])."\n";
}
exit;
} else {
echo number_format(mysqli_num_rows($result)).' files with errors or warnings:
';
echo '(.m3u version)
';
echo '';
echo 'Filename | Error | Warning |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo ''.htmlentities($row['filename']).' | ';
echo ''.(!empty($row['error']) ? ''.str_replace("\t", '', htmlentities($row['error'])).'' : ' ').' | ';
echo ''.(!empty($row['warning']) ? ''.str_replace("\t", '', htmlentities($row['warning'])).'' : ' ').' | ';
echo '
';
}
}
echo '
';
} elseif (!empty($_REQUEST['fixid3v1padding'])) {
getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v1.php', __FILE__, true);
$id3v1_writer = new getid3_write_id3v1;
$SQLquery = 'SELECT `filename`, `error`, `warning`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` = "mp3")';
$SQLquery .= ' AND (`warning` <> "")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
$totaltofix = mysqli_num_rows($result);
$rowcounter = 0;
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
if (strpos($row['warning'], 'Some ID3v1 fields do not use NULL characters for padding') !== false) {
set_time_limit(30);
$id3v1_writer->filename = $row['filename'];
echo ($id3v1_writer->FixID3v1Padding() ? 'fixed - ' : 'error - ');
} else {
echo 'No error? - ';
}
echo '['.++$rowcounter.' / '.$totaltofix.'] ';
echo htmlentities($row['filename']).'
';
flush();
}
} elseif (!empty($_REQUEST['vbrmethod'])) {
if ($_REQUEST['vbrmethod'] == '1') {
$SQLquery = 'SELECT COUNT(*) AS `num`, `vbr_method`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' GROUP BY `vbr_method`';
$SQLquery .= ' ORDER BY `vbr_method`';
$result = mysqli_query_safe($con, $SQLquery);
echo 'VBR methods:';
echo 'Count | VBR Method |
';
while ($row = mysqli_fetch_array($result)) {
echo '';
echo ''.htmlentities(number_format($row['num'])).' | ';
if ($row['vbr_method']) {
echo ''.htmlentities($row['vbr_method']).' | ';
} else {
echo 'CBR | ';
}
echo '
';
}
echo '
';
} else {
$SQLquery = 'SELECT `filename`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`vbr_method` = "'.mysqli_real_escape_string($con, $_REQUEST['vbrmethod']).'")';
$result = mysqli_query_safe($con, $SQLquery);
echo number_format(mysqli_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":';
}
echo '
';
} elseif (!empty($_REQUEST['correctcase'])) {
$SQLquery = 'SELECT `filename`, `fileformat`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$SQLquery .= ' WHERE (`fileformat` <> "")';
$SQLquery .= ' ORDER BY `filename` ASC';
$result = mysqli_query_safe($con, $SQLquery);
echo 'Copy and paste the following into a DOS batch file. You may have to run this script more than once to catch all the changes (remember to scan for deleted/changed files and rescan directory between scans)
';
echo '';
$lastdir = '';
while ($row = mysqli_fetch_array($result)) {
set_time_limit(30);
$CleanedFilename = CleanUpFileName($row['filename']);
if ($row['filename'] != $CleanedFilename) {
if (strtolower($lastdir) != strtolower(str_replace('/', '\\', dirname($row['filename'])))) {
$lastdir = str_replace('/', '\\', dirname($row['filename']));
echo 'cd "'.$lastdir.'"'."\n";
}
echo 'ren "'.basename($row['filename']).'" "'.basename(CleanUpFileName($row['filename'])).'"'."\n";
}
}
echo '
';
echo '
';
}
function CleanUpFileName($filename) {
$DirectoryName = dirname($filename);
$FileExtension = fileextension(basename($filename));
$BaseFilename = basename($filename, '.'.$FileExtension);
$BaseFilename = strtolower($BaseFilename);
$BaseFilename = str_replace('_', ' ', $BaseFilename);
//$BaseFilename = str_replace('-', ' - ', $BaseFilename);
$BaseFilename = str_replace('(', ' (', $BaseFilename);
$BaseFilename = str_replace('( ', '(', $BaseFilename);
$BaseFilename = str_replace(')', ') ', $BaseFilename);
$BaseFilename = str_replace(' )', ')', $BaseFilename);
$BaseFilename = str_replace(' \'\'', ' ', $BaseFilename);
$BaseFilename = str_replace('\'\' ', ' ', $BaseFilename);
$BaseFilename = str_replace(' vs ', ' vs. ', $BaseFilename);
while (strstr($BaseFilename, ' ') !== false) {
$BaseFilename = str_replace(' ', ' ', $BaseFilename);
}
$BaseFilename = trim($BaseFilename);
return $DirectoryName.'/'.BetterUCwords($BaseFilename).'.'.strtolower($FileExtension);
}
function BetterUCwords($string) {
$stringlength = strlen($string);
$string[0] = strtoupper($string[0]);
for ($i = 1; $i < $stringlength; $i++) {
if (($string[$i - 1] == '\'') && ($i > 1) && (($string[$i - 2] == 'O') || ($string[$i - 2] == ' '))) {
// O'Clock, 'Em
$string[$i] = strtoupper($string[$i]);
} elseif (preg_match('#^[\'A-Za-z0-9À-ÿ]$#', $string[$i - 1])) {
$string[$i] = strtolower($string[$i]);
} else {
$string[$i] = strtoupper($string[$i]);
}
}
static $LowerCaseWords = array('vs.', 'feat.');
static $UpperCaseWords = array('DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\'');
$OutputListOfWords = array();
$ListOfWords = explode(' ', $string);
foreach ($ListOfWords as $ThisWord) {
if (in_array(strtolower(str_replace('(', '', $ThisWord)), $LowerCaseWords)) {
$ThisWord = strtolower($ThisWord);
} elseif (in_array(strtoupper(str_replace('(', '', $ThisWord)), $UpperCaseWords)) {
$ThisWord = strtoupper($ThisWord);
} elseif ((substr($ThisWord, 0, 2) == 'Mc') && (strlen($ThisWord) > 2)) {
$ThisWord[2] = strtoupper($ThisWord[2]);
} elseif ((substr($ThisWord, 0, 3) == 'Mac') && (strlen($ThisWord) > 3)) {
$ThisWord[3] = strtoupper($ThisWord[3]);
}
$OutputListOfWords[] = $ThisWord;
}
$UCstring = implode(' ', $OutputListOfWords);
$UCstring = str_replace(' From ', ' from ', $UCstring);
$UCstring = str_replace(' \'n\' ', ' \'N\' ', $UCstring);
return $UCstring;
}
echo '
';
echo '
';
echo '';
$SQLquery = 'SELECT COUNT(*) AS `TotalFiles`, SUM(`playtime_seconds`) AS `TotalPlaytime`, SUM(`filesize`) AS `TotalFilesize`, AVG(`playtime_seconds`) AS `AvgPlaytime`, AVG(`filesize`) AS `AvgFilesize`, AVG(`audio_bitrate` + `video_bitrate`) AS `AvgBitrate`';
$SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
$result = mysqli_query_safe($con, $SQLquery);
if ($row = mysqli_fetch_array($result)) {
echo '
';
echo '';
echo 'Spent '.number_format(mysqli_query_safe($con, null), 3).' seconds querying the database
';
echo '
';
echo 'Currently in the database:';
echo 'Total Files | '.number_format($row['TotalFiles']).' |
';
echo 'Total Filesize | '.number_format($row['TotalFilesize'] / 1048576).' MB |
';
echo 'Total Playtime | '.number_format($row['TotalPlaytime'] / 3600, 1).' hours |
';
echo 'Average Filesize | '.number_format($row['AvgFilesize'] / 1048576, 1).' MB |
';
echo 'Average Playtime | '.getid3_lib::PlaytimeString($row['AvgPlaytime']).' |
';
echo 'Average Bitrate | '.BitrateText($row['AvgBitrate'] / 1000, 1).' |
';
echo '
';
echo '
';
}
echo '';