diff options
| author | Max Kremmel <xing@synapse.plus.com> | 2008-05-22 07:19:03 +0000 |
|---|---|---|
| committer | Max Kremmel <xing@synapse.plus.com> | 2008-05-22 07:19:03 +0000 |
| commit | 69e65f63d2a31c0b03df0cb5006b03c8f93f4b31 (patch) | |
| tree | 28827cad2af671d24d54e4fa8951c1c3b970ca3b /getid3/demos | |
| parent | 2f4451862589acfe9e93bfee4f8a0f261c82643c (diff) | |
| download | util-69e65f63d2a31c0b03df0cb5006b03c8f93f4b31.tar.gz util-69e65f63d2a31c0b03df0cb5006b03c8f93f4b31.tar.bz2 util-69e65f63d2a31c0b03df0cb5006b03c8f93f4b31.zip | |
add getID3 to our set of utilities. great tool for extracting meta data from various filetypes such as audio, video, image...
Diffstat (limited to 'getid3/demos')
| -rw-r--r-- | getid3/demos/demo.audioinfo.class.php | 319 | ||||
| -rw-r--r-- | getid3/demos/demo.basic.php | 38 | ||||
| -rw-r--r-- | getid3/demos/demo.browse.php | 669 | ||||
| -rw-r--r-- | getid3/demos/demo.cache.dbm.php | 29 | ||||
| -rw-r--r-- | getid3/demos/demo.cache.mysql.php | 29 | ||||
| -rw-r--r-- | getid3/demos/demo.joinmp3.php | 96 | ||||
| -rw-r--r-- | getid3/demos/demo.mimeonly.php | 53 | ||||
| -rw-r--r-- | getid3/demos/demo.mysql.php | 2130 | ||||
| -rw-r--r-- | getid3/demos/demo.simple.php | 53 | ||||
| -rw-r--r-- | getid3/demos/demo.simple.write.php | 54 | ||||
| -rw-r--r-- | getid3/demos/demo.write.php | 267 | ||||
| -rw-r--r-- | getid3/demos/index.php | 1 |
12 files changed, 3738 insertions, 0 deletions
diff --git a/getid3/demos/demo.audioinfo.class.php b/getid3/demos/demo.audioinfo.class.php new file mode 100644 index 0000000..d38ec19 --- /dev/null +++ b/getid3/demos/demo.audioinfo.class.php @@ -0,0 +1,319 @@ +<?php + +// +----------------------------------------------------------------------+ +// | PHP version 4.1.0 | +// +----------------------------------------------------------------------+ +// | Placed in public domain by Allan Hansen, 2002. Share and enjoy! | +// +----------------------------------------------------------------------+ +// | /demo/demo.audioinfo.class.php | +// | | +// | Example wrapper class to extract information from audio files | +// | through getID3(). | +// | | +// | getID3() returns a lot of information. Much of this information is | +// | not needed for the end-application. It is also possible that some | +// | users want to extract specific info. Modifying getID3() files is a | +// | bad idea, as modifications needs to be done to future versions of | +// | getID3(). | +// | | +// | Modify this wrapper class instead. This example extracts certain | +// | fields only and adds a new root value - encoder_options if possible. | +// | It also checks for mp3 files with wave headers. | +// +----------------------------------------------------------------------+ +// | Example code: | +// | $au = new AudioInfo(); | +// | print_r($au->Info('file.flac'); | +// +----------------------------------------------------------------------+ +// | Authors: Allan Hansen <ahØartemis*dk> | +// +----------------------------------------------------------------------+ +// + + + +/** +* getID3() settings +*/ + +require_once('../getid3/getid3.php'); + + + + +/** +* Class for extracting information from audio files with getID3(). +*/ + +class AudioInfo { + + /** + * Private variables + */ + var $result = NULL; + var $info = NULL; + + + + + /** + * Constructor + */ + + function AudioInfo() { + + // Initialize getID3 engine + $this->getID3 = new getID3; + $this->getID3->option_md5_data = true; + $this->getID3->option_md5_data_source = true; + $this->getID3->encoding = 'UTF-8'; + } + + + + + /** + * Extract information - only public function + * + * @access public + * @param string file Audio file to extract info from. + */ + + function Info($file) { + + // Analyze file + $this->info = $this->getID3->analyze($file); + + // Exit here on error + if (isset($this->info['error'])) { + return array ('error' => $this->info['error']); + } + + // Init wrapper object + $this->result = array (); + $this->result['format_name'] = @$this->info['fileformat'].'/'.@$this->info['audio']['dataformat'].(isset($this->info['video']['dataformat']) ? '/'.@$this->info['video']['dataformat'] : ''); + $this->result['encoder_version'] = @$this->info['audio']['encoder']; + $this->result['encoder_options'] = @$this->info['audio']['encoder_options']; + $this->result['bitrate_mode'] = @$this->info['audio']['bitrate_mode']; + $this->result['channels'] = @$this->info['audio']['channels']; + $this->result['sample_rate'] = @$this->info['audio']['sample_rate']; + $this->result['bits_per_sample'] = @$this->info['audio']['bits_per_sample']; + $this->result['playing_time'] = @$this->info['playtime_seconds']; + $this->result['avg_bit_rate'] = @$this->info['audio']['bitrate']; + $this->result['tags'] = @$this->info['tags']; + $this->result['comments'] = @$this->info['comments']; + $this->result['warning'] = @$this->info['warning']; + $this->result['md5'] = @$this->info['md5_data']; + + // Post getID3() data handling based on file format + $method = @$this->info['fileformat'].'Info'; + if (@$this->info['fileformat'] && method_exists($this, $method)) { + $this->$method(); + } + + return $this->result; + } + + + + + /** + * post-getID3() data handling for AAC files. + * + * @access private + */ + + function aacInfo() { + $this->result['format_name'] = 'AAC'; + } + + + + + /** + * post-getID3() data handling for Wave files. + * + * @access private + */ + + function riffInfo() { + if ($this->info['audio']['dataformat'] == 'wav') { + + $this->result['format_name'] = 'Wave'; + + } else if (ereg('^mp[1-3]$', $this->info['audio']['dataformat'])) { + + $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); + + } else { + + $this->result['format_name'] = 'riff/'.$this->info['audio']['dataformat']; + + } + } + + + + + /** + * * post-getID3() data handling for FLAC files. + * + * @access private + */ + + function flacInfo() { + $this->result['format_name'] = 'FLAC'; + } + + + + + + /** + * post-getID3() data handling for Monkey's Audio files. + * + * @access private + */ + + function macInfo() { + $this->result['format_name'] = 'Monkey\'s Audio'; + } + + + + + + /** + * post-getID3() data handling for Lossless Audio files. + * + * @access private + */ + + function laInfo() { + $this->result['format_name'] = 'La'; + } + + + + + + /** + * post-getID3() data handling for Ogg Vorbis files. + * + * @access private + */ + + function oggInfo() { + if ($this->info['audio']['dataformat'] == 'vorbis') { + + $this->result['format_name'] = 'Ogg Vorbis'; + + } else if ($this->info['audio']['dataformat'] == 'flac') { + + $this->result['format_name'] = 'Ogg FLAC'; + + } else if ($this->info['audio']['dataformat'] == 'speex') { + + $this->result['format_name'] = 'Ogg Speex'; + + } else { + + $this->result['format_name'] = 'Ogg '.$this->info['audio']['dataformat']; + + } + } + + + + + /** + * post-getID3() data handling for Musepack files. + * + * @access private + */ + + function mpcInfo() { + $this->result['format_name'] = 'Musepack'; + } + + + + + /** + * post-getID3() data handling for MPEG files. + * + * @access private + */ + + function mp3Info() { + $this->result['format_name'] = 'MP3'; + } + + + + + /** + * post-getID3() data handling for MPEG files. + * + * @access private + */ + + function mp2Info() { + $this->result['format_name'] = 'MP2'; + } + + + + + + /** + * post-getID3() data handling for MPEG files. + * + * @access private + */ + + function mp1Info() { + $this->result['format_name'] = 'MP1'; + } + + + + + /** + * post-getID3() data handling for WMA files. + * + * @access private + */ + + function asfInfo() { + $this->result['format_name'] = strtoupper($this->info['audio']['dataformat']); + } + + + + /** + * post-getID3() data handling for Real files. + * + * @access private + */ + + function realInfo() { + $this->result['format_name'] = 'Real'; + } + + + + + + /** + * post-getID3() data handling for VQF files. + * + * @access private + */ + + function vqfInfo() { + $this->result['format_name'] = 'VQF'; + } + +} + + +?>
\ No newline at end of file diff --git a/getid3/demos/demo.basic.php b/getid3/demos/demo.basic.php new file mode 100644 index 0000000..ddd56e5 --- /dev/null +++ b/getid3/demos/demo.basic.php @@ -0,0 +1,38 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.basic.php - part of getID3() // +// Sample script showing most basic use of getID3() // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +// include getID3() library (can be in a different directory if full path is specified) +require_once('../getid3/getid3.php'); + +// Initialize getID3 engine +$getID3 = new getID3; + +// Analyze file and store returned data in $ThisFileInfo +$ThisFileInfo = $getID3->analyze($filename); + +// Optional: copies data from all subarrays of [tags] into [comments] so +// metadata is all available in one location for all tag formats +// metainformation is always available under [tags] even if this is not called +getid3_lib::CopyTagsToComments($ThisFileInfo); + +// Output desired information in whatever format you want +// Note: all entries in [comments] or [tags] are arrays of strings +// See structure.txt for information on what information is available where +// or check out the output of /demos/demo.browse.php for a particular file +// to see the full detail of what information is returned where in the array +echo @$ThisFileInfo['comments_html']['artist'][0]; // artist from any/all available tag formats +echo @$ThisFileInfo['tags']['id3v2']['title'][0]; // title from ID3v2 +echo @$ThisFileInfo['audio']['bitrate']; // audio bitrate +echo @$ThisFileInfo['playtime_string']; // playtime in minutes:seconds, formatted string + +?>
\ No newline at end of file diff --git a/getid3/demos/demo.browse.php b/getid3/demos/demo.browse.php new file mode 100644 index 0000000..6a9af4f --- /dev/null +++ b/getid3/demos/demo.browse.php @@ -0,0 +1,669 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.browse.php - part of getID3() // +// Sample script for browsing/scanning files and displaying // +// information returned by getID3() // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + + + +///////////////////////////////////////////////////////////////// +// set predefined variables as if magic_quotes_gpc was off, +// whether the server's got it or not: +UnifyMagicQuotes(false); +///////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////// +// showfile is used to display embedded images from table_var_dump() +// md5 of requested file is required to prevent abuse where any +// random file on the server could be viewed +if (@$_REQUEST['showfile']) { + if (is_readable($_REQUEST['showfile'])) { + if (md5_file($_REQUEST['showfile']) == @$_REQUEST['md5']) { + readfile($_REQUEST['showfile']); + exit; + } + } + die('Cannot display "'.$_REQUEST['showfile'].'"'); +} +///////////////////////////////////////////////////////////////// + + +if (!function_exists('getmicrotime')) { + function getmicrotime() { + list($usec, $sec) = explode(' ', microtime()); + return ((float) $usec + (float) $sec); + } +} + +/////////////////////////////////////////////////////////////////////////////// + + +$writescriptfilename = 'demo.write.php'; + +require_once('../getid3/getid3.php'); + +// Needed for windows only +define('GETID3_HELPERAPPSDIR', 'C:/helperapps/'); + +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array('encoding' => 'UTF-8')); + +$getID3checkColor_Head = 'CCCCDD'; +$getID3checkColor_DirectoryLight = 'FFCCCC'; +$getID3checkColor_DirectoryDark = 'EEBBBB'; +$getID3checkColor_FileLight = 'EEEEEE'; +$getID3checkColor_FileDark = 'DDDDDD'; +$getID3checkColor_UnknownLight = 'CCCCFF'; +$getID3checkColor_UnknownDark = 'BBBBDD'; + + +/////////////////////////////////////////////////////////////////////////////// + + +header('Content-Type: text/html; charset=UTF-8'); +ob_start(); +echo '<html><head>'; +echo '<title>getID3() - /demo/demo.browse.php (sample script)</title>'; +echo '<style>BODY,TD,TH { font-family: sans-serif; font-size: 9pt; }</style>'; +echo '</head><body>'; + +if (isset($_REQUEST['deletefile'])) { + if (file_exists($_REQUEST['deletefile'])) { + if (unlink($_REQUEST['deletefile'])) { + $deletefilemessage = 'Successfully deleted '.addslashes($_REQUEST['deletefile']); + } else { + $deletefilemessage = 'FAILED to delete '.addslashes($_REQUEST['deletefile']).' - error deleting file'; + } + } else { + $deletefilemessage = 'FAILED to delete '.addslashes($_REQUEST['deletefile']).' - file does not exist'; + } + if (isset($_REQUEST['noalert'])) { + echo '<b><font color="'.(($deletefilemessage{0} == 'F') ? '#FF0000' : '#008000').'">'.$deletefilemessage.'</font></b><hr>'; + } else { + echo '<script language="JavaScript">alert("'.$deletefilemessage.'");</script>'; + } +} + + +if (isset($_REQUEST['filename'])) { + + if (!file_exists($_REQUEST['filename'])) { + die(getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-8', $_REQUEST['filename'].' does not exist')); + } + $starttime = getmicrotime(); + $AutoGetHashes = (bool) (filesize($_REQUEST['filename']) < 52428800); // auto-get md5_data, md5_file, sha1_data, sha1_file if filesize < 50MB + + $getID3->setOption(array( + 'option_md5_data' => $AutoGetHashes, + 'option_sha1_data' => $AutoGetHashes, + )); + $ThisFileInfo = $getID3->analyze($_REQUEST['filename']); + if ($AutoGetHashes) { + $ThisFileInfo['md5_file'] = getid3_lib::md5_file($_REQUEST['filename']); + $ThisFileInfo['sha1_file'] = getid3_lib::sha1_file($_REQUEST['filename']); + } + + + getid3_lib::CopyTagsToComments($ThisFileInfo); + + $listdirectory = dirname(getid3_lib::SafeStripSlashes($_REQUEST['filename'])); + $listdirectory = realpath($listdirectory); // get rid of /../../ references + + if (GETID3_OS_ISWINDOWS) { + // this mostly just gives a consistant look to Windows and *nix filesystems + // (windows uses \ as directory seperator, *nix uses /) + $listdirectory = str_replace('\\', '/', $listdirectory.'/'); + } + + if (strstr($_REQUEST['filename'], 'http://') || strstr($_REQUEST['filename'], 'ftp://')) { + echo '<i>Cannot browse remote filesystems</i><br>'; + } else { + echo 'Browse: <a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'">'.getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-8', $listdirectory).'</a><br>'; + } + + echo table_var_dump($ThisFileInfo); + $endtime = getmicrotime(); + echo 'File parsed in '.number_format($endtime - $starttime, 3).' seconds.<br>'; + +} else { + + $listdirectory = (isset($_REQUEST['listdirectory']) ? getid3_lib::SafeStripSlashes($_REQUEST['listdirectory']) : '.'); + $listdirectory = realpath($listdirectory); // get rid of /../../ references + $currentfulldir = $listdirectory.'/'; + + if (GETID3_OS_ISWINDOWS) { + // this mostly just gives a consistant look to Windows and *nix filesystems + // (windows uses \ as directory seperator, *nix uses /) + $currentfulldir = str_replace('\\', '/', $listdirectory.'/'); + } + + if ($handle = @opendir($listdirectory)) { + + echo str_repeat(' ', 300); // IE buffers the first 300 or so chars, making this progressive display useless - fill the buffer with spaces + echo 'Processing'; + + $starttime = getmicrotime(); + + $TotalScannedUnknownFiles = 0; + $TotalScannedKnownFiles = 0; + $TotalScannedPlaytimeFiles = 0; + $TotalScannedBitrateFiles = 0; + $TotalScannedFilesize = 0; + $TotalScannedPlaytime = 0; + $TotalScannedBitrate = 0; + $FilesWithWarnings = 0; + $FilesWithErrors = 0; + + while ($file = readdir($handle)) { + set_time_limit(30); // allocate another 30 seconds to process this file - should go much quicker than this unless intense processing (like bitrate histogram analysis) is enabled + echo ' .'; // progress indicator dot + flush(); // make sure the dot is shown, otherwise it's useless + $currentfilename = $listdirectory.'/'.$file; + + switch ($file) { + case '..': + $ParentDir = realpath($file.'/..').'/'; + if (GETID3_OS_ISWINDOWS) { + $ParentDir = str_replace('\\', '/', $ParentDir); + } + $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $ParentDir; + continue 2; + break; + + case '.': + // ignore + continue 2; + break; + } + + // symbolic-link-resolution enhancements by davidbullock״ech-center*com + $TargetObject = realpath($currentfilename); // Find actual file path, resolve if it's a symbolic link + $TargetObjectType = filetype($TargetObject); // Check file type without examining extension + + if ($TargetObjectType == 'dir') { + + $DirectoryContents[$currentfulldir]['dir'][$file]['filename'] = $file; + + } elseif ($TargetObjectType == 'file') { + + $getID3->setOption(array('option_md5_data' => isset($_REQUEST['ShowMD5']))); + $fileinformation = $getID3->analyze($currentfilename); + + getid3_lib::CopyTagsToComments($fileinformation); + + $TotalScannedFilesize += @$fileinformation['filesize']; + + if (isset($_REQUEST['ShowMD5'])) { + $fileinformation['md5_file'] = md5($currentfilename); + $fileinformation['md5_file'] = getid3_lib::md5_file($currentfilename); + } + + if (!empty($fileinformation['fileformat'])) { + $DirectoryContents[$currentfulldir]['known'][$file] = $fileinformation; + $TotalScannedPlaytime += @$fileinformation['playtime_seconds']; + $TotalScannedBitrate += @$fileinformation['bitrate']; + $TotalScannedKnownFiles++; + } else { + $DirectoryContents[$currentfulldir]['other'][$file] = $fileinformation; + $DirectoryContents[$currentfulldir]['other'][$file]['playtime_string'] = '-'; + $TotalScannedUnknownFiles++; + } + if (isset($fileinformation['playtime_seconds']) && ($fileinformation['playtime_seconds'] > 0)) { + $TotalScannedPlaytimeFiles++; + } + if (isset($fileinformation['bitrate']) && ($fileinformation['bitrate'] > 0)) { + $TotalScannedBitrateFiles++; + } + } + } + $endtime = getmicrotime(); + closedir($handle); + echo 'done<br>'; + echo 'Directory scanned in '.number_format($endtime - $starttime, 2).' seconds.<br>'; + flush(); + + $columnsintable = 14; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + + echo '<tr bgcolor="#'.$getID3checkColor_Head.'"><th colspan="'.$columnsintable.'">Files in '.getid3_lib::iconv_fallback('ISO-8859-1', 'UTF-8', $currentfulldir).'</th></tr>'; + $rowcounter = 0; + foreach ($DirectoryContents as $dirname => $val) { + if (is_array($DirectoryContents[$dirname]['dir'])) { + uksort($DirectoryContents[$dirname]['dir'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['dir'] as $filename => $fileinfo) { + echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_DirectoryLight : $getID3checkColor_DirectoryDark).'">'; + if ($filename == '..') { + echo '<form action="'.$_SERVER['PHP_SELF'].'" method="get">'; + echo '<td colspan="'.$columnsintable.'">Parent directory: '; + echo '<input type="text" name="listdirectory" size="50" style="background-color: '.$getID3checkColor_DirectoryDark.';" value="'; + if (GETID3_OS_ISWINDOWS) { + echo htmlentities(str_replace('\\', '/', realpath($dirname.$filename)), ENT_QUOTES); + } else { + echo htmlentities(realpath($dirname.$filename), ENT_QUOTES); + } + echo '"> <input type="submit" value="Go">'; + echo '</td></form>'; + } else { + echo '<td colspan="'.$columnsintable.'"><a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($dirname.$filename).'"><b>'.FixTextFields($filename).'</b></a></td>'; + } + echo '</tr>'; + } + } + + echo '<tr bgcolor="#'.$getID3checkColor_Head.'">'; + echo '<th>Filename</th>'; + echo '<th>File Size</th>'; + echo '<th>Format</th>'; + echo '<th>Playtime</th>'; + echo '<th>Bitrate</th>'; + echo '<th>Artist</th>'; + echo '<th>Title</th>'; + if (isset($_REQUEST['ShowMD5'])) { + echo '<th>MD5 File (File) (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'">disable</a>)</th>'; + echo '<th>MD5 Data (File) (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'">disable</a>)</th>'; + echo '<th>MD5 Data (Source) (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'">disable</a>)</th>'; + } else { + echo '<th colspan="3">MD5 Data (<a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.rawurlencode(isset($_REQUEST['listdirectory']) ? $_REQUEST['listdirectory'] : '.').'&ShowMD5=1">enable</a>)</th>'; + } + echo '<th>Tags</th>'; + echo '<th>Errors & Warnings</th>'; + echo '<th>Edit</th>'; + echo '<th>Delete</th>'; + echo '</tr>'; + + if (isset($DirectoryContents[$dirname]['known']) && is_array($DirectoryContents[$dirname]['known'])) { + uksort($DirectoryContents[$dirname]['known'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['known'] as $filename => $fileinfo) { + echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_FileDark : $getID3checkColor_FileLight).'">'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename).'" TITLE="View detailed analysis">'.FixTextFields(getid3_lib::SafeStripSlashes($filename)).'</a></td>'; + echo '<td align="right"> '.number_format($fileinfo['filesize']).'</td>'; + echo '<td align="right"> '.NiceDisplayFiletypeFormat($fileinfo).'</td>'; + echo '<td align="right"> '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>'; + echo '<td align="right"> '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000, 0, ((@$fileinfo['audio']['bitrate_mode'] == 'vbr') ? true : false)) : '-').'</td>'; + echo '<td align="left"> '.(isset($fileinfo['comments_html']['artist']) ? implode('<br>', $fileinfo['comments_html']['artist']) : '').'</td>'; + echo '<td align="left"> '.(isset($fileinfo['comments_html']['title']) ? implode('<br>', $fileinfo['comments_html']['title']) : '').'</td>'; + if (isset($_REQUEST['ShowMD5'])) { + echo '<td align="left"><tt>'.(isset($fileinfo['md5_file']) ? $fileinfo['md5_file'] : ' ').'</tt></td>'; + echo '<td align="left"><tt>'.(isset($fileinfo['md5_data']) ? $fileinfo['md5_data'] : ' ').'</tt></td>'; + echo '<td align="left"><tt>'.(isset($fileinfo['md5_data_source']) ? $fileinfo['md5_data_source'] : ' ').'</tt></td>'; + } else { + echo '<td align="center" colspan="3">-</td>'; + } + echo '<td align="left"> '.@implode(', ', array_keys($fileinfo['tags'])).'</td>'; + + echo '<td align="left"> '; + if (!empty($fileinfo['warning'])) { + $FilesWithWarnings++; + echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['warning'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['warning'])).'">warning</a><br>'; + } + if (!empty($fileinfo['error'])) { + $FilesWithErrors++; + echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['error'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['error'])).'">error</a><br>'; + } + echo '</td>'; + + echo '<td align="left"> '; + switch (@$fileinfo['fileformat']) { + case 'mp3': + case 'mp2': + case 'mp1': + case 'flac': + case 'mpc': + case 'real': + echo '<a href="'.$writescriptfilename.'?Filename='.urlencode($dirname.$filename).'" TITLE="Edit tags">edit tags</a>'; + break; + case 'ogg': + switch (@$fileinfo['audio']['dataformat']) { + case 'vorbis': + echo '<a href="'.$writescriptfilename.'?Filename='.urlencode($dirname.$filename).'" TITLE="Edit tags">edit tags</a>'; + break; + } + break; + default: + break; + } + echo '</td>'; + echo '<td align="left"> <a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes($dirname.$filename).'? \n(this action cannot be un-done)\');" TITLE="Permanently delete '."\n".FixTextFields($filename)."\n".' from'."\n".' '.FixTextFields($dirname).'">delete</a></td>'; + echo '</tr>'; + } + } + + if (isset($DirectoryContents[$dirname]['other']) && is_array($DirectoryContents[$dirname]['other'])) { + uksort($DirectoryContents[$dirname]['other'], 'MoreNaturalSort'); + foreach ($DirectoryContents[$dirname]['other'] as $filename => $fileinfo) { + echo '<tr bgcolor="#'.(($rowcounter++ % 2) ? $getID3checkColor_UnknownDark : $getID3checkColor_UnknownLight).'">'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?filename='.urlencode($dirname.$filename).'"><i>'.$filename.'</i></a></td>'; + echo '<td align="right"> '.(isset($fileinfo['filesize']) ? number_format($fileinfo['filesize']) : '-').'</td>'; + echo '<td align="right"> '.NiceDisplayFiletypeFormat($fileinfo).'</td>'; + echo '<td align="right"> '.(isset($fileinfo['playtime_string']) ? $fileinfo['playtime_string'] : '-').'</td>'; + echo '<td align="right"> '.(isset($fileinfo['bitrate']) ? BitrateText($fileinfo['bitrate'] / 1000) : '-').'</td>'; + echo '<td align="left"> </td>'; // Artist + echo '<td align="left"> </td>'; // Title + echo '<td align="left" colspan="3"> </td>'; // MD5_data + echo '<td align="left"> </td>'; // Tags + + //echo '<td align="left"> </td>'; // Warning/Error + echo '<td align="left"> '; + if (!empty($fileinfo['warning'])) { + $FilesWithWarnings++; + echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['warning'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['warning'])).'">warning</a><br>'; + } + if (!empty($fileinfo['error'])) { + if ($fileinfo['error'][0] != 'unable to determine file format') { + $FilesWithErrors++; + echo '<a href="javascript:alert(\''.FixTextFields(implode('\\n', $fileinfo['error'])).'\');" TITLE="'.FixTextFields(implode("\n", $fileinfo['error'])).'">error</a><br>'; + } + } + echo '</td>'; + + echo '<td align="left"> </td>'; // Edit + echo '<td align="left"> <a href="'.$_SERVER['PHP_SELF'].'?listdirectory='.urlencode($listdirectory).'&deletefile='.urlencode($dirname.$filename).'" onClick="return confirm(\'Are you sure you want to delete '.addslashes($dirname.$filename).'? \n(this action cannot be un-done)\');" TITLE="Permanently delete '.addslashes($dirname.$filename).'">delete</a></td>'; + echo '</tr>'; + } + } + + echo '<tr bgcolor="#'.$getID3checkColor_Head.'">'; + echo '<td><b>Average:</b></td>'; + echo '<td align="right">'.number_format($TotalScannedFilesize / max($TotalScannedKnownFiles, 1)).'</td>'; + echo '<td> </td>'; + echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime / max($TotalScannedPlaytimeFiles, 1)).'</td>'; + echo '<td align="right">'.BitrateText(round(($TotalScannedBitrate / 1000) / max($TotalScannedBitrateFiles, 1))).'</td>'; + echo '<td rowspan="2" colspan="'.($columnsintable - 5).'"><table border="0" cellspacing="0" cellpadding="2"><tr><th align="right">Identified Files:</th><td align="right">'.number_format($TotalScannedKnownFiles).'</td><td> </td><th align="right">Errors:</th><td align="right">'.number_format($FilesWithErrors).'</td></tr><tr><th align="right">Unknown Files:</th><td align="right">'.number_format($TotalScannedUnknownFiles).'</td><td> </td><th align="right">Warnings:</th><td align="right">'.number_format($FilesWithWarnings).'</td></tr></table>'; + echo '</tr>'; + echo '<tr bgcolor="#'.$getID3checkColor_Head.'">'; + echo '<td><b>Total:</b></td>'; + echo '<td align="right">'.number_format($TotalScannedFilesize).'</td>'; + echo '<td> </td>'; + echo '<td align="right">'.getid3_lib::PlaytimeString($TotalScannedPlaytime).'</td>'; + echo '<td> </td>'; + echo '</tr>'; + } + echo '</table>'; + } else { + echo '<b>ERROR: Could not open directory: <u>'.$currentfulldir.'</u></b><br>'; + } +} +echo PoweredBygetID3(); +echo 'Running on PHP v'.phpversion(); +echo '</body></html>'; +ob_end_flush(); + + +///////////////////////////////////////////////////////////////// + + +function RemoveAccents($string) { + // Revised version by markstewardרotmail*com + // Again revised by James Heinrich (19-June-2006) + return strtr( + strtr( + $string, + "\x8A\x8E\x9A\x9E\x9F\xC0\xC1\xC2\xC3\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFF", + 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy' + ), + array( + "\xDE" => 'TH', + "\xFE" => 'th', + "\xD0" => 'DH', + "\xF0" => 'dh', + "\xDF" => 'ss', + "\x8C" => 'OE', + "\x9C" => 'oe', + "\xC6" => 'AE', + "\xE6" => 'ae', + "\xB5" => '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, $vbr=false) { + return '<SPAN STYLE="color: #'.BitrateColor($bitrate).($vbr ? '; font-weight: bold;' : '').'">'.number_format($bitrate, $decimals).' kbps</SPAN>'; +} + +function FixTextFields($text) { + $text = getid3_lib::SafeStripSlashes($text); + $text = htmlentities($text, ENT_QUOTES); + return $text; +} + + +function string_var_dump($variable) { + ob_start(); + var_dump($variable); + $dumpedvariable = ob_get_contents(); + ob_end_clean(); + return $dumpedvariable; +} + + +function table_var_dump($variable) { + $returnstring = ''; + switch (gettype($variable)) { + case 'array': + $returnstring .= '<table border="1" cellspacing="0" cellpadding="2">'; + foreach ($variable as $key => $value) { + $returnstring .= '<tr><td valign="top"><b>'.str_replace("\x00", ' ', $key).'</b></td>'; + $returnstring .= '<td valign="top">'.gettype($value); + if (is_array($value)) { + $returnstring .= ' ('.count($value).')'; + } elseif (is_string($value)) { + $returnstring .= ' ('.strlen($value).')'; + } + if (($key == 'data') && isset($variable['image_mime']) && isset($variable['dataoffset'])) { + $imagechunkcheck = getid3_lib::GetDataImageSize($value); + $DumpedImageSRC = (!empty($_REQUEST['filename']) ? $_REQUEST['filename'] : '.getid3').'.'.$variable['dataoffset'].'.'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]); + if ($tempimagefile = @fopen($DumpedImageSRC, 'wb')) { + fwrite($tempimagefile, $value); + fclose($tempimagefile); + } + $returnstring .= '</td><td><img src="'.$_SERVER['PHP_SELF'].'?showfile='.urlencode($DumpedImageSRC).'&md5='.md5_file($DumpedImageSRC).'" width="'.$imagechunkcheck[0].'" height="'.$imagechunkcheck[1].'"></td></tr>'; + } else { + $returnstring .= '</td><td>'.table_var_dump($value).'</td></tr>'; + } + } + $returnstring .= '</table>'; + break; + + case 'boolean': + $returnstring .= ($variable ? 'TRUE' : 'FALSE'); + break; + + case 'integer': + case 'double': + case 'float': + $returnstring .= $variable; + break; + + case 'object': + case 'null': + $returnstring .= string_var_dump($variable); + break; + + case 'string': + $variable = str_replace("\x00", ' ', $variable); + $varlen = strlen($variable); + for ($i = 0; $i < $varlen; $i++) { + if (ereg('['."\x0A\x0D".' -;0-9A-Za-z]', $variable{$i})) { + $returnstring .= $variable{$i}; + } else { + $returnstring .= '&#'.str_pad(ord($variable{$i}), 3, '0', STR_PAD_LEFT).';'; + } + } + $returnstring = nl2br($returnstring); + break; + + default: + $imagechunkcheck = getid3_lib::GetDataImageSize($variable); + if (($imagechunkcheck[2] >= 1) && ($imagechunkcheck[2] <= 3)) { + $returnstring .= '<table border="1" cellspacing="0" cellpadding="2">'; + $returnstring .= '<tr><td><b>type</b></td><td>'.getid3_lib::ImageTypesLookup($imagechunkcheck[2]).'</td></tr>'; + $returnstring .= '<tr><td><b>width</b></td><td>'.number_format($imagechunkcheck[0]).' px</td></tr>'; + $returnstring .= '<tr><td><b>height</b></td><td>'.number_format($imagechunkcheck[1]).' px</td></tr>'; + $returnstring .= '<tr><td><b>size</b></td><td>'.number_format(strlen($variable)).' bytes</td></tr></table>'; + } else { + $returnstring .= nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable))); + } + break; + } + return $returnstring; +} + + +function NiceDisplayFiletypeFormat(&$fileinfo) { + + if (empty($fileinfo['fileformat'])) { + return '-'; + } + + $output = $fileinfo['fileformat']; + if (empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { + return $output; // 'gif' + } + if (empty($fileinfo['video']['dataformat']) && !empty($fileinfo['audio']['dataformat'])) { + if ($fileinfo['fileformat'] == $fileinfo['audio']['dataformat']) { + return $output; // 'mp3' + } + $output .= '.'.$fileinfo['audio']['dataformat']; // 'ogg.flac' + return $output; + } + if (!empty($fileinfo['video']['dataformat']) && empty($fileinfo['audio']['dataformat'])) { + if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { + return $output; // 'mpeg' + } + $output .= '.'.$fileinfo['video']['dataformat']; // 'riff.avi' + return $output; + } + if ($fileinfo['video']['dataformat'] == $fileinfo['audio']['dataformat']) { + if ($fileinfo['fileformat'] == $fileinfo['video']['dataformat']) { + return $output; // 'real' + } + $output .= '.'.$fileinfo['video']['dataformat']; // any examples? + return $output; + } + $output .= '.'.$fileinfo['video']['dataformat']; + $output .= '.'.$fileinfo['audio']['dataformat']; // asf.wmv.wma + return $output; + +} + +function MoreNaturalSort($ar1, $ar2) { + if ($ar1 === $ar2) { + return 0; + } + $len1 = strlen($ar1); + $len2 = strlen($ar2); + $shortest = min($len1, $len2); + if (substr($ar1, 0, $shortest) === substr($ar2, 0, $shortest)) { + // the shorter argument is the beginning of the longer one, like "str" and "string" + if ($len1 < $len2) { + return -1; + } elseif ($len1 > $len2) { + return 1; + } + return 0; + } + $ar1 = RemoveAccents(strtolower(trim($ar1))); + $ar2 = RemoveAccents(strtolower(trim($ar2))); + $translatearray = array('\''=>'', '"'=>'', '_'=>' ', '('=>'', ')'=>'', '-'=>' ', ' '=>' ', '.'=>'', ','=>''); + foreach ($translatearray as $key => $val) { + $ar1 = str_replace($key, $val, $ar1); + $ar2 = str_replace($key, $val, $ar2); + } + + if ($ar1 < $ar2) { + return -1; + } elseif ($ar1 > $ar2) { + return 1; + } + return 0; +} + +function PoweredBygetID3($string='<br><HR NOSHADE><DIV STYLE="font-size: 8pt; font-face: sans-serif;">Powered by <a href="http://getid3.sourceforge.net" TARGET="_blank"><b>getID3() v<!--GETID3VER--></b><br>http://getid3.sourceforge.net</a></DIV>') { + return str_replace('<!--GETID3VER-->', GETID3_VERSION, $string); +} + + +///////////////////////////////////////////////////////////////// +// Unify the contents of GPC, +// whether magic_quotes_gpc is on or off + +function AddStripSlashesArray($input, $addslashes=false) { + if (is_array($input)) { + + $output = $input; + foreach ($input as $key => $value) { + $output[$key] = AddStripSlashesArray($input[$key]); + } + return $output; + + } elseif ($addslashes) { + return addslashes($input); + } + return stripslashes($input); +} + +function UnifyMagicQuotes($turnon=false) { + global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS; + + if (get_magic_quotes_gpc() && !$turnon) { + + // magic_quotes_gpc is on and we want it off! + $_GET = AddStripSlashesArray($_GET, true); + $_POST = AddStripSlashesArray($_POST, true); + $_COOKIE = AddStripSlashesArray($_COOKIE, true); + + unset($_REQUEST); + $_REQUEST = array_merge_recursive($_GET, $_POST, $_COOKIE); + + } elseif (!get_magic_quotes_gpc() && $turnon) { + + // magic_quotes_gpc is off and we want it on (why??) + $_GET = AddStripSlashesArray($_GET, true); + $_POST = AddStripSlashesArray($_POST, true); + $_COOKIE = AddStripSlashesArray($_COOKIE, true); + + unset($_REQUEST); + $_REQUEST = array_merge_recursive($_GET, $_POST, $_COOKIE); + + } + $HTTP_GET_VARS = $_GET; + $HTTP_POST_VARS = $_POST; + $HTTP_COOKIE_VARS = $_COOKIE; + + return true; +} +///////////////////////////////////////////////////////////////// + + +?> +</BODY> +</HTML>
\ No newline at end of file diff --git a/getid3/demos/demo.cache.dbm.php b/getid3/demos/demo.cache.dbm.php new file mode 100644 index 0000000..acaaa0f --- /dev/null +++ b/getid3/demos/demo.cache.dbm.php @@ -0,0 +1,29 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.cache.dbm.php - part of getID3() // +// Sample script demonstrating the use of the DBM caching // +// extension for getID3() // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +require_once('../getid3/getid3.php'); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'extension.cache.dbm.php', __FILE__, true); + +$getID3 = new getID3_cached_dbm('db3', '/zimweb/test/test.dbm', '/zimweb/test/test.lock'); + +$r = $getID3->analyze('/path/to/files/filename.mp3'); + +echo '<pre>'; +var_dump($r); +echo '</pre>'; + +// uncomment to clear cache +// $getID3->clear_cache(); + +?>
\ No newline at end of file diff --git a/getid3/demos/demo.cache.mysql.php b/getid3/demos/demo.cache.mysql.php new file mode 100644 index 0000000..537b2f0 --- /dev/null +++ b/getid3/demos/demo.cache.mysql.php @@ -0,0 +1,29 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.cache.mysql.php - part of getID3() // +// Sample script demonstrating the use of the DBM caching // +// extension for getID3() // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +require_once('../getid3/getid3.php'); +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'extension.cache.mysql.php', __FILE__, true); + +$getID3 = new getID3_cached_mysql('localhost', 'database', 'username', 'password'); + +$r = $getID3->analyze('/path/to/files/filename.mp3'); + +echo '<pre>'; +var_dump($r); +echo '</pre>'; + +// uncomment to clear cache +//$getID3->clear_cache(); + +?>
\ No newline at end of file diff --git a/getid3/demos/demo.joinmp3.php b/getid3/demos/demo.joinmp3.php new file mode 100644 index 0000000..976884f --- /dev/null +++ b/getid3/demos/demo.joinmp3.php @@ -0,0 +1,96 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.joinmp3.php - part of getID3() // +// Sample script for splicing two or more MP3s together into // +// one file. Does not attempt to fix VBR header frames. // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + + +// sample usage: +// $FilenameOut = 'combined.mp3'; +// $FilenamesIn[] = 'file1.mp3'; +// $FilenamesIn[] = 'file2.mp3'; +// $FilenamesIn[] = 'file3.mp3'; +// +// if (CombineMultipleMP3sTo($FilenameOut, $FilenamesIn)) { +// echo 'Successfully copied '.implode(' + ', $FilenamesIn).' to '.$FilenameOut; +// } else { +// echo 'Failed to copy '.implode(' + ', $FilenamesIn).' to '.$FilenameOut; +// } + +function CombineMultipleMP3sTo($FilenameOut, $FilenamesIn) { + + foreach ($FilenamesIn as $nextinputfilename) { + if (!is_readable($nextinputfilename)) { + echo 'Cannot read "'.$nextinputfilename.'"<BR>'; + return false; + } + } + if (!is_writeable($FilenameOut)) { + echo 'Cannot write "'.$FilenameOut.'"<BR>'; + return false; + } + + require_once('../getid3/getid3.php'); + if ($fp_output = @fopen($FilenameOut, 'wb')) { + + // Initialize getID3 engine + $getID3 = new getID3; + foreach ($FilenamesIn as $nextinputfilename) { + + $CurrentFileInfo = $getID3->analyze($nextinputfilename); + if ($CurrentFileInfo['fileformat'] == 'mp3') { + + if ($fp_source = @fopen($nextinputfilename, 'rb')) { + + $CurrentOutputPosition = ftell($fp_output); + + // copy audio data from first file + fseek($fp_source, $CurrentFileInfo['avdataoffset'], SEEK_SET); + while (!feof($fp_source) && (ftell($fp_source) < $CurrentFileInfo['avdataend'])) { + fwrite($fp_output, fread($fp_source, 32768)); + } + fclose($fp_source); + + // trim post-audio data (if any) copied from first file that we don't need or want + $EndOfFileOffset = $CurrentOutputPosition + ($CurrentFileInfo['avdataend'] - $CurrentFileInfo['avdataoffset']); + fseek($fp_output, $EndOfFileOffset, SEEK_SET); + ftruncate($fp_output, $EndOfFileOffset); + + } else { + + echo 'failed to open '.$nextinputfilename.' for reading'; + fclose($fp_output); + return false; + + } + + } else { + + echo $nextinputfilename.' is not MP3 format'; + fclose($fp_output); + return false; + + } + + } + + } else { + + echo 'failed to open '.$FilenameOut.' for writing'; + return false; + + } + + fclose($fp_output); + return true; +} + +?>
\ No newline at end of file diff --git a/getid3/demos/demo.mimeonly.php b/getid3/demos/demo.mimeonly.php new file mode 100644 index 0000000..dd6dec6 --- /dev/null +++ b/getid3/demos/demo.mimeonly.php @@ -0,0 +1,53 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.mimeonly.php - part of getID3() // +// Sample script for scanning a single file and returning only // +// the MIME information // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +echo '<HTML><HEAD><STYLE>BODY, TD, TH { font-family: sans-serif; font-size: 10pt; }</STYLE></HEAD><BODY>'; + +if (!empty($_REQUEST['filename'])) { + + echo 'The file "'.$_REQUEST['filename'].'" has a MIME type of "'.GetMIMEtype($_REQUEST['filename']).'"'; + +} else { + + echo 'Usage: <TT>'.$_SERVER['PHP_SELF'].'?filename=<I>filename.ext</I></TT>'; + +} + + +function GetMIMEtype($filename) { + // include getID3() library (can be in a different directory if full path is specified) + require_once('../getid3/getid3.php'); + // Initialize getID3 engine + $getID3 = new getID3; + + $DeterminedMIMEtype = ''; + if ($fp = fopen($filename, 'rb')) { + $ThisFileInfo = array('avdataoffset'=>0, 'avdataend'=>0); + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true); + $tag = new getid3_id3v2($fp, $ThisFileInfo); + + fseek($fp, $ThisFileInfo['avdataoffset'], SEEK_SET); + $formattest = fread($fp, 16); // 16 bytes is sufficient for any format except ISO CD-image + fclose($fp); + + $DeterminedFormatInfo = $getID3->GetFileFormat($formattest); + $DeterminedMIMEtype = $DeterminedFormatInfo['mime_type']; + } + return $DeterminedMIMEtype; +} + +?> +</BODY> +</HTML>
\ No newline at end of file diff --git a/getid3/demos/demo.mysql.php b/getid3/demos/demo.mysql.php new file mode 100644 index 0000000..0228749 --- /dev/null +++ b/getid3/demos/demo.mysql.php @@ -0,0 +1,2130 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /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 // +// /// +///////////////////////////////////////////////////////////////// + +// 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', 'getid3'); +define('GETID3_DB_PASS', 'getid3'); +define('GETID3_DB_DB', 'getid3'); +define('GETID3_DB_TABLE', 'files'); + + +if (!@mysql_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)) { + die('Could not connect to MySQL host: <blockquote style="background-color: #FF9933; padding: 10px;">'.mysql_error().'</blockquote>'); +} +if (!@mysql_select_db(GETID3_DB_DB)) { + die('Could not select database: <blockquote style="background-color: #FF9933; padding: 10px;">'.mysql_error().'</blockquote>'); +} + +if (!@include_once('../getid3/getid3.php')) { + die('Cannot open '.realpath('../getid3/getid3.php')); +} +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array( + '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'), array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u')); +} + +function FixTextFields($text) { + $text = getid3_lib::SafeStripSlashes($text); + $text = htmlentities($text, ENT_QUOTES); + return $text; +} + +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 '<span style="color: #'.BitrateColor($bitrate).'">'.number_format($bitrate, $decimals).' kbps</span>'; +} + +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 = '<span style="color: #FF0000;"><b>Source and Destination filenames identical</b><br>FAILED to rename'; + } elseif (!file_exists($from)) { + $results = '<span style="color: #FF0000;"><b>Source file does not exist</b><br>FAILED to rename'; + } elseif (file_exists($to) && (strtolower($from) !== strtolower($to))) { + $results = '<span style="color: #FF0000;"><b>Destination file already exists</b><br>FAILED to rename'; + } elseif (@rename($from, $to)) { + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_escape_string($from).'")'; + safe_mysql_query($SQLquery); + $results = '<span style="color: #008000;">Successfully renamed'; + } else { + $results = '<br><span style="color: #FF0000;">FAILED to rename'; + $success = false; + } + $results .= ' from:<br><i>'.$from.'</i><br>to:<br><i>'.$to.'</i></span><hr>'; + 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 '<html><head><title>getID3() demo - /demo/mysql.php</title><style>BODY, TD, TH { font-family: sans-serif; font-size: 10pt; } A { text-decoration: none; } A:hover { text-decoration: underline; } A:visited { font-style: italic; }</style></head><body>'; + +} + + +function WindowsShareSlashTranslate($filename) { + if (substr($filename, 0, 2) == '//') { + return str_replace('/', '\\', $filename); + } + return $filename; +} + +function safe_mysql_query($SQLquery) { + $result = @mysql_query($SQLquery); + if (mysql_error()) { + die('<FONT COLOR="red">'.mysql_error().'</FONT><hr><TT>'.$SQLquery.'</TT>'); + } + return $result; +} + +function mysql_table_exists($tablename) { + return (bool) mysql_query('DESCRIBE '.$tablename); +} + +function AcceptableExtensions($fileformat, $audio_dataformat='', $video_dataformat='') { + static $AcceptableExtensionsAudio = array(); + if (empty($AcceptableExtensionsAudio)) { + $AcceptableExtensionsAudio['mp3']['mp3'] = array('mp3'); + $AcceptableExtensionsAudio['mp2']['mp2'] = array('mp2'); + $AcceptableExtensionsAudio['mp1']['mp1'] = array('mp1'); + $AcceptableExtensionsAudio['asf']['asf'] = array('asf'); + $AcceptableExtensionsAudio['asf']['wma'] = array('wma'); + $AcceptableExtensionsAudio['riff']['mp3'] = array('wav'); + $AcceptableExtensionsAudio['riff']['wav'] = array('wav'); + } + static $AcceptableExtensionsVideo = array(); + if (empty($AcceptableExtensionsVideo)) { + $AcceptableExtensionsVideo['mp3']['mp3'] = array('mp3'); + $AcceptableExtensionsVideo['mp2']['mp2'] = array('mp2'); + $AcceptableExtensionsVideo['mp1']['mp1'] = array('mp1'); + $AcceptableExtensionsVideo['asf']['asf'] = array('asf'); + $AcceptableExtensionsVideo['asf']['wmv'] = array('wmv'); + $AcceptableExtensionsVideo['gif']['gif'] = array('gif'); + $AcceptableExtensionsVideo['jpg']['jpg'] = array('jpg'); + $AcceptableExtensionsVideo['png']['png'] = array('png'); + $AcceptableExtensionsVideo['bmp']['bmp'] = array('bmp'); + } + if (!empty($video_dataformat)) { + return (isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : array()); + } else { + return (isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : array()); + } +} + + +if (!empty($_REQUEST['scan'])) { + if (mysql_table_exists(GETID3_DB_TABLE)) { + $SQLquery = 'DROP TABLE `'.GETID3_DB_TABLE.'`'; + safe_mysql_query($SQLquery); + } +} +if (!mysql_table_exists(GETID3_DB_TABLE)) { + $SQLquery = 'CREATE TABLE `'.GETID3_DB_TABLE.'` ('; + $SQLquery .= ' `ID` mediumint(8) unsigned NOT NULL auto_increment,'; + $SQLquery .= ' `filename` text NOT NULL,'; + $SQLquery .= ' `LastModified` text NOT NULL,'; + $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` varchar(255) NOT NULL default "",'; + $SQLquery .= ' `track` varchar(7) NOT NULL default "",'; + $SQLquery .= ' `comments_all` text NOT NULL,'; + $SQLquery .= ' `comments_id3v2` text NOT NULL,'; + $SQLquery .= ' `comments_ape` text NOT NULL,'; + $SQLquery .= ' `comments_lyrics3` text NOT NULL,'; + $SQLquery .= ' `comments_id3v1` text NOT NULL,'; + $SQLquery .= ' `warning` text NOT NULL,'; + $SQLquery .= ' `error` text 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 .= ') TYPE=MyISAM;'; + + safe_mysql_query($SQLquery); +} + +$ExistingTableFields = array(); +$result = mysql_query('DESCRIBE `'.GETID3_DB_TABLE.'`'); +while ($row = mysql_fetch_array($result)) { + $ExistingTableFields[$row['Field']] = $row; +} +if (!isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2 + echo '<b>adding field `encoder_options`</b><br>'; + mysql_query('ALTER TABLE `'.GETID3_DB_TABLE.'` ADD `encoder_options` VARCHAR(255) DEFAULT "" NOT NULL AFTER `error`'); + mysql_query('OPTIMIZE TABLE `'.GETID3_DB_TABLE.'`'); +} +if (isset($ExistingTableFields['track']) && ($ExistingTableFields['track']['Type'] != 'varchar(7)')) { // Changed in 1.7.0b2 + echo '<b>changing field `track` to VARCHAR(7)</b><br>'; + mysql_query('ALTER TABLE `'.GETID3_DB_TABLE.'` CHANGE `track` `track` VARCHAR(7) DEFAULT "" NOT NULL'); + mysql_query('OPTIMIZE TABLE `'.GETID3_DB_TABLE.'`'); +} +if (!isset($ExistingTableFields['track_volume'])) { // Added in 1.7.0b5 + echo '<H1><FONT COLOR="red">WARNING! You should erase your database and rescan everything because the comment storing has been changed since the last version</FONT></H1><hr>'; + echo '<b>adding field `track_volume`</b><br>'; + mysql_query('ALTER TABLE `'.GETID3_DB_TABLE.'` ADD `track_volume` FLOAT NOT NULL AFTER `error`'); + mysql_query('OPTIMIZE TABLE `'.GETID3_DB_TABLE.'`'); +} +if (!isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1 + echo '<b>adding field `encoder_options`, `alternate_name`, `parody`</b><br>'; + mysql_query('ALTER TABLE `'.GETID3_DB_TABLE.'` ADD `remix` VARCHAR(255) DEFAULT "" NOT NULL AFTER `title`'); + mysql_query('ALTER TABLE `'.GETID3_DB_TABLE.'` ADD `alternate_name` VARCHAR(255) DEFAULT "" NOT NULL AFTER `track`'); + mysql_query('ALTER TABLE `'.GETID3_DB_TABLE.'` ADD `parody` VARCHAR(255) DEFAULT "" NOT NULL AFTER `alternate_name`'); + mysql_query('OPTIMIZE TABLE `'.GETID3_DB_TABLE.'`'); +} + + +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 = @$ThisFileInfo['comments']; + } elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) { + $SourceArray = @$ThisFileInfo['tags'][$synchronizefrom]; + } else { + die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist'); + } + + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_escape_string($filename).'")'; + safe_mysql_query($SQLquery); + + + $TagFormatsToWrite = array(); + if ((strpos($synchronizeto, '2') !== false) && ($synchronizefrom != 'id3v2')) { + $TagFormatsToWrite[] = 'id3v2.3'; + } + if ((strpos($synchronizeto, 'A') !== false) && ($synchronizefrom != 'ape')) { + $TagFormatsToWrite[] = 'ape'; + } + if ((strpos($synchronizeto, 'L') !== false) && ($synchronizefrom != 'lyrics3')) { + $TagFormatsToWrite[] = 'lyrics3'; + } + if ((strpos($synchronizeto, '1') !== false) && ($synchronizefrom != 'id3v1')) { + $TagFormatsToWrite[] = 'id3v1'; + } + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); + $tagwriter = new getid3_writetags; + $tagwriter->filename = $filename; + $tagwriter->tagformats = $TagFormatsToWrite; + $tagwriter->overwrite_tags = true; + $tagwriter->tag_encoding = $getID3->encoding; + $tagwriter->tag_data = $SourceArray; + + if ($tagwriter->WriteTags()) { + $errors = $tagwriter->errors; + return true; + } + $errors = $tagwriter->errors; + return false; +} + +$IgnoreNoTagFormats = array('', 'png', 'jpg', 'gif', 'bmp', 'swf', 'zip', 'mid', 'mod', 'xm', 'it', 's3m'); + +if (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan']) || !empty($_REQUEST['rescanerrors'])) { + + $SQLquery = 'DELETE from `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` = "")'; + safe_mysql_query($SQLquery); + + $FilesInDir = array(); + + if (!empty($_REQUEST['rescanerrors'])) { + + echo '<a href="'.$_SERVER['PHP_SELF'].'">abort</a><hr>'; + + echo 'Re-scanning all media files already in database that had errors and/or warnings in last scan<hr>'; + + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`error` <> "")'; + $SQLquery .= ' OR (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + while ($row = mysql_fetch_array($result)) { + + if (!file_exists($row['filename'])) { + echo '<b>File missing: '.$row['filename'].'</b><br>'; + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_escape_string($row['filename']).'")'; + safe_mysql_query($SQLquery); + } else { + $FilesInDir[] = $row['filename']; + } + + } + + } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { + + echo '<a href="'.$_SERVER['PHP_SELF'].'">abort</a><hr>'; + + echo 'Scanning all media files in <b>'.str_replace('\\', '/', realpath(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan'])).'</b> (and subdirectories)<hr>'; + + $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' GROUP BY `filename`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = safe_mysql_query($SQLquery); + $DupesDeleted = 0; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + if ($row['num'] <= 1) { + break; + } + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE `filename` LIKE "'.mysql_escape_string($row['filename']).'"'; + safe_mysql_query($SQLquery); + $DupesDeleted++; + } + if ($DupesDeleted > 0) { + echo 'Deleted <b>'.number_format($DupesDeleted).'</b> duplicate filenames<hr>'; + } + + if (!empty($_REQUEST['newscan'])) { + $AlreadyInDatabase = array(); + set_time_limit(60); + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + while ($row = mysql_fetch_array($result)) { + //$AlreadyInDatabase[] = strtolower($row['filename']); + $AlreadyInDatabase[] = $row['filename']; + } + } + + $DirectoriesToScan = array(@$_REQUEST['scan'] ? $_REQUEST['scan'] : $_REQUEST['newscan']); + $DirectoriesScanned = array(); + while (count($DirectoriesToScan) > 0) { + foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) { + if ($dir = opendir($startingdir)) { + set_time_limit(30); + echo '<b>'.str_replace('\\', '/', $startingdir).'</b><br>'; + 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; + } + } else if (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 '<FONT COLOR="RED">Failed to open directory "<b>'.$startingdir.'</b>"</FONT><br><br>'; + } + $DirectoriesScanned[] = $startingdir; + unset($DirectoriesToScan[$DirectoryKey]); + } + } + echo '<i>List of files to scan complete (added '.number_format(count($FilesInDir)).' files to scan)</i><hr>'; + flush(); + } + + $FilesInDir = array_unique($FilesInDir); + sort($FilesInDir); + + $starttime = time(); + $rowcounter = 0; + $totaltoprocess = count($FilesInDir); + + foreach ($FilesInDir as $filename) { + set_time_limit(300); + + echo '<br>'.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 ' (<span style="color: #990099;">unknown file type</span>)'; + + } else { + + if (!empty($ThisFileInfo['error'])) { + echo ' (<span style="color: #FF0000;">errors</span>)'; + } elseif (!empty($ThisFileInfo['warning'])) { + echo ' (<span style="color: #FF9999;">warnings</span>)'; + } else { + echo ' (<span style="color: #009900;">OK</span>)'; + } + + $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 (ereg('^([0-9]+)/([0-9]+)$', $this_track_track, $matches)) { + // change "1/5"->"01/05", "3/12"->"03/12", etc + $this_track_track = str_pad($matches[1], 2, '0', STR_PAD_LEFT).'/'.str_pad($matches[2], 2, '0', STR_PAD_LEFT); + } + } + + $this_track_remix = ''; + $this_track_title = ''; + if (!empty($ThisFileInfo['comments']['title'])) { + foreach ($ThisFileInfo['comments']['title'] as $possible_title) { + if (strlen($possible_title) > strlen($this_track_title)) { + $this_track_title = $possible_title; + } + } + } + + $ParenthesesPairs = array('()', '[]', '{}'); + foreach ($ParenthesesPairs as $pair) { + if (preg_match_all('/(.*) '.preg_quote($pair{0}).'(([^'.preg_quote($pair).']*[\- '.preg_quote($pair{0}).'])?(cut|dub|edit|version|live|reprise|[a-z]*mix))'.preg_quote($pair{1}).'/iU', $this_track_title, $matches)) { + $this_track_title = $matches[1][0]; + $this_track_remix = implode("\t", $matches[2]); + } + } + + + + if (!empty($_REQUEST['rescanerrors'])) { + + $SQLquery = 'UPDATE `'.GETID3_DB_TABLE.'` SET '; + $SQLquery .= '`LastModified` = "'.mysql_escape_string(@$ThisFileInfo['file_modified_time']).'", '; + $SQLquery .= '`md5_file` = "'.mysql_escape_string(@$ThisFileInfo['md5_file']).'", '; + $SQLquery .= '`md5_data` = "'.mysql_escape_string(@$ThisFileInfo['md5_data']).'", '; + $SQLquery .= '`md5_data_source` = "'.mysql_escape_string(@$ThisFileInfo['md5_data_source']).'", '; + $SQLquery .= '`filesize` = "'.mysql_escape_string(@$ThisFileInfo['filesize']).'", '; + $SQLquery .= '`fileformat` = "'.mysql_escape_string(@$ThisFileInfo['fileformat']).'", '; + $SQLquery .= '`audio_dataformat` = "'.mysql_escape_string(@$ThisFileInfo['audio']['dataformat']).'", '; + $SQLquery .= '`video_dataformat` = "'.mysql_escape_string(@$ThisFileInfo['video']['dataformat']).'", '; + $SQLquery .= '`audio_bitrate` = "'.mysql_escape_string(@$ThisFileInfo['audio']['bitrate']).'", '; + $SQLquery .= '`video_bitrate` = "'.mysql_escape_string(@$ThisFileInfo['video']['bitrate']).'", '; + $SQLquery .= '`playtime_seconds` = "'.mysql_escape_string(@$ThisFileInfo['playtime_seconds']).'", '; + $SQLquery .= '`tags` = "'.mysql_escape_string(@implode("\t", @array_keys(@$ThisFileInfo['tags']))).'", '; + $SQLquery .= '`artist` = "'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['artist'])).'", '; + + $SQLquery .= '`title` = "'.mysql_escape_string($this_track_title).'", '; + $SQLquery .= '`remix` = "'.mysql_escape_string($this_track_remix).'", '; + + $SQLquery .= '`album` = "'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['album'])).'", '; + $SQLquery .= '`genre` = "'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['genre'])).'", '; + $SQLquery .= '`comment` = "'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['comment'])).'", '; + + $SQLquery .= '`track` = "'.mysql_escape_string($this_track_track).'", '; + + $SQLquery .= '`comments_all` = "'.mysql_escape_string(@serialize(@$ThisFileInfo['comments'])).'", '; + $SQLquery .= '`comments_id3v2` = "'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['id3v2'])).'", '; + $SQLquery .= '`comments_ape` = "'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['ape'])).'", '; + $SQLquery .= '`comments_lyrics3` = "'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['lyrics3'])).'", '; + $SQLquery .= '`comments_id3v1` = "'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['id3v1'])).'", '; + $SQLquery .= '`warning` = "'.mysql_escape_string(@implode("\t", @$ThisFileInfo['warning'])).'", '; + $SQLquery .= '`error` = "'.mysql_escape_string(@implode("\t", @$ThisFileInfo['error'])).'", '; + $SQLquery .= '`encoder_options` = "'.mysql_escape_string(trim(@$ThisFileInfo['audio']['encoder'].' '.@$ThisFileInfo['audio']['encoder_options'])).'", '; + $SQLquery .= '`vbr_method` = "'.mysql_escape_string(@$ThisFileInfo['mpeg']['audio']['VBR_method']).'", '; + $SQLquery .= '`track_volume` = "'.mysql_escape_string(@$ThisFileInfo['replay_gain']['track']['volume']).'" '; + $SQLquery .= 'WHERE (`filename` = "'.mysql_escape_string(@$ThisFileInfo['filenamepath']).'")'; + + } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) { + + $SQLquery = 'INSERT INTO `'.GETID3_DB_TABLE.'` (`filename`, `LastModified`, `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_escape_string(@$ThisFileInfo['filenamepath']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['file_modified_time']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['md5_file']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['md5_data']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['md5_data_source']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['filesize']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['fileformat']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['audio']['dataformat']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['video']['dataformat']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['audio']['bitrate']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['video']['bitrate']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['playtime_seconds']).'", '; + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @array_keys(@$ThisFileInfo['tags']))).'", '; + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['artist'])).'", '; + + $SQLquery .= '"'.mysql_escape_string($this_track_title).'", '; + $SQLquery .= '"'.mysql_escape_string($this_track_remix).'", '; + + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['album'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['genre'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @$ThisFileInfo['comments']['comment'])).'", '; + + $SQLquery .= '"'.mysql_escape_string($this_track_track).'", '; + + $SQLquery .= '"'.mysql_escape_string(@serialize(@$ThisFileInfo['comments'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['id3v2'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['ape'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['lyrics3'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@serialize(@$ThisFileInfo['tags']['id3v1'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @$ThisFileInfo['warning'])).'", '; + $SQLquery .= '"'.mysql_escape_string(@implode("\t", @$ThisFileInfo['error'])).'", '; + $SQLquery .= '"'.mysql_escape_string(trim(@$ThisFileInfo['audio']['encoder'].' '.@$ThisFileInfo['audio']['encoder_options'])).'", '; + $SQLquery .= '"'.mysql_escape_string(!empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : @$ThisFileInfo['mpeg']['audio']['VBR_method']).'", '; + $SQLquery .= '"'.mysql_escape_string(@$ThisFileInfo['replay_gain']['track']['volume']).'")'; + + } + flush(); + safe_mysql_query($SQLquery); + } + + } + + $SQLquery = 'OPTIMIZE TABLE `'.GETID3_DB_TABLE.'`'; + safe_mysql_query($SQLquery); + + echo '<hr>Done scanning!<hr>'; + +} elseif (!empty($_REQUEST['missingtrackvolume'])) { + + $MissingTrackVolumeFilesScanned = 0; + $MissingTrackVolumeFilesAdjusted = 0; + $MissingTrackVolumeFilesDeleted = 0; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`track_volume` = "0")'; + $SQLquery .= ' AND (`audio_bitrate` > "0")'; + $result = safe_mysql_query($SQLquery); + echo 'Scanning <span ID="missingtrackvolumeNowScanning">0</span> / '.number_format(mysql_num_rows($result)).' files for track volume information:<hr>'; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + echo '<script>if (document.getElementById("missingtrackvolumeNowScanning")) document.getElementById("missingtrackvolumeNowScanning").innerHTML = "'.number_format($MissingTrackVolumeFilesScanned++).'";</script>. '; + flush(); + if (file_exists($row['filename'])) { + + $ThisFileInfo = $getID3->analyze($row['filename']); + if (!empty($ThisFileInfo['replay_gain']['track']['volume'])) { + $MissingTrackVolumeFilesAdjusted++; + $SQLquery = 'UPDATE `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_escape_string($row['filename']).'")'; + safe_mysql_query($SQLquery); + } + + } else { + + $MissingTrackVolumeFilesDeleted++; + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_escape_string($row['filename']).'")'; + safe_mysql_query($SQLquery); + + } + } + echo '<hr>Scanned '.number_format($MissingTrackVolumeFilesScanned).' files with no track volume information.<br>'; + 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)<hr>'; + +} elseif (!empty($_REQUEST['deadfilescheck'])) { + + $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' GROUP BY `filename`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = safe_mysql_query($SQLquery); + $DupesDeleted = 0; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + if ($row['num'] <= 1) { + break; + } + echo '<br>'.FixTextFields($row['filename']).' (<font color="#FF9999">duplicate</font>)'; + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE `filename` LIKE "'.mysql_escape_string($row['filename']).'"'; + safe_mysql_query($SQLquery); + $DupesDeleted++; + } + if ($DupesDeleted > 0) { + echo '<hr>Deleted <b>'.number_format($DupesDeleted).'</b> duplicate filenames<hr>'; + } + + $SQLquery = 'SELECT `filename`, `filesize`, `LastModified`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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['LastModified']) { + if (abs(filemtime($row['filename']) - $row['LastModified']) != 3600) { + // off by exactly one hour == daylight savings time + $reason = 'last-modified time changed'; + } + } + + $thisdir = dirname($row['filename']); + if ($reason) { + + $totalremoved++; + echo '<br>'.FixTextFields($row['filename']).' (<font color="#FF9999">'.$reason.'</font>)'; + flush(); + $SQLquery = 'DELETE FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`filename` = "'.mysql_escape_string($row['filename']).'")'; + safe_mysql_query($SQLquery); + + } elseif ($thisdir != $previousdir) { + + echo '. '; + flush(); + + } + $previousdir = $thisdir; + } + + echo '<hr><b>'.number_format($totalremoved).' of '.number_format($totalchecked).' files in database no longer exist, or have been altered since last scan. Removed from database.</b><hr>'; + +} elseif (!empty($_REQUEST['encodedbydistribution'])) { + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + + $SQLquery = 'SELECT `filename`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`encoder_options` = "'.mysql_escape_string($_REQUEST['encodedbydistribution']).'")'; + $result = mysql_query($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 '<a href="'.$_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode('%').'">show all</a><br>'; + echo '<table border="1">'; + + $SQLquery = 'SELECT `filename`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $result = mysql_query($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 '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td></tr>'; + } + } + echo '</table>'; + + } else { + + $SQLquery = 'SELECT `encoder_options`, `comments_id3v2`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC'; + $result = mysql_query($SQLquery); + $EncodedBy = array(); + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + $CommentArray = unserialize($row['comments_id3v2']); + 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 '<a href="'.$_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode('%').'&m3u=1">.m3u version</a><br>'; + echo '<table border="1"><tr><th>m3u</th><th>Encoder Options</th><th>Encoded By (ID3v2)</th></tr>'; + foreach ($EncodedBy as $key => $value) { + echo '<tr><TD VALIGN="TOP"><a href="'.$_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode($key).'&showfiles=1&m3u=1">m3u</a></td>'; + echo '<TD VALIGN="TOP"><b>'.$key.'</b></td>'; + echo '<td><table border="0" WIDTH="100%">'; + arsort($value); + foreach ($value as $string => $count) { + echo '<tr><TD ALIGN="RIGHT" WIDTH="50"><i>'.number_format($count).'</i></td><td> </td>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode($string).'&showfiles=1">'.$string.'</a></td></tr>'; + } + echo '</table></td></tr>'; + } + echo '</table>'; + + } + +} elseif (!empty($_REQUEST['audiobitrates'])) { + + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true); + $BitrateDistribution = array(); + $SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`audio_bitrate` > 0)'; + $SQLquery .= ' GROUP BY `RoundBitrate`'; + $result = safe_mysql_query($SQLquery); + while ($row = mysql_fetch_array($result)) { + @$BitrateDistribution[getid3_mp3::ClosestStandardMP3Bitrate($row['RoundBitrate'] * 1000)] += $row['num']; // safe_inc + } + + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>Bitrate</th><th>Count</th></tr>'; + foreach ($BitrateDistribution as $Bitrate => $Count) { + echo '<tr>'; + echo '<TD ALIGN="RIGHT">'.round($Bitrate / 1000).' kbps</td>'; + echo '<TD ALIGN="RIGHT">'.number_format($Count).'</td>'; + echo '</tr>'; + } + echo '</table>'; + + +} elseif (!empty($_REQUEST['emptygenres'])) { + + $SQLquery = 'SELECT `fileformat`, `filename`, `genre`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`genre` = "")'; + $SQLquery .= ' OR (`genre` = "Unknown")'; + $SQLquery .= ' OR (`genre` = "Other")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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 '<a href="'.$_SERVER['PHP_SELF'].'?emptygenres='.urlencode($_REQUEST['emptygenres']).'&m3u=1">.m3u version</a><br>'; + $EmptyGenreCounter = 0; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>m3u</th><th>filename</th></tr>'; + while ($row = mysql_fetch_array($result)) { + if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) { + $EmptyGenreCounter++; + echo '<tr>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '</tr>'; + } + } + echo '</table>'; + echo '<b>'.number_format($EmptyGenreCounter).'</b> files with empty genres'; + + } + +} elseif (!empty($_REQUEST['nonemptycomments'])) { + + $SQLquery = 'SELECT `filename`, `comment`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`comment` <> "")'; + $SQLquery .= ' ORDER BY `comment` ASC'; + $result = safe_mysql_query($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 '<a href="'.$_SERVER['PHP_SELF'].'?nonemptycomments='.urlencode($_REQUEST['nonemptycomments']).'&m3u=1">.m3u version</a><br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>m3u</th><th>filename</th><th>comments</th></tr>'; + while ($row = mysql_fetch_array($result)) { + $NonEmptyCommentsCounter++; + echo '<tr>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + if (strlen(trim($row['comment'])) > 0) { + echo '<td>'.FixTextFields($row['comment']).'</td>'; + } else { + echo '<td><i>space</i></td>'; + } + echo '</tr>'; + } + echo '</table>'; + echo '<b>'.number_format($NonEmptyCommentsCounter).'</b> files with non-empty comments'; + + } + +} elseif (!empty($_REQUEST['trackzero'])) { + + $SQLquery = 'SELECT `filename`, `track`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`track` <> "")'; + $SQLquery .= ' AND ((`track` < "1")'; + $SQLquery .= ' OR (`track` > "99"))'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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 '<a href="'.$_SERVER['PHP_SELF'].'?trackzero='.urlencode($_REQUEST['trackzero']).'&m3u=1">.m3u version</a><br>'; + $TrackZeroCounter = 0; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>m3u</th><th>filename</th><th>track</th></tr>'; + while ($row = mysql_fetch_array($result)) { + if ((strlen($row['track']) > 0) && ($row['track'] < 1) || ($row['track'] > 99)) { + $TrackZeroCounter++; + echo '<tr>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td>'.FixTextFields($row['track']).'</td>'; + echo '</tr>'; + } + } + echo '</table>'; + echo '<b>'.number_format($TrackZeroCounter).'</b> files with track "zero"'; + + } + + +} elseif (!empty($_REQUEST['titlefeat'])) { + + $SQLquery = 'SELECT `filename`, `title`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`title` LIKE "%feat.%")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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 '<b>'.number_format(mysql_num_rows($result)).'</b> files with "feat." in the title (instead of the artist)<br><br>'; + echo '<a href="'.$_SERVER['PHP_SELF'].'?titlefeat='.urlencode($_REQUEST['titlefeat']).'&m3u=1">.m3u version</a><br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>m3u</th><th>filename</th><th>title</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td>'.eregi_replace('(feat\. .*)', '<b>\\1</b>', FixTextFields($row['title'])).'</td>'; + echo '</tr>'; + } + echo '</table>'; + + } + + +} elseif (!empty($_REQUEST['tracknoalbum'])) { + + $SQLquery = 'SELECT `filename`, `track`, `album`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`track` <> "")'; + $SQLquery .= ' AND (`album` = "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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 '<b>'.number_format(mysql_num_rows($result)).'</b> files with a track number, but no album<br><br>'; + echo '<a href="'.$_SERVER['PHP_SELF'].'?tracknoalbum='.urlencode($_REQUEST['tracknoalbum']).'&m3u=1">.m3u version</a><br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>m3u</th><th>filename</th><th>track</th><th>album</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td>'.FixTextFields($row['track']).'</td>'; + echo '<td>'.FixTextFields($row['album']).'</td>'; + echo '</tr>'; + } + echo '</table>'; + + } + + +} elseif (!empty($_REQUEST['synchronizetagsfrom']) && !empty($_REQUEST['filename'])) { + + echo 'Applying new tags from <b>'.$_REQUEST['synchronizetagsfrom'].'</b> in <b>'.FixTextFields($_REQUEST['filename']).'</b><ul>'; + $errors = array(); + if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) { + echo '<li>Sucessfully wrote tags</li>'; + } else { + echo '<li>Tag writing had errors: <ul><li>'.implode('</li><li>', $errors).'</li></ul></li>'; + } + echo '</ul>'; + + +} elseif (!empty($_REQUEST['unsynchronizedtags'])) { + + $NotOKfiles = 0; + $Autofixedfiles = 0; + $FieldsToCompare = array('title', 'artist', 'album', 'year', 'genre', 'comment', 'track'); + $TagsToCompare = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); + $ID3v1FieldLengths = array('title'=>30, 'artist'=>30, 'album'=>30, 'year'=>4, 'genre'=>99, 'comment'=>28); + if (strpos($_REQUEST['unsynchronizedtags'], '2') !== false) { + $TagsToCompare['id3v2'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], 'A') !== false) { + $TagsToCompare['ape'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], 'L') !== false) { + $TagsToCompare['lyrics3'] = true; + } + if (strpos($_REQUEST['unsynchronizedtags'], '1') !== false) { + $TagsToCompare['id3v1'] = true; + } + + echo '<a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags='.urlencode($_REQUEST['unsynchronizedtags']).'&autofix=1">Auto-fix empty tags</a><br><br>'; + echo '<div id="Autofixing"></div>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr>'; + echo '<th>View</th>'; + echo '<th>Filename</th>'; + echo '<th>Combined</th>'; + if ($TagsToCompare['id3v2']) { + echo '<th><a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags='.urlencode($_REQUEST['unsynchronizedtags']).'&autofix=1&autofixforcesource=id3v2&autofixforcedest=A1" TITLE="Auto-fix all tags to match ID3v2 contents" onClick="return confirm(\'Are you SURE you want to synchronize all tags to match ID3v2?\');">ID3v2</a></th>'; + } + if ($TagsToCompare['ape']) { + echo '<th><a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags='.urlencode($_REQUEST['unsynchronizedtags']).'&autofix=1&autofixforcesource=ape&autofixforcedest=21" TITLE="Auto-fix all tags to match APE contents" onClick="return confirm(\'Are you SURE you want to synchronize all tags to match APE?\');">APE</a></th>'; + } + if ($TagsToCompare['lyrics3']) { + echo '<th>Lyrics3</th>'; + } + if ($TagsToCompare['id3v1']) { + echo '<th><a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags='.urlencode($_REQUEST['unsynchronizedtags']).'&autofix=1&autofixforcesource=ape&autofixforcedest=2A" TITLE="Auto-fix all tags to match ID3v1 contents" onClick="return confirm(\'Are you SURE you want to synchronize all tags to match ID3v1?\');">ID3v1</a></th>'; + } + echo '</tr>'; + + $SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` = "mp3")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + $lastdir = ''; + while ($row = mysql_fetch_array($result)) { + set_time_limit(30); + if ($lastdir != dirname($row['filename'])) { + echo '<script>if (document.getElementById("Autofixing")) document.getElementById("Autofixing").innerHTML = "'.htmlentities($lastdir, ENT_QUOTES).'";</script>'; + flush(); + } + + $FileOK = true; + $Mismatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); + $SemiMatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false); + $EmptyTags = array('id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true); + + $Comments['all'] = @unserialize($row['comments_all']); + $Comments['id3v2'] = @unserialize($row['comments_id3v2']); + $Comments['ape'] = @unserialize($row['comments_ape']); + $Comments['lyrics3'] = @unserialize($row['comments_lyrics3']); + $Comments['id3v1'] = @unserialize($row['comments_id3v1']); + + if (isset($Comments['ape']['tracknumber'])) { + $Comments['ape']['track'] = $Comments['ape']['tracknumber']; + unset($Comments['ape']['tracknumber']); + } + if (!empty($Comments['all']['track'])) { + $besttrack = ''; + foreach ($Comments['all']['track'] as $key => $value) { + if (strlen($value) > strlen($besttrack)) { + $besttrack = $value; + } + } + $Comments['all']['track'] = array(0=>$besttrack); + } + + $ThisLine = '<tr>'; + $ThisLine .= '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">view</a></td>'; + $ThisLine .= '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + $tagvalues = ''; + foreach ($FieldsToCompare as $fieldname) { + $tagvalues .= $fieldname.' = '.@implode(" \n", @$Comments['all'][$fieldname])." \n"; + } + $ThisLine .= '<td><a href="'.$_SERVER['PHP_SELF'].'?synchronizetagsfrom=all&filename='.urlencode($row['filename']).'" TITLE="'.htmlentities(rtrim($tagvalues, "\n"), ENT_QUOTES).'" TARGET="retagwindow">all</a></td>'; + 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') && !getid3_id3v1::LookupGenreID(@$Comments['all'][$fieldname][0])) { + + // non-standard genres can never match, so just ignore + $tagvalues .= $fieldname.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + + } elseif ($fieldname == 'comment') { + + if (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.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + } + + } elseif ($fieldname == 'track') { + + // intval('01/20') == intval('1') + if (intval(@$Comments[$tagtype][$fieldname][0]) != intval(@$Comments['all'][$fieldname][0])) { + $tagvalues .= $fieldname.' = [['.@$Comments[$tagtype][$fieldname][0].']]'."\n"; + $Mismatched[$tagtype] = true; + $FileOK = false; + } else { + $tagvalues .= $fieldname.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + } + + } elseif (rtrim(substr(@$Comments[$tagtype][$fieldname][0], 0, 30)) != rtrim(substr(@$Comments['all'][$fieldname][0], 0, 30))) { + + $tagvalues .= $fieldname.' = [['.@$Comments[$tagtype][$fieldname][0].']]'."\n"; + if (strtolower(RemoveAccents(trim(substr(@$Comments[$tagtype][$fieldname][0], 0, 30)))) == strtolower(RemoveAccents(trim(substr(@$Comments['all'][$fieldname][0], 0, 30))))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + if (strlen(trim(@$Comments[$tagtype][$fieldname][0])) > 0) { + $EmptyTags[$tagtype] = false; + } + + } else { + + $tagvalues .= $fieldname.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + if (strlen(trim(@$Comments[$tagtype][$fieldname][0])) > 0) { + $EmptyTags[$tagtype] = false; + } + + } + + } elseif (($tagtype == 'ape') && ($fieldname == 'year')) { + + if ((@$Comments['ape']['date'][0] != @$Comments['all']['year'][0]) && (@$Comments['ape']['year'][0] != @$Comments['all']['year'][0])) { + + $tagvalues .= $fieldname.' = [['.@$Comments['ape']['date'][0].']]'."\n"; + $Mismatched[$tagtype] = true; + $FileOK = false; + if (strlen(trim(@$Comments['ape']['date'][0])) > 0) { + $EmptyTags[$tagtype] = false; + } + + } else { + + $tagvalues .= $fieldname.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + if (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.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + if (strlen(trim(@$Comments[$tagtype][$fieldname][0])) > 0) { + $EmptyTags[$tagtype] = false; + } + + } elseif (@$Comments[$tagtype][$fieldname][0] != @$Comments['all'][$fieldname][0]) { + + $tagvalues .= $fieldname.' = [['.@$Comments[$tagtype][$fieldname][0].']]'."\n"; + if (trim(strtolower(RemoveAccents(@$Comments[$tagtype][$fieldname][0]))) == trim(strtolower(RemoveAccents(@$Comments['all'][$fieldname][0])))) { + $SemiMatched[$tagtype] = true; + } else { + $Mismatched[$tagtype] = true; + } + $FileOK = false; + if (strlen(trim(@$Comments[$tagtype][$fieldname][0])) > 0) { + $EmptyTags[$tagtype] = false; + } + + } else { + + $tagvalues .= $fieldname.' = '.@$Comments[$tagtype][$fieldname][0]."\n"; + if (strlen(trim(@$Comments[$tagtype][$fieldname][0])) > 0) { + $EmptyTags[$tagtype] = false; + } + + } + } + + if ($EmptyTags[$tagtype]) { + $FileOK = false; + $ThisLine .= '<TD BGCOLOR="#0099CC">'; + } elseif ($SemiMatched[$tagtype]) { + $ThisLine .= '<TD BGCOLOR="#FF9999">'; + } elseif ($Mismatched[$tagtype]) { + $ThisLine .= '<TD BGCOLOR="#FF0000">'; + } else { + $ThisLine .= '<TD BGCOLOR="#00CC00">'; + } + $ThisLine .= '<a href="'.$_SERVER['PHP_SELF'].'?synchronizetagsfrom='.$tagtype.'&filename='.urlencode($row['filename']).'" TITLE="'.htmlentities(rtrim($tagvalues, "\n"), ENT_QUOTES).'" TARGET="retagwindow">'.$tagtype.'</a>'; + $ThisLine .= '</td>'; + } + } + $ThisLine .= '</tr>'; + + if (!$FileOK) { + $NotOKfiles++; + + echo '<script>if (document.getElementById("Autofixing")) document.getElementById("Autofixing").innerHTML = "'.htmlentities($row['filename'], ENT_QUOTES).'";</script>'; + 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 = (@$_REQUEST['autofixforcesource'] ? $_REQUEST['autofixforcesource'] : 'all'); + $TagsToSynch = (@$_REQUEST['autofixforcedest'] ? $_REQUEST['autofixforcedest'] : $TagsToSynch); + + $errors = array(); + if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) { + $Autofixedfiles++; + echo '<tr bgcolor="#00CC00">'; + } else { + echo '<tr bgcolor="#FF0000">'; + } + echo '<td> </th>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'" TITLE="'.FixTextFields(implode("\n", $errors)).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td><table border="0">'; + echo '<tr><td><b>'.$TagsToSynch.'</b></td></tr>'; + echo '</table></td></tr>'; + } + + } else { + + echo $ThisLine; + + } + } + } + + echo '</table><br>'; + echo '<script>if (document.getElementById("Autofixing")) document.getElementById("Autofixing").innerHTML = "";</script>'; + echo 'Found <b>'.number_format($NotOKfiles).'</b> 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(eregi_replace('[^A-Z]', '', $_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 `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + echo 'Files that do not match naming pattern: (<a href="?filenamepattern='.urlencode($_REQUEST['filenamepattern']).'&autofix=1">auto-fix</a>)<br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>view</th><th>Why</th><td><b>Actual filename</b><br>(click to play/edit file)</td><td><b>Correct filename (based on tags)</b>'.(!@$_REQUEST['autofix'] ? '<br>(click to rename file to this)' : '').'</td></tr>'; + $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 = eregi_replace('([ a-z]+)/([ a-z]+)', '\\1~\\2', $PatternFilename); + $PatternFilename = str_replace('/', '×', $PatternFilename); + + $PatternFilename = str_replace('?', '¿', $PatternFilename); + $PatternFilename = str_replace(' "', ' “', $PatternFilename); + $PatternFilename = str_replace('("', '(“', $PatternFilename); + $PatternFilename = str_replace('-"', '-“', $PatternFilename); + $PatternFilename = str_replace('" ', '” ', $PatternFilename.' '); + $PatternFilename = str_replace('"', '”', $PatternFilename); + $PatternFilename = str_replace(' ', ' ', $PatternFilename); + + + $ParenthesesPairs = array('()', '[]', '{}'); + foreach ($ParenthesesPairs as $pair) { + + // multiple remixes are stored tab-seperated in the database. + // change "{2000 Version\tSomebody Remix}" into "{2000 Version} {Somebody Remix}" + while (ereg('^(.*)'.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 = ereg_replace(preg_quote($pair), '', $PatternFilename); + + // "[01] - Title With No Artist.mp3" ==> "[01] Title With No Artist.mp3" + $PatternFilename = ereg_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, '</b>'.$ActualFilenameNoExt.'<b>', $PatternFilenameNoExt); + } else { + $ShortestNameLength = min(strlen($ActualFilenameNoExt), strlen($PatternFilenameNoExt)); + for ($DifferenceOffset = 0; $DifferenceOffset < $ShortestNameLength; $DifferenceOffset++) { + if ($ActualFilenameNoExt{$DifferenceOffset} !== $PatternFilenameNoExt{$DifferenceOffset}) { + break; + } + } + $DifferenceBoldedName = '</b>'.substr($PatternFilenameNoExt, 0, $DifferenceOffset).'<b>'.substr($PatternFilenameNoExt, $DifferenceOffset); + } + $DifferenceBoldedName .= (($actualExt == $patternExt) ? '</b>'.$patternExt.'<b>' : $patternExt); + + + echo '<tr>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">view</a></td>'; + echo '<td> '.$NotMatchedReasons.'</td>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">'.FixTextFields($ActualFilename).'</a></td>'; + + if (@$_REQUEST['autofix']) { + + $results = ''; + if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) { + echo '<TD BGCOLOR="#009900">'; + } else { + echo '<TD BGCOLOR="#FF0000">'; + } + echo '<b>'.$DifferenceBoldedName.'</b></td>'; + + + } else { + + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?filenamepattern='.urlencode($_REQUEST['filenamepattern']).'&renamefilefrom='.urlencode($row['filename']).'&renamefileto='.urlencode(dirname($row['filename']).'/'.$PatternFilename).'" TITLE="'.FixTextFields(basename($row['filename']))."\n".FixTextFields(basename($PatternFilename)).'" TARGET="renamewindow">'; + echo '<b>'.$DifferenceBoldedName.'</b></a></td>'; + + } + echo '</tr>'; + + $nonmatchingfilenames++; + } + } + echo '</table><br>'; + echo 'Found '.number_format($nonmatchingfilenames).' files that do not match naming pattern<br>'; + + +} elseif (!empty($_REQUEST['encoderoptionsdistribution'])) { + + if (isset($_REQUEST['showtagfiles'])) { + $SQLquery = 'SELECT `filename`, `encoder_options` FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysql_escape_string($_REQUEST['showtagfiles']).'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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 '<a href="'.$_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1">Show all Encoder Options</a><hr>'; + echo 'Files with Encoder Options <b>'.$_REQUEST['showtagfiles'].'</b>:<br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td>'.$row['encoder_options'].'</td>'; + echo '</tr>'; + } + echo '</table>'; + + } + + } elseif (!isset($_REQUEST['m3u'])) { + + $SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.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 = safe_mysql_query($SQLquery); + echo 'Files with Encoder Options:<br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>Encoder Options</th><th>Count</th><th>M3U</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td>'.$row['encoder_options'].'</td>'; + echo '<TD ALIGN="RIGHT"><a href="'.$_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1&showtagfiles='.($row['encoder_options'] ? urlencode($row['encoder_options']) : '').'">'.number_format($row['num']).'</a></td>'; + echo '<TD ALIGN="RIGHT"><a href="'.$_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1&showtagfiles='.($row['encoder_options'] ? urlencode($row['encoder_options']) : '').'&m3u=.m3u">m3u</a></td>'; + echo '</tr>'; + } + echo '</table><hr>'; + + } + +} elseif (!empty($_REQUEST['tagtypes'])) { + + if (!isset($_REQUEST['m3u'])) { + $SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `tags`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = safe_mysql_query($SQLquery); + echo 'Files with tags:<br>'; + echo '<table border="1" cellspacing="0" cellpadding="3">'; + echo '<tr><th>Tags</th><th>Count</th><th>M3U</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td>'.$row['tags'].'</td>'; + echo '<TD ALIGN="RIGHT"><a href="'.$_SERVER['PHP_SELF'].'?tagtypes=1&showtagfiles='.($row['tags'] ? urlencode($row['tags']) : '').'">'.number_format($row['num']).'</a></td>'; + echo '<TD ALIGN="RIGHT"><a href="'.$_SERVER['PHP_SELF'].'?tagtypes=1&showtagfiles='.($row['tags'] ? urlencode($row['tags']) : '').'&m3u=.m3u">m3u</a></td>'; + echo '</tr>'; + } + echo '</table><hr>'; + } + + if (isset($_REQUEST['showtagfiles'])) { + $SQLquery = 'SELECT `filename`, `tags` FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`tags` LIKE "'.mysql_escape_string($_REQUEST['showtagfiles']).'")'; + $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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 '<table border="1" cellspacing="0" cellpadding="3">'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td>'.$row['tags'].'</td>'; + echo '</tr>'; + } + echo '</table>'; + + } + } + + +} elseif (!empty($_REQUEST['md5datadupes'])) { + + $OtherFormats = ''; + $AVFormats = ''; + + $SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`md5_data` <> "")'; + $SQLquery .= ' GROUP BY `md5_data`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = safe_mysql_query($SQLquery); + while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { + set_time_limit(30); + + $filenames = array(); + $tags = array(); + $md5_data = array(); + $SQLquery = 'SELECT `fileformat`, `filename`, `tags`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`md5_data` = "'.mysql_escape_string($row['md5_data']).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result2 = safe_mysql_query($SQLquery); + while ($row2 = mysql_fetch_array($result2)) { + $thisfileformat = $row2['fileformat']; + $filenames[] = $row2['filename']; + $tags[] = $row2['tags']; + $md5_data[] = $row['md5_data']; + } + + $thisline = '<tr>'; + $thisline .= '<TD VALIGN="TOP" style="font-family: monospace;">'.implode('<br>', $md5_data).'</td>'; + $thisline .= '<TD VALIGN="TOP" NOWRAP>'.implode('<br>', $tags).'</td>'; + $thisline .= '<TD VALIGN="TOP">'.implode('<br>', $filenames).'</td>'; + $thisline .= '</tr>'; + + if (in_array($thisfileformat, $IgnoreNoTagFormats)) { + $OtherFormats .= $thisline; + } else { + $AVFormats .= $thisline; + } + } + echo 'Duplicated MD5_DATA (Audio/Video files):<table border="1" cellspacing="0" cellpadding="2">'; + echo $AVFormats.'</table><hr>'; + echo 'Duplicated MD5_DATA (Other files):<table border="1" cellspacing="0" cellpadding="2">'; + echo $OtherFormats.'</table><hr>'; + + +} 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 `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysql_escape_string($_REQUEST['m3uartist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysql_escape_string($_REQUEST['m3utitle']).'")'; + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result = safe_mysql_query($SQLquery); + while ($row = mysql_fetch_array($result)) { + echo WindowsShareSlashTranslate($row['filename'])."\n"; + } + exit; + + } + + $SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`artist` <> "")'; + $SQLquery .= ' AND (`title` <> "")'; + $SQLquery .= ' GROUP BY `artist`, `title`'.(@$_REQUEST['samemix'] ? ', `remix`' : ''); + $SQLquery .= ' ORDER BY `num` DESC, `artist` ASC, `title` ASC, `playtime_seconds` ASC, `remix` ASC'; + $result = safe_mysql_query($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 `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysql_escape_string($row['artist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysql_escape_string($row['title']).'")'; + if (@$_REQUEST['samemix']) { + $SQLquery .= ' AND (`remix` = "'.mysql_escape_string($row['remix']).'")'; + } + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result2 = safe_mysql_query($SQLquery); + while ($row2 = mysql_fetch_array($result2)) { + echo WindowsShareSlashTranslate($row2['filename'])."\n"; + } + } + exit; + + } else { + + echo 'Duplicated aritst + title: (<a href="'.$_SERVER['PHP_SELF'].'?artisttitledupes=1&samemix=1">Identical Mix/Version only</a>)<br>'; + echo '(<a href="'.$_SERVER['PHP_SELF'].'?artisttitledupes=1&m3u=.m3u">.m3u version</a>)<br>'; + echo '<table border="1" cellspacing="0" cellpadding="2">'; + echo '<tr><th colspan="3"> </th><th>Artist</th><th>Title</th><th>Version</th><th> </th><th> </th><th>Filename</th></tr>'; + + while (($row = mysql_fetch_array($result)) && ($row['num'] > 1)) { + $uniquetitles++; + set_time_limit(30); + + $filenames = array(); + $artists = array(); + $titles = array(); + $remixes = array(); + $bitrates = array(); + $playtimes = array(); + $SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`artist` = "'.mysql_escape_string($row['artist']).'")'; + $SQLquery .= ' AND (`title` = "'.mysql_escape_string($row['title']).'")'; + $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC'; + $result2 = safe_mysql_query($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[] = '<B'.($row2['encoder_options'] ? ' style="text-decoration: underline; cursor: help;" TITLE="'.$row2['encoder_options'] : '').'">'.BitrateText($row2['audio_bitrate'] / 1000).'</b>'; + } else { + $bitrates[] = BitrateText($row2['audio_bitrate'] / 1000); + } + $playtimes[] = getid3_lib::PlaytimeString($row2['playtime_seconds']); + } + + echo '<tr>'; + echo '<TD NOWRAP VALIGN="TOP">'; + foreach ($filenames as $file) { + echo '<a href="demo.browse.php?deletefile='.urlencode($file).'&noalert=1" onClick="return confirm(\'Are you sure you want to delete '.addslashes($file).'? \n(this action cannot be un-done)\');" TITLE="Permanently delete '."\n".FixTextFields($file)."\n".'" TARGET="deletedupewindow">delete</a><br>'; + } + echo '</td>'; + echo '<TD NOWRAP VALIGN="TOP">'; + foreach ($filenames as $file) { + echo '<a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($file).'">play</a><br>'; + } + echo '</td>'; + echo '<TD VALIGN="MIDDLE" ALIGN="CENTER" ><a href="'.$_SERVER['PHP_SELF'].'?artisttitledupes=1&m3uartist='.urlencode($artists[0]).'&m3utitle='.urlencode($titles[0]).'">play all</a></td>'; + echo '<TD VALIGN="TOP" NOWRAP>'.implode('<br>', $artists).'</td>'; + echo '<TD VALIGN="TOP" NOWRAP>'.implode('<br>', $titles).'</td>'; + echo '<TD VALIGN="TOP" NOWRAP>'.implode('<br>', $remixes).'</td>'; + echo '<TD VALIGN="TOP" NOWRAP ALIGN="RIGHT">'.implode('<br>', $bitrates).'</td>'; + echo '<TD VALIGN="TOP" NOWRAP ALIGN="RIGHT">'.implode('<br>', $playtimes).'</td>'; + + echo '<TD VALIGN="TOP" NOWRAP ALIGN="LEFT"><table border="0" cellspacing="0" cellpadding="0">'; + foreach ($filenames as $file) { + echo '<tr><TD NOWRAP ALIGN="RIGHT"><a href="demo.browse.php?filename='.rawurlencode($file).'"><span style="color: #339966;">'.dirname($file).'/</span>'.basename($file).'</a></td></tr>'; + } + echo '</table></td>'; + + echo '</tr>'; + } + + } + echo '</table>'; + echo number_format($uniquefiles).' files with '.number_format($uniquetitles).' unique <i>aritst + title</i><br>'; + echo '<hr>'; + +} elseif (!empty($_REQUEST['filetypelist'])) { + + list($fileformat, $audioformat) = explode('|', $_REQUEST['filetypelist']); + $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` = "'.mysql_escape_string($fileformat).'")'; + $SQLquery .= ' AND (`audio_dataformat` = "'.mysql_escape_string($audioformat).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + echo 'Files of format <b>'.$fileformat.'.'.$audioformat.'</b>:<table border="1" cellspacing="0" cellpadding="4">'; + echo '<tr><th>file</th><th>audio</th><th>filename</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td>'.$row['fileformat'].'</td>'; + echo '<td>'.$row['audio_dataformat'].'</td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '</tr>'; + } + echo '</table><hr>'; + +} elseif (!empty($_REQUEST['trackinalbum'])) { + + $SQLquery = 'SELECT `filename`, `album`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`album` LIKE "% [%")'; + $SQLquery .= ' ORDER BY `album` ASC, `filename` ASC'; + $result = safe_mysql_query($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 '<hr>'.FixTextFields($row['filename']).'<br>'; + echo '<i>'.$Album.'</i> (track #'.$Track.')<br>'; + echo '<b>ID3v2:</b> '.(RemoveID3v2($row['filename'], false) ? 'removed' : 'REMOVAL FAILED!').', '; + echo '<b>ID3v1:</b> '.(WriteID3v1($row['filename'], @$ThisFileInfo['comments']['title'][0], @$ThisFileInfo['comments']['artist'][0], $Album, @$ThisFileInfo['comments']['year'][0], @$ThisFileInfo['comments']['comment'][0], @$ThisFileInfo['comments']['genreid'][0], $Track, false) ? 'updated' : 'UPDATE FAILED').'<br>'; + } else { + echo ' . '; + } + + } else { + + echo '<hr>FAILED<br>'.FixTextFields($row['filename']).'<hr>'; + + } + flush(); + } + + } else { + + echo '<b>'.number_format(mysql_num_rows($result)).'</b> files with <b>[??]</b>-format track numbers in album field:<br>'; + if (mysql_num_rows($result) > 0) { + echo '(<a href="'.$_SERVER['PHP_SELF'].'?trackinalbum=1&m3u=.m3u">.m3u version</a>)<br>'; + echo '<a href="'.$_SERVER['PHP_SELF'].'?trackinalbum=1&autofix=1">Try to auto-fix</a><br>'; + echo '<table border="1" cellspacing="0" cellpadding="4">'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td>'.$row['album'].'</td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '</tr>'; + } + echo '</table>'; + } + echo '<hr>'; + + } + +} elseif (!empty($_REQUEST['fileextensions'])) { + + $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + $invalidextensionfiles = 0; + $invalidextensionline = '<table border="1" cellspacing="0" cellpadding="4">'; + $invalidextensionline .= '<tr><th>file</th><th>audio</th><th>video</th><th>tags</th><th>actual</th><th>correct</th><th>filename</th></tr>'; + 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 .= '<tr>'; + $invalidextensionline .= '<td>'.$row['fileformat'].'</td>'; + $invalidextensionline .= '<td>'.$row['audio_dataformat'].'</td>'; + $invalidextensionline .= '<td>'.$row['video_dataformat'].'</td>'; + $invalidextensionline .= '<td>'.$row['tags'].'</td>'; + $invalidextensionline .= '<td>'.$actualextension.'</td>'; + $invalidextensionline .= '<td>'.implode('; ', $acceptableextensions).'</td>'; + $invalidextensionline .= '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + $invalidextensionline .= '</tr>'; + } + } + $invalidextensionline .= '</table><hr>'; + echo number_format($invalidextensionfiles).' files with incorrect filename extension:<br>'; + echo $invalidextensionline; + +} elseif (isset($_REQUEST['genredistribution'])) { + + if (!empty($_REQUEST['m3u'])) { + + header('Content-type: audio/x-mpegurl'); + echo '#EXTM3U'."\n"; + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.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 = safe_mysql_query($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 `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")'; + $SQLquery .= ' GROUP BY `genre`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = safe_mysql_query($SQLquery); + getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true); + echo '<table border="1" cellspacing="0" cellpadding="4">'; + echo '<tr><th>Count</th><th>Genre</th><th>m3u</th></tr>'; + while ($row = mysql_fetch_array($result)) { + $GenreID = getid3_id3v1::LookupGenreID($row['genre']); + if (is_numeric($GenreID)) { + echo '<tr bgcolor="#00FF00;">'; + } else { + echo '<tr bgcolor="#FF9999;">'; + } + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?genredistribution='.urlencode($row['genre']).'">'.number_format($row['num']).'</a></td>'; + echo '<TD NOWRAP>'.str_replace("\t", '<br>', $row['genre']).'</td>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3u=.m3u&genredistribution='.urlencode($row['genre']).'">.m3u</a></td>'; + echo '</tr>'; + } + echo '</table><hr>'; + + } else { + + $SQLquery = 'SELECT `filename`, `genre`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`genre` LIKE "'.mysql_escape_string($_REQUEST['genredistribution']).'")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($SQLquery); + echo '<a href="'.$_SERVER['PHP_SELF'].'?genredistribution='.urlencode('%').'">All Genres</a><br>'; + echo '<table border="1" cellspacing="0" cellpadding="4">'; + echo '<tr><th>Genre</th><th>m3u</th><th>Filename</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<TD NOWRAP>'.str_replace("\t", '<br>', $row['genre']).'</td>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '</tr>'; + } + echo '</table><hr>'; + + } + + + } + +} elseif (!empty($_REQUEST['formatdistribution'])) { + + $SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`'; + $SQLquery .= ' ORDER BY `num` DESC'; + $result = safe_mysql_query($SQLquery); + echo 'File format distribution:<table border="1" cellspacing="0" cellpadding="4">'; + echo '<tr><th>Number</th><th>Format</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<TD ALIGN="RIGHT">'.number_format($row['num']).'</td>'; + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?filetypelist='.$row['fileformat'].'|'.$row['audio_dataformat'].'">'.($row['fileformat'] ? $row['fileformat'] : '<i>unknown</i>').(($row['audio_dataformat'] && ($row['audio_dataformat'] != $row['fileformat'])) ? '.'.$row['audio_dataformat'] : '').'</a></td>'; + echo '</tr>'; + } + echo '</table><hr>'; + +} elseif (!empty($_REQUEST['errorswarnings'])) { + + $SQLquery = 'SELECT `filename`, `error`, `warning`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`error` <> "")'; + $SQLquery .= ' OR (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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:<br>'; + echo '(<a href="'.$_SERVER['PHP_SELF'].'?errorswarnings=1&m3u=.m3u">.m3u version</a>)<br>'; + echo '<table border="1" cellspacing="0" cellpadding="4">'; + echo '<tr><th>Filename</th><th>Error</th><th>Warning</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td>'; + echo '<td>'.(!empty($row['error']) ? '<li>'.str_replace("\t", '<li>', FixTextFields($row['error'])).'</li>' : ' ').'</td>'; + echo '<td>'.(!empty($row['warning']) ? '<li>'.str_replace("\t", '<li>', FixTextFields($row['warning'])).'</li>' : ' ').'</td>'; + echo '</tr>'; + } + } + echo '</table><hr>'; + +} 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 `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` = "mp3")'; + $SQLquery .= ' AND (`warning` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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() ? '<span style="color: #009900;">fixed - ' : '<span style="color: #FF0000;">error - '); + } else { + echo '<span style="color: #0000FF;">No error? - '; + } + echo '['.++$rowcounter.' / '.$totaltofix.'] '; + echo FixTextFields($row['filename']).'</span><br>'; + flush(); + } + +} elseif (!empty($_REQUEST['vbrmethod'])) { + + if ($_REQUEST['vbrmethod'] == '1') { + + $SQLquery = 'SELECT COUNT(*) AS `num`, `vbr_method`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' GROUP BY `vbr_method`'; + $SQLquery .= ' ORDER BY `vbr_method`'; + $result = safe_mysql_query($SQLquery); + echo 'VBR methods:<table border="1" cellspacing="0" cellpadding="4">'; + echo '<tr><th>Count</th><th>VBR Method</th></tr>'; + while ($row = mysql_fetch_array($result)) { + echo '<tr>'; + echo '<TD ALIGN="RIGHT">'.FixTextFields(number_format($row['num'])).'</td>'; + if ($row['vbr_method']) { + echo '<td><a href="'.$_SERVER['PHP_SELF'].'?vbrmethod='.$row['vbr_method'].'">'.FixTextFields($row['vbr_method']).'</a></td>'; + } else { + echo '<td><i>CBR</i></td>'; + } + echo '</tr>'; + } + echo '</table>'; + + } else { + + $SQLquery = 'SELECT `filename`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`vbr_method` = "'.mysql_escape_string($_REQUEST['vbrmethod']).'")'; + $result = safe_mysql_query($SQLquery); + echo number_format(mysql_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":<table border="1" cellspacing="0" cellpadding="3">'; + while ($row = mysql_fetch_array($result)) { + echo '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']).'">m3u</a></td>'; + echo '<td><a href="demo.browse.php?filename='.rawurlencode($row['filename']).'">'.FixTextFields($row['filename']).'</a></td></tr>'; + } + echo '</table>'; + + } + echo '<hr>'; + +} elseif (!empty($_REQUEST['correctcase'])) { + + $SQLquery = 'SELECT `filename`, `fileformat`'; + $SQLquery .= ' FROM `'.GETID3_DB_TABLE.'`'; + $SQLquery .= ' WHERE (`fileformat` <> "")'; + $SQLquery .= ' ORDER BY `filename` ASC'; + $result = safe_mysql_query($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)<hr>'; + echo '<PRE>'; + $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 '</PRE>'; + echo '<hr>'; + +} + +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 (ereg('^[\'A-Za-z0-9À-ÿ]$', $string{$i - 1})) { + $string{$i} = strtolower($string{$i}); + } else { + $string{$i} = strtoupper($string{$i}); + } + } + + static $LowerCaseWords = array('vs.', 'feat.'); + static $UpperCaseWords = array('DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\''); + + $OutputListOfWords = array(); + $ListOfWords = explode(' ', $string); + foreach ($ListOfWords as $ThisWord) { + if (in_array(strtolower(str_replace('(', '', $ThisWord)), $LowerCaseWords)) { + $ThisWord = strtolower($ThisWord); + } elseif (in_array(strtoupper(str_replace('(', '', $ThisWord)), $UpperCaseWords)) { + $ThisWord = strtoupper($ThisWord); + } elseif ((substr($ThisWord, 0, 2) == 'Mc') && (strlen($ThisWord) > 2)) { + $ThisWord{2} = strtoupper($ThisWord{2}); + } elseif ((substr($ThisWord, 0, 3) == 'Mac') && (strlen($ThisWord) > 3)) { + $ThisWord{3} = strtoupper($ThisWord{3}); + } + $OutputListOfWords[] = $ThisWord; + } + $UCstring = implode(' ', $OutputListOfWords); + $UCstring = str_replace(' From “', ' from “', $UCstring); + $UCstring = str_replace(' \'n\' ', ' \'N\' ', $UCstring); + + return $UCstring; +} + + + +echo '<hr><form action="'.FixTextFields($_SERVER['PHP_SELF']).'">'; +echo '<b>Warning:</b> Scanning a new directory will erase all previous entries in the database!<br>'; +echo 'Directory: <input type="text" name="scan" size="50" value="'.FixTextFields(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : '').'"> '; +echo '<input type="submit" value="Go" onClick="return confirm(\'Are you sure you want to erase all entries in the database and start scanning again?\');">'; +echo '</form>'; +echo '<hr><form action="'.FixTextFields($_SERVER['PHP_SELF']).'">'; +echo 'Re-scanning a new directory will only add new, previously unscanned files into the list (and not erase the database).<br>'; +echo 'Directory: <input type="text" name="newscan" size="50" value="'.FixTextFields(!empty($_REQUEST['newscan']) ? $_REQUEST['newscan'] : '').'"> '; +echo '<input type="SUBMIT" value="Go">'; +echo '</form><hr>'; +echo '<ul>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?deadfilescheck=1">Remove deleted or changed files from database</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?md5datadupes=1">List files with identical MD5_DATA values</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?artisttitledupes=1">List files with identical artist + title</a> (<a href="'.$_SERVER['PHP_SELF'].'?artisttitledupes=1&samemix=1">same mix only</a>)</li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?fileextensions=1">File with incorrect file extension</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?formatdistribution=1">File Format Distribution</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?audiobitrates=1">Audio Bitrate Distribution</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?vbrmethod=1">VBR_Method Distribution</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?tagtypes=1">Tag Type Distribution</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?genredistribution='.urlencode('%').'">Genre Distribution</a></li>'; +//echo '<li><a href="'.$_SERVER['PHP_SELF'].'?missingtrackvolume=1">Scan for missing track volume information (update database from pre-v1.7.0b5)</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1">Encoder Options Distribution</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode('%').'">Encoded By (ID3v2) Distribution</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?trackinalbum=1">Track number in Album field</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?tracknoalbum=1">Track number, but no Album</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?titlefeat=1">"feat." in Title field</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?emptygenres=1">Blank genres</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?trackzero=1">Track "zero"</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?nonemptycomments=1">non-empty comments</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags=2A1">Tags that are not synchronized</a> (<a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags=2A1&autofix=1">autofix</a>)</li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?filenamepattern='.urlencode('[N] A - T {R}').'">Filenames that don\'t match pattern</a> (<a href="?filenamepattern='.urlencode('[N] A - T {R}').'&autofix=1">auto-fix</a>)</li>'; +//echo '<li><a href="'.$_SERVER['PHP_SELF'].'?filenamepattern='.urlencode('A - T').'">Filenames that don\'t match pattern</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?correctcase=1">Correct filename case (Win/DOS)</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?fixid3v1padding=1">Fix ID3v1 invalid padding</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?errorswarnings=1">Files with Errors and/or Warnings</a></li>'; +echo '<li><a href="'.$_SERVER['PHP_SELF'].'?rescanerrors=1">Re-scan only files with Errors and/or Warnings</a></li>'; +echo '</ul>'; + +$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 `'.GETID3_DB_TABLE.'`'; +$result = mysql_query($SQLquery); +if ($row = mysql_fetch_array($result)) { + echo '<hr><b>Currently in the database:</b><TABLE>'; + echo '<tr><TH ALIGN="LEFT">Total Files</th><td>'.number_format($row['TotalFiles']).'</td></tr>'; + echo '<tr><TH ALIGN="LEFT">Total Filesize</th><td>'.number_format($row['TotalFilesize'] / 1048576).' MB</td></tr>'; + echo '<tr><TH ALIGN="LEFT">Total Playtime</th><td>'.number_format($row['TotalPlaytime'] / 3600, 1).' hours</td></tr>'; + echo '<tr><TH ALIGN="LEFT">Average Filesize</th><td>'.number_format($row['AvgFilesize'] / 1048576, 1).' MB</td></tr>'; + echo '<tr><TH ALIGN="LEFT">Average Playtime</th><td>'.getid3_lib::PlaytimeString($row['AvgPlaytime']).'</td></tr>'; + echo '<tr><TH ALIGN="LEFT">Average Bitrate</th><td>'.BitrateText($row['AvgBitrate'] / 1000, 1).'</td></tr>'; + echo '</table>'; +} + +?> +</BODY> +</HTML>
\ No newline at end of file diff --git a/getid3/demos/demo.simple.php b/getid3/demos/demo.simple.php new file mode 100644 index 0000000..db937f1 --- /dev/null +++ b/getid3/demos/demo.simple.php @@ -0,0 +1,53 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.simple.php - part of getID3() // +// Sample script for scanning a single directory and // +// displaying a few pieces of information for each file // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +echo '<HTML><HEAD>'; +echo '<TITLE>getID3() - /demo/demo.simple.php (sample script)</TITLE>'; +echo '<STYLE>BODY,TD,TH { font-family: sans-serif; font-size: 9pt; }</STYLE>'; +echo '</HEAD><BODY>'; + + +// include getID3() library (can be in a different directory if full path is specified) +require_once('../getid3/getid3.php'); + +// Initialize getID3 engine +$getID3 = new getID3; + +$DirectoryToScan = '/change/to/directory/you/want/to/scan'; // change to whatever directory you want to scan +$dir = opendir($DirectoryToScan); +echo '<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="3">'; +echo '<TR><TH>Filename</TH><TH>Artist</TH><TH>Title</TH><TH>Bitrate</TH><TH>Playtime</TH></TR>'; +while (($file = readdir($dir)) !== false) { + $FullFileName = realpath($DirectoryToScan.'/'.$file); + if (is_file($FullFileName)) { + set_time_limit(30); + + $ThisFileInfo = $getID3->analyze($FullFileName); + + getid3_lib::CopyTagsToComments($ThisFileInfo); + + // output desired information in whatever format you want + echo '<TR>'; + echo '<TD>'.$ThisFileInfo['filenamepath'].'</TD>'; + echo '<TD>'.(!empty($ThisFileInfo['comments_html']['artist']) ? implode('<BR>', $ThisFileInfo['comments_html']['artist']) : ' ').'</TD>'; + echo '<TD>'.(!empty($ThisFileInfo['comments_html']['title']) ? implode('<BR>', $ThisFileInfo['comments_html']['title']) : ' ').'</TD>'; + echo '<TD ALIGN="RIGHT">'.(!empty($ThisFileInfo['audio']['bitrate']) ? round($ThisFileInfo['audio']['bitrate'] / 1000).' kbps' : ' ').'</TD>'; + echo '<TD ALIGN="RIGHT">'.(!empty($ThisFileInfo['playtime_string']) ? $ThisFileInfo['playtime_string'] : ' ').'</TD>'; + echo '</TR>'; + } +} + +?> +</BODY> +</HTML>
\ No newline at end of file diff --git a/getid3/demos/demo.simple.write.php b/getid3/demos/demo.simple.write.php new file mode 100644 index 0000000..468984e --- /dev/null +++ b/getid3/demos/demo.simple.write.php @@ -0,0 +1,54 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.simple.write.php - part of getID3() // +// Sample script showing basic syntax for writing tags // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +$TaggingFormat = 'UTF-8'; + +require_once('../getid3/getid3.php'); +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array('encoding'=>$TaggingFormat)); + +require_once('../getid3/write.php'); +// Initialize getID3 tag-writing module +$tagwriter = new getid3_writetags; +//$tagwriter->filename = '/path/to/file.mp3'; +$tagwriter->filename = 'd:/file.mp3'; +$tagwriter->tagformats = array('id3v1', 'id3v2.3'); + +// set various options (optional) +$tagwriter->overwrite_tags = true; +$tagwriter->tag_encoding = $TaggingFormat; +$tagwriter->remove_other_tags = true; + +// populate data array +$TagData['title'][] = 'My Song'; +$TagData['artist'][] = 'The Artist'; +$TagData['album'][] = 'Greatest Hits'; +$TagData['year'][] = '2004'; +$TagData['genre'][] = 'Rock'; +$TagData['comment'][] = 'excellent!'; +$TagData['track'][] = '04/16'; + +$tagwriter->tag_data = $TagData; + +// write tags +if ($tagwriter->WriteTags()) { + echo 'Successfully wrote tags<br>'; + if (!empty($tagwriter->warnings)) { + echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings); + } +} else { + echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors); +} + +?>
\ No newline at end of file diff --git a/getid3/demos/demo.write.php b/getid3/demos/demo.write.php new file mode 100644 index 0000000..4a878ec --- /dev/null +++ b/getid3/demos/demo.write.php @@ -0,0 +1,267 @@ +<?php +///////////////////////////////////////////////////////////////// +/// getID3() by James Heinrich <info@getid3.org> // +// available at http://getid3.sourceforge.net // +// or http://www.getid3.org // +///////////////////////////////////////////////////////////////// +// // +// /demo/demo.write.php - part of getID3() // +// sample script for demonstrating writing ID3v1 and ID3v2 // +// tags for MP3, or Ogg comment tags for Ogg Vorbis // +// See readme.txt for more details // +// /// +///////////////////////////////////////////////////////////////// + +$TaggingFormat = 'UTF-8'; + +header('Content-Type: text/html; charset='.$TaggingFormat); +echo '<HTML><HEAD><TITLE>getID3() - Sample tag writer</TITLE></HEAD><BODY>'; + +require_once('../getid3/getid3.php'); +// Initialize getID3 engine +$getID3 = new getID3; +$getID3->setOption(array('encoding'=>$TaggingFormat)); + +getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true); + +$browsescriptfilename = 'demo.browse.php'; + +function FixTextFields($text) { + return htmlentities(getid3_lib::SafeStripSlashes($text), ENT_QUOTES); +} + +$Filename = (isset($_REQUEST['Filename']) ? getid3_lib::SafeStripSlashes($_REQUEST['Filename']) : ''); + + + +if (isset($_POST['WriteTags'])) { + + $TagFormatsToWrite = (isset($_POST['TagFormatsToWrite']) ? $_POST['TagFormatsToWrite'] : array()); + if (!empty($TagFormatsToWrite)) { + echo 'starting to write tag(s)<BR>'; + + $tagwriter = new getid3_writetags; + $tagwriter->filename = $Filename; + $tagwriter->tagformats = $TagFormatsToWrite; + $tagwriter->overwrite_tags = true; + $tagwriter->tag_encoding = $TaggingFormat; + if (!empty($_POST['remove_other_tags'])) { + $tagwriter->remove_other_tags = true; + } + + $commonkeysarray = array('Title', 'Artist', 'Album', 'Year', 'Comment'); + foreach ($commonkeysarray as $key) { + if (!empty($_POST[$key])) { + $TagData[strtolower($key)][] = getid3_lib::SafeStripSlashes($_POST[$key]); + } + } + if (!empty($_POST['Genre'])) { + $TagData['genre'][] = getid3_lib::SafeStripSlashes($_POST['Genre']); + } + if (!empty($_POST['GenreOther'])) { + $TagData['genre'][] = getid3_lib::SafeStripSlashes($_POST['GenreOther']); + } + if (!empty($_POST['Track'])) { + $TagData['track'][] = getid3_lib::SafeStripSlashes($_POST['Track'].(!empty($_POST['TracksTotal']) ? '/'.$_POST['TracksTotal'] : '')); + } + + if (!empty($_FILES['userfile']['tmp_name'])) { + if (in_array('id3v2.4', $tagwriter->tagformats) || in_array('id3v2.3', $tagwriter->tagformats) || in_array('id3v2.2', $tagwriter->tagformats)) { + if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { + if ($fd = @fopen($_FILES['userfile']['tmp_name'], 'rb')) { + $APICdata = fread($fd, filesize($_FILES['userfile']['tmp_name'])); + fclose ($fd); + + list($APIC_width, $APIC_height, $APIC_imageTypeID) = GetImageSize($_FILES['userfile']['tmp_name']); + $imagetypes = array(1=>'gif', 2=>'jpeg', 3=>'png'); + if (isset($imagetypes[$APIC_imageTypeID])) { + + $TagData['attached_picture'][0]['data'] = $APICdata; + $TagData['attached_picture'][0]['picturetypeid'] = $_POST['APICpictureType']; + $TagData['attached_picture'][0]['description'] = $_FILES['userfile']['name']; + $TagData['attached_picture'][0]['mime'] = 'image/'.$imagetypes[$APIC_imageTypeID]; + + } else { + echo '<B>invalid image format (only GIF, JPEG, PNG)</B><BR>'; + } + } else { + echo '<B>cannot open '.$_FILES['userfile']['tmp_name'].'</B><BR>'; + } + } else { + echo '<B>!is_uploaded_file('.$_FILES['userfile']['tmp_name'].')</B><BR>'; + } + } else { + echo '<B>WARNING:</B> Can only embed images for ID3v2<BR>'; + } + } + + $tagwriter->tag_data = $TagData; + if ($tagwriter->WriteTags()) { + echo 'Successfully wrote tags<BR>'; + if (!empty($tagwriter->warnings)) { + echo 'There were some warnings:<BLOCKQUOTE STYLE="background-color:#FFCC33; padding: 10px;">'.implode('<BR><BR>', $tagwriter->warnings).'</BLOCKQUOTE>'; + } + } else { + echo 'Failed to write tags!<BLOCKQUOTE STYLE="background-color:#FF9999; padding: 10px;">'.implode('<BR><BR>', $tagwriter->errors).'</BLOCKQUOTE>'; + } + + } else { + + echo 'WARNING: no tag formats selected for writing - nothing written'; + + } + echo '<HR>'; + +} + + +echo '<H4>Sample tag editor/writer</H4>'; +echo '<A HREF="'.$browsescriptfilename.'?listdirectory='.rawurlencode(realpath(dirname($Filename))).'">Browse current directory</A><BR>'; +if (!empty($Filename)) { + echo '<A HREF="'.$_SERVER['PHP_SELF'].'">Start Over</A><BR><BR>'; + echo '<TABLE BORDER="3" CELLSPACING="0" CELLPADDING="4"><FORM ACTION="'.$_SERVER['PHP_SELF'].'" METHOD="POST" ENCTYPE="multipart/form-data">'; + echo '<TR><TD ALIGN="RIGHT"><B>Filename: </B></TD><TD><INPUT TYPE="HIDDEN" NAME="Filename" VALUE="'.FixTextFields($Filename).'"><A HREF="'.$browsescriptfilename.'?filename='.rawurlencode($Filename).'" TARGET="_blank">'.$Filename.'</A></TD></TR>'; + if (file_exists($Filename)) { + + // Initialize getID3 engine + $getID3 = new getID3; + $OldThisFileInfo = $getID3->analyze($Filename); + getid3_lib::CopyTagsToComments($OldThisFileInfo); + + switch ($OldThisFileInfo['fileformat']) { + case 'mp3': + case 'mp2': + case 'mp1': + $ValidTagTypes = array('id3v1', 'id3v2.3', 'ape'); + break; + + case 'mpc': + $ValidTagTypes = array('ape'); + break; + + case 'ogg': + if (@$OldThisFileInfo['audio']['dataformat'] == 'flac') { + //$ValidTagTypes = array('metaflac'); + // metaflac doesn't (yet) work with OggFLAC files + $ValidTagTypes = array(); + } else { + $ValidTagTypes = array('vorbiscomment'); + } + break; + + case 'flac': + $ValidTagTypes = array('metaflac'); + break; + + case 'real': + $ValidTagTypes = array('real'); + break; + + default: + $ValidTagTypes = array(); + break; + } + echo '<TR><TD ALIGN="RIGHT"><B>Title</B></TD> <TD><INPUT TYPE="TEXT" SIZE="40" NAME="Title" VALUE="'.FixTextFields(@implode(', ', @$OldThisFileInfo['comments']['title'])).'"></TD></TR>'; + echo '<TR><TD ALIGN="RIGHT"><B>Artist</B></TD><TD><INPUT TYPE="TEXT" SIZE="40" NAME="Artist" VALUE="'.FixTextFields(@implode(', ', @$OldThisFileInfo['comments']['artist'])).'"></TD></TR>'; + echo '<TR><TD ALIGN="RIGHT"><B>Album</B></TD> <TD><INPUT TYPE="TEXT" SIZE="40" NAME="Album" VALUE="'.FixTextFields(@implode(', ', @$OldThisFileInfo['comments']['album'])).'"></TD></TR>'; + echo '<TR><TD ALIGN="RIGHT"><B>Year</B></TD> <TD><INPUT TYPE="TEXT" SIZE="4" NAME="Year" VALUE="'.FixTextFields(@implode(', ', @$OldThisFileInfo['comments']['year'])).'"></TD></TR>'; + + $TracksTotal = ''; + $TrackNumber = ''; + if (!empty($OldThisFileInfo['comments']['tracknumber']) && is_array($OldThisFileInfo['comments']['tracknumber'])) { + $RawTrackNumberArray = $OldThisFileInfo['comments']['tracknumber']; + } elseif (!empty($OldThisFileInfo['comments']['track']) && is_array($OldThisFileInfo['comments']['track'])) { + $RawTrackNumberArray = $OldThisFileInfo['comments']['track']; + } else { + $RawTrackNumberArray = array(); + } + foreach ($RawTrackNumberArray as $key => $value) { + if (strlen($value) > strlen($TrackNumber)) { + // ID3v1 may store track as "3" but ID3v2/APE would store as "03/16" + $TrackNumber = $value; + } + } + if (strstr($TrackNumber, '/')) { + list($TrackNumber, $TracksTotal) = explode('/', $TrackNumber); + } + echo '<TR><TD ALIGN="RIGHT"><B>Track</B></TD><TD><INPUT TYPE="TEXT" SIZE="2" NAME="Track" VALUE="'.FixTextFields($TrackNumber).'"> of <INPUT TYPE="TEXT" SIZE="2" NAME="TracksTotal" VALUE="'.FixTextFields($TracksTotal).'"></TD></TR>'; + + $ArrayOfGenresTemp = getid3_id3v1::ArrayOfGenres(); // get the array of genres + foreach ($ArrayOfGenresTemp as $key => $value) { // change keys to match displayed value + $ArrayOfGenres[$value] = $value; + } + unset($ArrayOfGenresTemp); // remove temporary array + unset($ArrayOfGenres['Cover']); // take off these special cases + unset($ArrayOfGenres['Remix']); + unset($ArrayOfGenres['Unknown']); + $ArrayOfGenres[''] = '- Unknown -'; // Add special cases back in with renamed key/value + $ArrayOfGenres['Cover'] = '-Cover-'; + $ArrayOfGenres['Remix'] = '-Remix-'; + asort($ArrayOfGenres); // sort into alphabetical order + echo '<TR><TD ALIGN="RIGHT"><B>Genre</B></TD><TD><SELECT NAME="Genre">'; + $AllGenresArray = (!empty($OldThisFileInfo['comments']['genre']) ? $OldThisFileInfo['comments']['genre'] : array()); + foreach ($ArrayOfGenres as $key => $value) { + echo '<OPTION VALUE="'.$key.'"'; + if (in_array($key, $AllGenresArray)) { + echo ' SELECTED'; + unset($AllGenresArray[array_search($key, $AllGenresArray)]); + sort($AllGenresArray); + } + echo '>'.$value.'</OPTION>'; + //echo '<OPTION VALUE="'.FixTextFields($value).'"'.((@$OldThisFileInfo['comments']['genre'][0] == $value) ? ' SELECTED' : '').'>'.$value.'</OPTION>'; + } + echo '</SELECT><INPUT TYPE="TEXT" NAME="GenreOther" SIZE="10" VALUE="'.FixTextFields(@$AllGenresArray[0]).'"></TD></TR>'; + + echo '<TR><TD ALIGN="RIGHT"><B>Write Tags</B></TD><TD>'; + foreach ($ValidTagTypes as $ValidTagType) { + echo '<INPUT TYPE="CHECKBOX" NAME="TagFormatsToWrite[]" VALUE="'.$ValidTagType.'"'; + if (count($ValidTagTypes) == 1) { + echo ' CHECKED'; + } else { + switch ($ValidTagType) { + case 'id3v2.2': + case 'id3v2.3': + case 'id3v2.4': + if (isset($OldThisFileInfo['tags']['id3v2'])) { + echo ' CHECKED'; + } + break; + + default: + if (isset($OldThisFileInfo['tags'][$ValidTagType])) { + echo ' CHECKED'; + } + break; + } + } + echo '>'.$ValidTagType.'<BR>'; + } + if (count($ValidTagTypes) > 1) { + echo '<hr><input type="checkbox" name="remove_other_tags" value="1"> Remove non-selected tag formats when writing new tag<br>'; + } + echo '</TD></TR>'; + + echo '<TR><TD ALIGN="RIGHT"><B>Comment</B></TD><TD><TEXTAREA COLS="30" ROWS="3" NAME="Comment" WRAP="VIRTUAL">'.(isset($OldThisFileInfo['comments']['comment']) ? @implode("\n", $OldThisFileInfo['comments']['comment']) : '').'</TEXTAREA></TD></TR>'; + + echo '<TR><TD ALIGN="RIGHT"><B>Picture</B><BR>(ID3v2 only)</TD><TD><INPUT TYPE="FILE" NAME="userfile" ACCEPT="image/jpeg, image/gif, image/png"><BR>'; + echo '<SELECT NAME="APICpictureType">'; + $APICtypes = getid3_id3v2::APICPictureTypeLookup('', true); + foreach ($APICtypes as $key => $value) { + echo '<OPTION VALUE="'.FixTextFields($key).'">'.FixTextFields($value).'</OPTION>'; + } + echo '</SELECT></TD></TR>'; + echo '<TR><TD ALIGN="CENTER" COLSPAN="2"><INPUT TYPE="SUBMIT" NAME="WriteTags" VALUE="Save Changes"> '; + echo '<INPUT TYPE="RESET" VALUE="Reset"></TD></TR>'; + + } else { + + echo '<TR><TD ALIGN="RIGHT"><B>Error</B></TD><TD>'.FixTextFields($Filename).' does not exist</TD></TR>'; + + } + echo '</FORM></TABLE>'; + +} + +?> +</BODY> +</HTML>
\ No newline at end of file diff --git a/getid3/demos/index.php b/getid3/demos/index.php new file mode 100644 index 0000000..13783f0 --- /dev/null +++ b/getid3/demos/index.php @@ -0,0 +1 @@ +In this directory are a number of examples of how to use <A HREF="http://www.getid3.org">getID3()</A> - if you don't know what to run, take a look at <A HREF="demo.browse.php">demo.browse.php</A>
\ No newline at end of file |
