// // available at http://getid3.sourceforge.net // // or http://www.getid3.org // // also https://github.com/JamesHeinrich/getID3 // ///////////////////////////////////////////////////////////////// // // // /demo/demo.mysql.php - part of getID3() // // Sample script for recursively scanning directories and // // storing the results in a database // // See readme.txt for more details // // /// ///////////////////////////////////////////////////////////////// die('Due to a security issue, this demo has been disabled. It can be enabled by removing line 16 in demos/demo.mysql.php'); // OPTIONS: $getid3_demo_mysql_encoding = 'ISO-8859-1'; $getid3_demo_mysql_md5_data = false; // All data hashes are by far the slowest part of scanning $getid3_demo_mysql_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 (!mysql_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)) { $errormessage = ob_get_contents(); ob_end_clean(); die('Could not connect to MySQL host:
'.mysql_error().'
'); } if (!mysql_select_db(GETID3_DB_DB)) { $errormessage = ob_get_contents(); ob_end_clean(); die('Could not select database:
'.mysql_error().'
'); } ob_end_clean(); $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([ 'option_md5_data' => $getid3_demo_mysql_md5_data, 'encoding' => $getid3_demo_mysql_encoding, ]); function RemoveAccents($string) { // Revised version by markstewardØhotmail*com return strtr(strtr($string, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), ['Þ' => '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 FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($from).'")'; mysql_query_safe($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 mysql_query_safe($SQLquery) { static $TimeSpentQuerying = 0; if ($SQLquery === null) { return $TimeSpentQuerying; } $starttime = microtime(true); $result = mysql_query($SQLquery); $TimeSpentQuerying += (microtime(true) - $starttime); if (mysql_error()) { die('
SQL error:
'.htmlentities(mysql_error()).'

'.htmlentities($SQLquery).'
'); } return $result; } function mysql_table_exists($tablename) { return (bool) mysql_query('DESCRIBE '.$tablename); } function AcceptableExtensions($fileformat, $audio_dataformat = '', $video_dataformat = '') { static $AcceptableExtensionsAudio = []; if (empty($AcceptableExtensionsAudio)) { $AcceptableExtensionsAudio['mp3']['mp3'] = ['mp3']; $AcceptableExtensionsAudio['mp2']['mp2'] = ['mp2']; $AcceptableExtensionsAudio['mp1']['mp1'] = ['mp1']; $AcceptableExtensionsAudio['asf']['asf'] = ['asf']; $AcceptableExtensionsAudio['asf']['wma'] = ['wma']; $AcceptableExtensionsAudio['riff']['mp3'] = ['wav']; $AcceptableExtensionsAudio['riff']['wav'] = ['wav']; } static $AcceptableExtensionsVideo = []; if (empty($AcceptableExtensionsVideo)) { $AcceptableExtensionsVideo['mp3']['mp3'] = ['mp3']; $AcceptableExtensionsVideo['mp2']['mp2'] = ['mp2']; $AcceptableExtensionsVideo['mp1']['mp1'] = ['mp1']; $AcceptableExtensionsVideo['asf']['asf'] = ['asf']; $AcceptableExtensionsVideo['asf']['wmv'] = ['wmv']; $AcceptableExtensionsVideo['gif']['gif'] = ['gif']; $AcceptableExtensionsVideo['jpg']['jpg'] = ['jpg']; $AcceptableExtensionsVideo['png']['png'] = ['png']; $AcceptableExtensionsVideo['bmp']['bmp'] = ['bmp']; } if (!empty($video_dataformat)) { return (isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : []); } else { return (isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : []); } } if (!empty($_REQUEST['scan'])) { if (mysql_table_exists(GETID3_DB_TABLE)) { $SQLquery = 'DROP TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; mysql_query_safe($SQLquery); } } if (!mysql_table_exists(GETID3_DB_TABLE)) { $SQLquery = "CREATE TABLE `".mysql_real_escape_string(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` longtext NOT NULL,"; $SQLquery .= " `comments_id3v2` longtext NOT NULL,"; $SQLquery .= " `comments_ape` longtext NOT NULL,"; $SQLquery .= " `comments_lyrics3` longtext NOT NULL,"; $SQLquery .= " `comments_id3v1` text 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 .= ")"; mysql_query_safe($SQLquery); } $ExistingTableFields = []; $result = mysql_query_safe('DESCRIBE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); while ($row = mysql_fetch_array($result)) { $ExistingTableFields[$row['Field']] = $row; } if (!isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2 echo 'adding field `encoder_options`
'; mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `encoder_options` VARCHAR(255) default "" NOT NULL AFTER `error`'); mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } if (isset($ExistingTableFields['track']) && ($ExistingTableFields['track']['Type'] != 'varchar(7)')) { // Changed in 1.7.0b2 echo 'changing field `track` to VARCHAR(7)
'; mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `track` `track` VARCHAR(7) default "" NOT NULL'); mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(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`
'; mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `track_volume` FLOAT NOT NULL AFTER `error`'); mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } if (!isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1 echo 'adding field `encoder_options`, `alternate_name`, `parody`
'; mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `remix` VARCHAR(255) default "" NOT NULL AFTER `title`'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `alternate_name` VARCHAR(255) default "" NOT NULL AFTER `track`'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` ADD `parody` VARCHAR(255) default "" NOT NULL AFTER `alternate_name`'); mysql_query_safe('OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'); } if (isset($ExistingTableFields['comments_all']) && ($ExistingTableFields['comments_all']['Type'] != 'longtext')) { // Changed in 1.9.0 echo 'changing comments fields from text to longtext
'; // no need to change id3v1 mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_all` `comments_all` LONGTEXT NOT NULL'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_id3v2` `comments_id3v2` LONGTEXT NOT NULL'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_ape` `comments_ape` LONGTEXT NOT NULL'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `comments_lyrics3` `comments_lyrics3` LONGTEXT NOT NULL'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `warning` `warning` LONGTEXT NOT NULL'); mysql_query_safe('ALTER TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'` CHANGE `error` `error` LONGTEXT NOT NULL'); } function SynchronizeAllTags($filename, $synchronizefrom = 'all', $synchronizeto = 'A12', &$errors) { global $getID3; set_time_limit(30); $ThisFileInfo = $getID3->analyze($filename); getid3_lib::CopyTagsToComments($ThisFileInfo); if ($synchronizefrom == 'all') { $SourceArray = (!empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : []); } elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) { $SourceArray = (!empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : []); } else { die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist'); } $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($filename).'")'; mysql_query_safe($SQLquery); $TagFormatsToWrite = []; 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 = ['', '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 from `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` = "")'; mysql_query_safe($SQLquery); $FilesInDir = []; 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`error` <> "")'; $SQLquery .= ' OR (`warning` <> "")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); while ($row = mysql_fetch_array($result)) { if (!file_exists($row['filename'])) { echo 'File missing: '.$row['filename'].'
'; $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; mysql_query_safe($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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' GROUP BY `filename`'; $SQLquery .= ' HAVING (`num` > 1)'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); $DupesDeleted = 0; while ($row = mysql_fetch_array($result)) { set_time_limit(30); $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE `filename` LIKE "'.mysql_real_escape_string($row['filename']).'"'; mysql_query_safe($SQLquery); $DupesDeleted++; } if ($DupesDeleted > 0) { echo 'Deleted '.number_format($DupesDeleted).' duplicate filenames
'; } if (!empty($_REQUEST['newscan'])) { $AlreadyInDatabase = []; set_time_limit(60); $SQLquery = 'SELECT `filename`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); while ($row = mysql_fetch_array($result)) { //$AlreadyInDatabase[] = strtolower($row['filename']); $AlreadyInDatabase[] = $row['filename']; } } $DirectoriesToScan = [!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan']]; $DirectoriesScanned = []; 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_lib::CopyTagsToComments($ThisFileInfo); if (file_exists($filename)) { $ThisFileInfo['file_modified_time'] = filemtime($filename); $ThisFileInfo['md5_file'] = ($getid3_demo_mysql_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'])) { foreach ($ThisFileInfo['comments']['track'] 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 = ['()', '[]', '{}']; 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'` SET '; $SQLquery .= ' `last_modified` = "'. mysql_real_escape_string(!empty($ThisFileInfo['file_modified_time']) ? $ThisFileInfo['file_modified_time'] : '').'"'; $SQLquery .= ', `md5_file` = "'. mysql_real_escape_string(!empty($ThisFileInfo['md5_file']) ? $ThisFileInfo['md5_file'] : '').'"'; $SQLquery .= ', `md5_data` = "'. mysql_real_escape_string(!empty($ThisFileInfo['md5_data']) ? $ThisFileInfo['md5_data'] : '').'"'; $SQLquery .= ', `md5_data_source` = "'. mysql_real_escape_string(!empty($ThisFileInfo['md5_data_source']) ? $ThisFileInfo['md5_data_source'] : '').'"'; $SQLquery .= ', `filesize` = "'. mysql_real_escape_string(!empty($ThisFileInfo['filesize']) ? $ThisFileInfo['filesize'] : 0).'"'; $SQLquery .= ', `fileformat` = "'. mysql_real_escape_string(!empty($ThisFileInfo['fileformat']) ? $ThisFileInfo['fileformat'] : '').'"'; $SQLquery .= ', `audio_dataformat` = "'.mysql_real_escape_string(!empty($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; $SQLquery .= ', `video_dataformat` = "'.mysql_real_escape_string(!empty($ThisFileInfo['video']['dataformat']) ? $ThisFileInfo['video']['dataformat'] : '').'"'; $SQLquery .= ', `vbr_method` = "'. mysql_real_escape_string(!empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '').'"'; $SQLquery .= ', `audio_bitrate` = "'. mysql_real_escape_string(!empty($ThisFileInfo['audio']['bitrate']) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; $SQLquery .= ', `video_bitrate` = "'. mysql_real_escape_string(!empty($ThisFileInfo['video']['bitrate']) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; $SQLquery .= ', `playtime_seconds` = "'.mysql_real_escape_string(!empty($ThisFileInfo['playtime_seconds']) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; $SQLquery .= ', `track_volume` = "'. mysql_real_escape_string(!empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; $SQLquery .= ', `comments_all` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']) ? serialize($ThisFileInfo['comments']) : '').'"'; $SQLquery .= ', `comments_id3v2` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v2']) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; $SQLquery .= ', `comments_ape` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']['ape']) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; $SQLquery .= ', `comments_lyrics3` = "'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['lyrics3']) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; $SQLquery .= ', `comments_id3v1` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v1']) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; $SQLquery .= ', `warning` = "'. mysql_real_escape_string(!empty($ThisFileInfo['warning']) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; $SQLquery .= ', `error` = "'. mysql_real_escape_string(!empty($ThisFileInfo['error']) ? implode("\t", $ThisFileInfo['error']) : '').'"'; $SQLquery .= ', `album` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['album']) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; $SQLquery .= ', `genre` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['genre']) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; $SQLquery .= ', `comment` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['comment']) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; $SQLquery .= ', `artist` = "'. mysql_real_escape_string(!empty($ThisFileInfo['comments']['artist']) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; $SQLquery .= ', `tags` = "'. mysql_real_escape_string(!empty($ThisFileInfo['tags']) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; $SQLquery .= ', `encoder_options` = "'. mysql_real_escape_string(trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; $SQLquery .= ', `title` = "'. mysql_real_escape_string($this_track_title).'"'; $SQLquery .= ', `remix` = "'. mysql_real_escape_string($this_track_remix).'"'; $SQLquery .= ', `track` = "'. mysql_real_escape_string($this_track_track).'"'; $SQLquery .= 'WHERE (`filename` = "'. mysql_real_escape_string(isset($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'")'; } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { //$SQLquery = 'INSERT INTO `'.mysql_real_escape_string(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`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `encoder_options`, `vbr_method`, `track_volume`) VALUES ('; $SQLquery = 'INSERT INTO `'.mysql_real_escape_string(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`, `encoder_options`, `vbr_method`, `track_volume`) VALUES ('; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['file_modified_time']) ? $ThisFileInfo['file_modified_time'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['md5_file']) ? $ThisFileInfo['md5_file'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['md5_data']) ? $ThisFileInfo['md5_data'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['md5_data_source']) ? $ThisFileInfo['md5_data_source'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['filesize']) ? $ThisFileInfo['filesize'] : 0).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['fileformat']) ? $ThisFileInfo['fileformat'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['audio']['dataformat']) ? $ThisFileInfo['audio']['dataformat'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['video']['dataformat']) ? $ThisFileInfo['video']['dataformat'] : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['audio']['bitrate']) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['video']['bitrate']) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['playtime_seconds']) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'", '; //$SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags'] ) ? implode("\t", $ThisFileInfo['tags']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['artist']) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string($this_track_title).'", '; $SQLquery .= '"'.mysql_real_escape_string($this_track_remix).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['album']) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['genre']) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']['comment']) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string($this_track_track).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['comments']) ? serialize($ThisFileInfo['comments']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v2']) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['ape']) ? serialize($ThisFileInfo['tags']['ape']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['lyrics3']) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['tags']['id3v1']) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['warning']) ? implode("\t", $ThisFileInfo['warning']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['error']) ? implode("\t", $ThisFileInfo['error']) : '').'", '; $SQLquery .= '"'.mysql_real_escape_string(trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : (!empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '')).'", '; $SQLquery .= '"'.mysql_real_escape_string(!empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'")'; } flush(); mysql_query_safe($SQLquery); } } $SQLquery = 'OPTIMIZE TABLE `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; mysql_query_safe($SQLquery); echo '
Done scanning!
'; } elseif (!empty($_REQUEST['missingtrackvolume'])) { $MissingTrackVolumeFilesScanned = 0; $MissingTrackVolumeFilesAdjusted = 0; $MissingTrackVolumeFilesDeleted = 0; $SQLquery = 'SELECT `filename`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`track_volume` = 0)'; $SQLquery .= ' AND (`audio_bitrate` > 0)'; $result = mysql_query_safe($SQLquery); echo 'Scanning 0 / '.number_format(mysql_num_rows($result)).' files for track volume information:
'; while ($row = mysql_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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"'; $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; mysql_query_safe($SQLquery); } } else { $MissingTrackVolumeFilesDeleted++; $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; mysql_query_safe($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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' GROUP BY `filename`'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); $DupesDeleted = 0; while ($row = mysql_fetch_array($result)) { set_time_limit(30); if ($row['num'] <= 1) { break; } echo '
'.htmlentities($row['filename']).' (duplicate)'; $SQLquery = 'DELETE FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE `filename` LIKE "'.mysql_real_escape_string($row['filename']).'"'; mysql_query_safe($SQLquery); $DupesDeleted++; } if ($DupesDeleted > 0) { echo '
Deleted '.number_format($DupesDeleted).' duplicate filenames
'; } $SQLquery = 'SELECT `filename`, `filesize`, `last_modified`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); $totalchecked = 0; $totalremoved = 0; $previousdir = ''; while ($row = mysql_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 FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`filename` = "'.mysql_real_escape_string($row['filename']).'")'; mysql_query_safe($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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`encoder_options` = "'.mysql_real_escape_string($_REQUEST['encodedbydistribution']).'")'; $result = mysql_query_safe($SQLquery); $NonBlankEncodedBy = ''; $BlankEncodedBy = ''; while ($row = mysql_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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $result = mysql_query_safe($SQLquery); while ($row = mysql_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 ''; echo ''; } } echo '
m3u'.htmlentities($row['filename']).'
'; } else { $SQLquery = 'SELECT `encoder_options`, `comments_id3v2`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC'; $result = mysql_query_safe($SQLquery); $EncodedBy = []; while ($row = mysql_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 ''; foreach ($EncodedBy as $key => $value) { echo ''; echo ''; echo ''; } echo '
m3uEncoder OptionsEncoded By (ID3v2)
m3u'.$key.''; arsort($value); foreach ($value as $string => $count) { echo ''; echo ''; } echo '
'.number_format($count).' '.$string.'
'; } } elseif (!empty($_REQUEST['audiobitrates'])) { getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); $BitrateDistribution = []; $SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`audio_bitrate` > 0)'; $SQLquery .= ' GROUP BY `RoundBitrate`'; $result = mysql_query_safe($SQLquery); while ($row = mysql_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 ''; foreach ($BitrateDistribution as $Bitrate => $Count) { echo ''; echo ''; echo ''; echo ''; } echo '
BitrateCount
'.round($Bitrate / 1000).' kbps'.number_format($Count).'
'; } elseif (!empty($_REQUEST['emptygenres'])) { $SQLquery = 'SELECT `fileformat`, `filename`, `genre`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`genre` = "")'; $SQLquery .= ' OR (`genre` = "Unknown")'; $SQLquery .= ' OR (`genre` = "Other")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } } exit; } else { echo '.m3u version
'; $EmptyGenreCounter = 0; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { $EmptyGenreCounter++; echo ''; echo ''; echo ''; echo ''; } } echo '
m3ufilename
m3u'.htmlentities($row['filename']).'
'; echo ''.number_format($EmptyGenreCounter).' files with empty genres'; } } elseif (!empty($_REQUEST['nonemptycomments'])) { $SQLquery = 'SELECT `filename`, `comment`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`comment` <> "")'; $SQLquery .= ' ORDER BY `comment` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { $NonEmptyCommentsCounter = 0; echo '.m3u version
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { $NonEmptyCommentsCounter++; echo ''; echo ''; echo ''; if (strlen(trim($row['comment'])) > 0) { echo ''; } else { echo ''; } echo ''; } echo '
m3ufilenamecomments
m3u'.htmlentities($row['filename']).''.htmlentities($row['comment']).'space
'; echo ''.number_format($NonEmptyCommentsCounter).' files with non-empty comments'; } } elseif (!empty($_REQUEST['trackzero'])) { $SQLquery = 'SELECT `filename`, `track`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`track` <> "")'; $SQLquery .= ' AND ((`track` < "1")'; $SQLquery .= ' OR (`track` > "99"))'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } } exit; } else { echo '.m3u version
'; $TrackZeroCounter = 0; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { $TrackZeroCounter++; echo ''; echo ''; echo ''; echo ''; echo ''; } } echo '
m3ufilenametrack
m3u'.htmlentities($row['filename']).''.htmlentities($row['track']).'
'; echo ''.number_format($TrackZeroCounter).' files with track "zero"'; } } elseif (!empty($_REQUEST['titlefeat'])) { $SQLquery = 'SELECT `filename`, `title`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`title` LIKE "%feat.%")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { echo ''.number_format(mysql_num_rows($result)).' files with "feat." in the title (instead of the artist)

'; echo '.m3u version
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
m3ufilenametitle
m3u'.htmlentities($row['filename']).''.preg_replace('#(feat\. .*)#i', '\\1', htmlentities($row['title'])).'
'; } } elseif (!empty($_REQUEST['tracknoalbum'])) { $SQLquery = 'SELECT `filename`, `track`, `album`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`track` <> "")'; $SQLquery .= ' AND (`album` = "")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { echo ''.number_format(mysql_num_rows($result)).' files with a track number, but no album

'; echo '.m3u version
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
m3ufilenametrackalbum
m3u'.htmlentities($row['filename']).''.htmlentities($row['track']).''.htmlentities($row['album']).'
'; } } elseif (!empty($_REQUEST['synchronizetagsfrom']) && !empty($_REQUEST['filename'])) { echo 'Applying new tags from '.$_REQUEST['synchronizetagsfrom'].' in '.htmlentities($_REQUEST['filename']).'
    '; $errors = []; if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) { echo '
  • Sucessfully wrote tags
  • '; } else { echo '
  • Tag writing had errors:
    • '.implode('
    • ', $errors).'
  • '; } echo '
'; } elseif (!empty($_REQUEST['unsynchronizedtags'])) { $NotOKfiles = 0; $Autofixedfiles = 0; $FieldsToCompare = ['title', 'artist', 'album', 'year', 'genre', 'comment', 'track']; $TagsToCompare = ['id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false]; $ID3v1FieldLengths = ['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 ''; echo ''; echo ''; if ($TagsToCompare['id3v2']) { echo ''; } if ($TagsToCompare['ape']) { echo ''; } if ($TagsToCompare['lyrics3']) { echo ''; } if ($TagsToCompare['id3v1']) { echo ''; } echo ''; $SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` = "mp3")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); $lastdir = ''; $serializedCommentsFields = ['all', 'id3v2', 'ape', 'lyrics3', 'id3v1']; while ($row = mysql_fetch_array($result)) { set_time_limit(30); if ($lastdir != dirname($row['filename'])) { echo ''; flush(); } $FileOK = true; $Mismatched = ['id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false]; $SemiMatched = ['id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false]; $EmptyTags = ['id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true]; foreach ($serializedCommentsFields as $field) { $Comments[$field] = []; 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'] = $Comments['ape']['tracknumber']; unset($Comments['ape']['tracknumber']); } if (isset($Comments['ape']['track_number'])) { $Comments['ape']['track'] = $Comments['ape']['track_number']; unset($Comments['ape']['track_number']); } if (isset($Comments['id3v2']['track_number'])) { $Comments['id3v2']['track'] = $Comments['id3v2']['track_number']; unset($Comments['id3v2']['track_number']); } if (!empty($Comments['all']['track'])) { $besttrack = ''; foreach ($Comments['all']['track'] as $key => $value) { if (strlen($value) > strlen($besttrack)) { $besttrack = $value; } } $Comments['all']['track'] = [0=>$besttrack]; } $ThisLine = ''; $ThisLine .= ''; $ThisLine .= ''; $tagvalues = ''; foreach ($FieldsToCompare as $fieldname) { $tagvalues .= $fieldname.' = '.(!empty($Comments['all'][$fieldname]) ? implode(" \n", $Comments['all'][$fieldname]) : '')." \n"; } $ThisLine .= ''; 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') { // 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 .= ''; } } $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 = []; if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) { $Autofixedfiles++; echo ''; } else { echo ''; } echo ''; echo ''; } } else { echo $ThisLine; } } } echo '
ViewFilenameCombinedID3v2APELyrics3ID3v1
view'.htmlentities($row['filename']).'all'; } elseif ($SemiMatched[$tagtype]) { $ThisLine .= ''; } elseif ($Mismatched[$tagtype]) { $ThisLine .= ''; } else { $ThisLine .= ''; } $ThisLine .= ''.$tagtype.''; $ThisLine .= '
 '; echo ''.htmlentities($row['filename']).''; echo ''; echo '
'.$TagsToSynch.'

'; 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); echo 'Files that do not match naming pattern: (auto-fix)
'; echo ''; echo ''; $nonmatchingfilenames = 0; $Pattern = $_REQUEST['filenamepattern']; $PatternLength = strlen($Pattern); while ($row = mysql_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 = ['()', '[]', '{}']; 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 ''; echo ''; echo ''; if (!empty($_REQUEST['autofix'])) { $results = ''; if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) { echo ''; } else { echo ''; } echo ''; $nonmatchingfilenames++; } } echo '
viewWhyActual filename
(click to play/edit file)
Correct filename (based on tags)'.(empty($_REQUEST['autofix']) ? '
(click to rename file to this)' : '').'
view '.$NotMatchedReasons.''.htmlentities($ActualFilename).''; } else { echo ''; } echo ''.$DifferenceBoldedName.''; echo ''.$DifferenceBoldedName.'

'; 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysql_real_escape_string($_REQUEST['showtagfiles']).'")'; $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { echo 'Show all Encoder Options
'; echo 'Files with Encoder Options '.$_REQUEST['showtagfiles'].':
'; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; } echo '
'.htmlentities($row['filename']).''.$row['encoder_options'].'
'; } } elseif (!isset($_REQUEST['m3u'])) { $SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.mysql_real_escape_string(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 = mysql_query_safe($SQLquery); echo 'Files with Encoder Options:
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
Encoder OptionsCountM3U
'.$row['encoder_options'].''.number_format($row['num']).'m3u

'; } } elseif (!empty($_REQUEST['tagtypes'])) { if (!isset($_REQUEST['m3u'])) { $SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; $SQLquery .= ' GROUP BY `tags`'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); echo 'Files with tags:
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
TagsCountM3U
'.$row['tags'].''.number_format($row['num']).'m3u

'; } if (isset($_REQUEST['showtagfiles'])) { $SQLquery = 'SELECT `filename`, `tags` FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`tags` LIKE "'.mysql_real_escape_string($_REQUEST['showtagfiles']).'")'; $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; } echo '
'.htmlentities($row['filename']).''.$row['tags'].'
'; } } } elseif (!empty($_REQUEST['md5datadupes'])) { $OtherFormats = ''; $AVFormats = ''; $SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`md5_data` <> "")'; $SQLquery .= ' GROUP BY `md5_data`'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { set_time_limit(30); $filenames = []; $tags = []; $md5_data = []; $SQLquery = 'SELECT `fileformat`, `filename`, `tags`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`md5_data` = "'.mysql_real_escape_string($row['md5_data']).'")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result2 = mysql_query_safe($SQLquery); while ($row2 = mysql_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 $AVFormats.'

'; echo 'Duplicated MD5_DATA (Other files):'; echo $OtherFormats.'

'; } 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($_REQUEST['m3uartist']).'")'; $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($_REQUEST['m3utitle']).'")'; $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; $result = mysql_query_safe($SQLquery); while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } $SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(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 = mysql_query_safe($SQLquery); $uniquetitles = 0; $uniquefiles = 0; if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { $SQLquery = 'SELECT `filename`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($row['artist']).'")'; $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($row['title']).'")'; if (!empty($_REQUEST['samemix'])) { $SQLquery .= ' AND (`remix` = "'.mysql_real_escape_string($row['remix']).'")'; } $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; $result2 = mysql_query_safe($SQLquery); while ($row2 = mysql_fetch_array($result2)) { echo WindowsShareSlashTranslate($row2['filename'])."\n"; } } exit; } else { echo 'Duplicated aritst + title: (Identical Mix/Version only)
'; echo '(.m3u version)
'; echo ''; echo ''; while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { $uniquetitles++; set_time_limit(30); $filenames = []; $artists = []; $titles = []; $remixes = []; $bitrates = []; $playtimes = []; $SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`artist` = "'.mysql_real_escape_string($row['artist']).'")'; $SQLquery .= ' AND (`title` = "'.mysql_real_escape_string($row['title']).'")'; $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; $result2 = mysql_query_safe($SQLquery); while ($row2 = mysql_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 ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } } echo '
 ArtistTitleVersion  Filename
'; foreach ($filenames as $file) { echo 'delete
'; } echo '
'; foreach ($filenames as $file) { echo 'play
'; } echo '
play all'.implode('
', $artists).'
'.implode('
', $titles).'
'.implode('
', $remixes).'
'.implode('
', $bitrates).'
'.implode('
', $playtimes).'
'; foreach ($filenames as $file) { echo ''; } echo '
'.dirname($file).'/'.basename($file).'
'; 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` = "'.mysql_real_escape_string($fileformat).'")'; $SQLquery .= ' AND (`audio_dataformat` = "'.mysql_real_escape_string($audioformat).'")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); echo 'Files of format '.$fileformat.'.'.$audioformat.':'; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
fileaudiofilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.htmlentities($row['filename']).'

'; } elseif (!empty($_REQUEST['trackinalbum'])) { $SQLquery = 'SELECT `filename`, `album`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`album` LIKE "% [%")'; $SQLquery .= ' ORDER BY `album` ASC, `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_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 = mysql_fetch_array($result)) { set_time_limit(30); $ThisFileInfo = $getID3->analyze($filename); getid3_lib::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(mysql_num_rows($result)).' files with [??]-format track numbers in album field:
'; if (mysql_num_rows($result) > 0) { echo '(.m3u version)
'; echo 'Try to auto-fix
'; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; } echo '
'.$row['album'].''.htmlentities($row['filename']).'
'; } echo '
'; } } elseif (!empty($_REQUEST['fileextensions'])) { $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); $invalidextensionfiles = 0; $invalidextensionline = ''; $invalidextensionline .= ''; while ($row = mysql_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 .= ''; $invalidextensionline .= ''; $invalidextensionline .= ''; $invalidextensionline .= ''; $invalidextensionline .= ''; $invalidextensionline .= ''; $invalidextensionline .= ''; $invalidextensionline .= ''; } } $invalidextensionline .= '
fileaudiovideotagsactualcorrectfilename
'.$row['fileformat'].''.$row['audio_dataformat'].''.$row['video_dataformat'].''.$row['tags'].''.$actualextension.''.implode('; ', $acceptableextensions).''.htmlentities($row['filename']).'

'; 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 `'.mysql_real_escape_string(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 = mysql_query_safe($SQLquery); while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { if ($_REQUEST['genredistribution'] == '%') { $SQLquery = 'SELECT COUNT(*) AS `num`, `genre`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; $SQLquery .= ' GROUP BY `genre`'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); echo ''; echo ''; while ($row = mysql_fetch_array($result)) { $GenreID = getid3_id3v1::LookupGenreID($row['genre']); if (is_numeric($GenreID)) { echo ''; } else { echo ''; } echo ''; echo ''; echo ''; echo ''; } echo '
CountGenrem3u
'.number_format($row['num']).''.str_replace("\t", '
', $row['genre']).'
.m3u

'; } else { $SQLquery = 'SELECT `filename`, `genre`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`genre` LIKE "'.mysql_real_escape_string($_REQUEST['genredistribution']).'")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); echo 'All Genres
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
Genrem3uFilename
'.str_replace("\t", '
', $row['genre']).'
m3u'.htmlentities($row['filename']).'

'; } } } elseif (!empty($_REQUEST['formatdistribution'])) { $SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`'; $SQLquery .= ' ORDER BY `num` DESC'; $result = mysql_query_safe($SQLquery); echo 'File format distribution:'; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; } echo '
NumberFormat
'.number_format($row['num']).''.($row['fileformat'] ? $row['fileformat'] : 'unknown').(($row['audio_dataformat'] && ($row['audio_dataformat'] != $row['fileformat'])) ? '.'.$row['audio_dataformat'] : '').'

'; } elseif (!empty($_REQUEST['errorswarnings'])) { $SQLquery = 'SELECT `filename`, `error`, `warning`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`error` <> "")'; $SQLquery .= ' OR (`warning` <> "")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); if (!empty($_REQUEST['m3u'])) { header('Content-type: audio/x-mpegurl'); echo '#EXTM3U'."\n"; while ($row = mysql_fetch_array($result)) { echo WindowsShareSlashTranslate($row['filename'])."\n"; } exit; } else { echo number_format(mysql_num_rows($result)).' files with errors or warnings:
'; echo '(.m3u version)
'; echo ''; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; echo ''; echo ''; echo ''; } } echo '
FilenameErrorWarning
'.htmlentities($row['filename']).''.(!empty($row['error']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['error'])).'
  • ' : ' ').'
    '.(!empty($row['warning']) ? '
  • '.str_replace("\t", '
  • ', htmlentities($row['warning'])).'
  • ' : ' ').'

    '; } 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` = "mp3")'; $SQLquery .= ' AND (`warning` <> "")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($SQLquery); $totaltofix = mysql_num_rows($result); $rowcounter = 0; while ($row = mysql_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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' GROUP BY `vbr_method`'; $SQLquery .= ' ORDER BY `vbr_method`'; $result = mysql_query_safe($SQLquery); echo 'VBR methods:'; echo ''; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; if ($row['vbr_method']) { echo ''; } else { echo ''; } echo ''; } echo '
    CountVBR Method
    '.htmlentities(number_format($row['num'])).''.htmlentities($row['vbr_method']).'CBR
    '; } else { $SQLquery = 'SELECT `filename`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`vbr_method` = "'.mysql_real_escape_string($_REQUEST['vbrmethod']).'")'; $result = mysql_query_safe($SQLquery); echo number_format(mysql_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":'; while ($row = mysql_fetch_array($result)) { echo ''; echo ''; } echo '
    m3u'.htmlentities($row['filename']).'
    '; } echo '
    '; } elseif (!empty($_REQUEST['correctcase'])) { $SQLquery = 'SELECT `filename`, `fileformat`'; $SQLquery .= ' FROM `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $SQLquery .= ' WHERE (`fileformat` <> "")'; $SQLquery .= ' ORDER BY `filename` ASC'; $result = mysql_query_safe($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 = mysql_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 = ['vs.', 'feat.']; static $UpperCaseWords = ['DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\'']; $OutputListOfWords = []; $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 'Warning: Scanning a new directory will erase all previous entries in the database!
    '; echo 'Directory: '; echo ''; echo '
    '; echo '
    '; echo 'Re-scanning a new directory will only add new, previously unscanned files into the list (and not erase the database).
    '; echo 'Directory: '; 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 `'.mysql_real_escape_string(GETID3_DB_TABLE).'`'; $result = mysql_query_safe($SQLquery); if ($row = mysql_fetch_array($result)) { echo '
    '; echo '
    '; echo 'Spent '.number_format(mysql_query_safe(null), 3).' seconds querying the database
    '; echo '
    '; echo 'Currently in the database:'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
    Total Files'.number_format($row['TotalFiles']).'
    Total Filesize'.number_format($row['TotalFilesize'] / 1048576).' MB
    Total Playtime'.number_format($row['TotalPlaytime'] / 3600, 1).' hours
    Average Filesize'.number_format($row['AvgFilesize'] / 1048576, 1).' MB
    Average Playtime'.getid3_lib::PlaytimeString($row['AvgPlaytime']).'
    Average Bitrate'.BitrateText($row['AvgBitrate'] / 1000, 1).'
    '; echo '
    '; } echo '';