// // 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 = 'UTF-8'; $getid3_demo_mysqli_md5_data = false; // All data hashes are by far the slowest part of scanning $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(); $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, )); 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
'.htmlentities($SQLquery).'
m3u | '; echo ''.htmlentities($row['filename']).' |
m3u | Encoder Options | Encoded By (ID3v2) | |||
---|---|---|---|---|---|
m3u | '; echo ''.$key.' | '; echo '
|
Bitrate | Count |
---|---|
'.round($Bitrate / 1000).' kbps | '; echo ''.number_format($Count).' | '; echo '
m3u | filename |
---|---|
m3u | '; echo ''.htmlentities($row['filename']).' | '; echo '
m3u | filename | comments | |
---|---|---|---|
m3u | '; echo ''.htmlentities($row['filename']).' | '; if (strlen(trim($row['comment'])) > 0) { echo ''.htmlentities($row['comment']).' | '; } else { echo 'space | '; } echo '
m3u | filename | track |
---|---|---|
m3u | '; echo ''.htmlentities($row['filename']).' | '; echo ''.htmlentities($row['track_number']).' | '; echo '
m3u | filename | title |
---|---|---|
m3u | '; echo ''.htmlentities($row['filename']).' | '; echo ''.preg_replace('#(feat\. .*)#i', '\\1', htmlentities($row['title'])).' | '; echo '
m3u | filename | track | album |
---|---|---|---|
m3u | '; echo ''.htmlentities($row['filename']).' | '; echo ''.htmlentities($row['track_number']).' | '; echo ''.htmlentities($row['album']).' | '; 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 '
---|---|---|---|---|---|---|
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 .= '
'; echo ' | '.htmlentities($row['filename']).' | '; echo '
|
view | Why | Actual filename (click to play/edit file) | Correct filename (based on tags)'.(empty($_REQUEST['autofix']) ? ' (click to rename file to this)' : '').' | ||
---|---|---|---|---|---|
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 '
'.htmlentities($row['filename']).' | '; echo ''.$row['encoder_options'].' | '; echo '
Encoder Options | Count | M3U |
---|---|---|
'.$row['encoder_options'].' | '; echo ''.number_format($row['num']).' | '; echo 'm3u | '; echo '
Tags | Count | M3U |
---|---|---|
'.$row['tags'].' | '; echo ''.number_format($row['num']).' | '; echo 'm3u | '; echo '
'.htmlentities($row['filename']).' | '; echo ''.$row['tags'].' | '; echo '
Artist | Title | Version | Filename | ||||||
---|---|---|---|---|---|---|---|---|---|
';
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 '
file | audio | filename |
---|---|---|
'.$row['fileformat'].' | '; echo ''.$row['audio_dataformat'].' | '; echo ''.htmlentities($row['filename']).' | '; echo '
'.$row['album'].' | '; echo ''.htmlentities($row['filename']).' | '; echo '
file | audio | video | tags | actual | correct | filename |
---|---|---|---|---|---|---|
'.$row['fileformat'].' | '; $invalidextensionline .= ''.$row['audio_dataformat'].' | '; $invalidextensionline .= ''.$row['video_dataformat'].' | '; $invalidextensionline .= ''.$row['tags'].' | '; $invalidextensionline .= ''.$actualextension.' | '; $invalidextensionline .= ''.implode('; ', $acceptableextensions).' | '; $invalidextensionline .= ''.htmlentities($row['filename']).' | '; $invalidextensionline .= '
Count | Genre | m3u |
---|---|---|
'.number_format($row['num']).' | '; echo ''.str_replace("\t", ' ', $row['genre']).' | ';
echo '.m3u | '; echo '
Genre | m3u | Filename |
---|---|---|
'.str_replace("\t", ' ', $row['genre']).' | ';
echo 'm3u | '; echo ''.htmlentities($row['filename']).' | '; echo '
Number | Format |
---|---|
'.number_format($row['num']).' | '; echo ''.($row['fileformat'] ? $row['fileformat'] : 'unknown').(($row['audio_dataformat'] && ($row['audio_dataformat'] != $row['fileformat'])) ? '.'.$row['audio_dataformat'] : '').' | '; echo '
Filename | Error | Warning |
---|---|---|
'.htmlentities($row['filename']).' | '; echo ''.(!empty($row['error']) ? ' | ';
echo ''.(!empty($row['warning']) ? ' | ';
echo '
Count | VBR Method | |
---|---|---|
'.htmlentities(number_format($row['num'])).' | '; if ($row['vbr_method']) { echo ''.htmlentities($row['vbr_method']).' | '; } else { echo 'CBR | '; } echo '
m3u | '; echo ''.htmlentities($row['filename']).' |
'; $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 '
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).' |