demo.mysqli.php 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  7. // //
  8. // /demo/demo.mysqli.php - part of getID3() //
  9. // Sample script for recursively scanning directories and //
  10. // storing the results in a database //
  11. // see readme.txt for more details //
  12. // updated to mysqli by sarang ///
  13. /////////////////////////////////////////////////////////////////
  14. die('Due to a security issue, this demo has been disabled. It can be enabled by removing line '.__LINE__.' in demos/'.basename(__FILE__));
  15. // OPTIONS:
  16. $getid3_demo_mysqli_encoding_getid3 = 'UTF-8';
  17. $getid3_demo_mysqli_encoding_mysqli = 'utf8'; // https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html
  18. $getid3_demo_mysqli_md5_data = false; // All data hashes are by far the slowest part of scanning, recommended to leave disabled
  19. $getid3_demo_mysqli_md5_file = false;
  20. define('GETID3_DB_HOST', 'localhost');
  21. define('GETID3_DB_USER', 'root');
  22. define('GETID3_DB_PASS', 'password');
  23. define('GETID3_DB_DB', 'getid3');
  24. define('GETID3_DB_TABLE', 'files');
  25. // CREATE DATABASE `getid3`;
  26. ob_start();
  27. if ($con = mysqli_connect(GETID3_DB_HOST, GETID3_DB_USER, GETID3_DB_PASS)){
  28. // great
  29. } else {
  30. $errormessage = ob_get_contents();
  31. ob_end_clean();
  32. die('Could not connect to MySQL host: <blockquote style="background-color: #FF9933; padding: 10px;">'.mysqli_error($con).'</blockquote>');
  33. }
  34. if (mysqli_select_db($con, GETID3_DB_DB)){
  35. // great
  36. } else {
  37. $errormessage = ob_get_contents();
  38. ob_end_clean();
  39. die('Could not select database: <blockquote style="background-color: #FF9933; padding: 10px;">'.mysqli_error($con).'</blockquote>');
  40. }
  41. ob_end_clean();
  42. if (!mysqli_set_charset($con, $getid3_demo_mysqli_encoding_mysqli)) {
  43. die('Could not mysqli_set_charset('.htmlentities($getid3_demo_mysqli_encoding_mysqli).')');
  44. }
  45. $getid3PHP_filename = realpath('../getid3/getid3.php');
  46. if (!file_exists($getid3PHP_filename) || !include_once($getid3PHP_filename)) {
  47. die('Cannot open '.$getid3PHP_filename);
  48. }
  49. // Initialize getID3 engine
  50. $getID3 = new getID3;
  51. $getID3->setOption(array(
  52. 'option_md5_data' => $getid3_demo_mysqli_md5_data,
  53. 'encoding' => $getid3_demo_mysqli_encoding_getid3,
  54. ));
  55. function RemoveAccents($string) {
  56. // Revised version by markstewardØhotmail*com
  57. return strtr(strtr($string, 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'), array('Þ' => 'TH', 'þ' => 'th', 'Ð' => 'DH', 'ð' => 'dh', 'ß' => 'ss', 'Œ' => 'OE', 'œ' => 'oe', 'Æ' => 'AE', 'æ' => 'ae', 'µ' => 'u'));
  58. }
  59. function BitrateColor($bitrate, $BitrateMaxScale=768) {
  60. // $BitrateMaxScale is bitrate of maximum-quality color (bright green)
  61. // below this is gradient, above is solid green
  62. $bitrate *= (256 / $BitrateMaxScale); // scale from 1-[768]kbps to 1-256
  63. $bitrate = round(min(max($bitrate, 1), 256));
  64. $bitrate--; // scale from 1-256kbps to 0-255kbps
  65. $Rcomponent = max(255 - ($bitrate * 2), 0);
  66. $Gcomponent = max(($bitrate * 2) - 255, 0);
  67. if ($bitrate > 127) {
  68. $Bcomponent = max((255 - $bitrate) * 2, 0);
  69. } else {
  70. $Bcomponent = max($bitrate * 2, 0);
  71. }
  72. 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);
  73. }
  74. function BitrateText($bitrate, $decimals=0) {
  75. return '<span style="color: #'.BitrateColor($bitrate).'">'.number_format($bitrate, $decimals).' kbps</span>';
  76. }
  77. function fileextension($filename, $numextensions=1) {
  78. if (strstr($filename, '.')) {
  79. $reversedfilename = strrev($filename);
  80. $offset = 0;
  81. for ($i = 0; $i < $numextensions; $i++) {
  82. $offset = strpos($reversedfilename, '.', $offset + 1);
  83. if ($offset === false) {
  84. return '';
  85. }
  86. }
  87. return strrev(substr($reversedfilename, 0, $offset));
  88. }
  89. return '';
  90. }
  91. function RenameFileFromTo($from, $to, &$results) {
  92. $success = true;
  93. if ($from === $to) {
  94. $results = '<span style="color: #FF0000;"><b>Source and Destination filenames identical</b><br>FAILED to rename';
  95. } elseif (!file_exists($from)) {
  96. $results = '<span style="color: #FF0000;"><b>Source file does not exist</b><br>FAILED to rename';
  97. } elseif (file_exists($to) && (strtolower($from) !== strtolower($to))) {
  98. $results = '<span style="color: #FF0000;"><b>Destination file already exists</b><br>FAILED to rename';
  99. } else {
  100. ob_start();
  101. if (rename($from, $to)) {
  102. ob_end_clean();
  103. $SQLquery = 'DELETE';
  104. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  105. $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $from).'")';
  106. mysqli_query_safe($con, $SQLquery);
  107. $results = '<span style="color: #008000;">Successfully renamed';
  108. } else {
  109. $errormessage = ob_get_contents();
  110. ob_end_clean();
  111. $results = '<br><span style="color: #FF0000;">FAILED to rename';
  112. $success = false;
  113. }
  114. }
  115. $results .= ' from:<br><i>'.$from.'</i><br>to:<br><i>'.$to.'</i></span><hr>';
  116. return $success;
  117. }
  118. if (!empty($_REQUEST['renamefilefrom']) && !empty($_REQUEST['renamefileto'])) {
  119. $results = '';
  120. RenameFileFromTo($_REQUEST['renamefilefrom'], $_REQUEST['renamefileto'], $results);
  121. echo $results;
  122. exit;
  123. } elseif (!empty($_REQUEST['m3ufilename'])) {
  124. header('Content-type: audio/x-mpegurl');
  125. echo '#EXTM3U'."\n";
  126. echo WindowsShareSlashTranslate($_REQUEST['m3ufilename'])."\n";
  127. exit;
  128. } elseif (!isset($_REQUEST['m3u']) && !isset($_REQUEST['m3uartist']) && !isset($_REQUEST['m3utitle'])) {
  129. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  130. 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>';
  131. }
  132. function WindowsShareSlashTranslate($filename) {
  133. if (substr($filename, 0, 2) == '//') {
  134. return str_replace('/', '\\', $filename);
  135. }
  136. return $filename;
  137. }
  138. function mysqli_query_safe($con, $SQLquery) {
  139. static $TimeSpentQuerying = 0;
  140. if ($SQLquery === null) {
  141. return $TimeSpentQuerying;
  142. }
  143. $starttime = microtime(true);
  144. $result = mysqli_query($con, $SQLquery);
  145. $TimeSpentQuerying += (microtime(true) - $starttime);
  146. if (mysqli_error($con)) {
  147. die('<div style="color: red; padding: 10px; margin: 10px; border: 3px red ridge;"><div style="font-weight: bold;">SQL error:</div><div style="color: blue; padding: 10px;">'.htmlentities(mysqli_error($con)).'</div><hr size="1"><div style="font-family: monospace;">'.htmlentities($SQLquery, ENT_SUBSTITUTE).'</div></div>');
  148. }
  149. return $result;
  150. }
  151. function mysqli_table_exists($con, $tablename) {
  152. return (bool) mysqli_query($con, 'DESCRIBE '.$tablename);
  153. }
  154. function AcceptableExtensions($fileformat, $audio_dataformat='', $video_dataformat='') {
  155. static $AcceptableExtensionsAudio = array();
  156. if (empty($AcceptableExtensionsAudio)) {
  157. $AcceptableExtensionsAudio['mp3']['mp3'] = array('mp3');
  158. $AcceptableExtensionsAudio['mp2']['mp2'] = array('mp2');
  159. $AcceptableExtensionsAudio['mp1']['mp1'] = array('mp1');
  160. $AcceptableExtensionsAudio['asf']['asf'] = array('asf');
  161. $AcceptableExtensionsAudio['asf']['wma'] = array('wma');
  162. $AcceptableExtensionsAudio['riff']['mp3'] = array('wav');
  163. $AcceptableExtensionsAudio['riff']['wav'] = array('wav');
  164. }
  165. static $AcceptableExtensionsVideo = array();
  166. if (empty($AcceptableExtensionsVideo)) {
  167. $AcceptableExtensionsVideo['mp3']['mp3'] = array('mp3');
  168. $AcceptableExtensionsVideo['mp2']['mp2'] = array('mp2');
  169. $AcceptableExtensionsVideo['mp1']['mp1'] = array('mp1');
  170. $AcceptableExtensionsVideo['asf']['asf'] = array('asf');
  171. $AcceptableExtensionsVideo['asf']['wmv'] = array('wmv');
  172. $AcceptableExtensionsVideo['gif']['gif'] = array('gif');
  173. $AcceptableExtensionsVideo['jpg']['jpg'] = array('jpg');
  174. $AcceptableExtensionsVideo['png']['png'] = array('png');
  175. $AcceptableExtensionsVideo['bmp']['bmp'] = array('bmp');
  176. }
  177. if (!empty($video_dataformat)) {
  178. return (isset($AcceptableExtensionsVideo[$fileformat][$video_dataformat]) ? $AcceptableExtensionsVideo[$fileformat][$video_dataformat] : array());
  179. } else {
  180. return (isset($AcceptableExtensionsAudio[$fileformat][$audio_dataformat]) ? $AcceptableExtensionsAudio[$fileformat][$audio_dataformat] : array());
  181. }
  182. }
  183. if (!empty($_REQUEST['scan'])) {
  184. if (mysqli_table_exists($con, GETID3_DB_TABLE)) {
  185. $SQLquery = 'DROP TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  186. mysqli_query_safe($con, $SQLquery);
  187. }
  188. }
  189. if (!mysqli_table_exists($con, GETID3_DB_TABLE)) {
  190. $SQLquery = "CREATE TABLE `".mysqli_real_escape_string($con, GETID3_DB_TABLE)."` (";
  191. $SQLquery .= "`ID` int(11) unsigned NOT NULL auto_increment";
  192. $SQLquery .= ", `filename` text NOT NULL";
  193. $SQLquery .= ", `last_modified` int(11) NOT NULL default '0'";
  194. $SQLquery .= ", `md5_file` varchar(32) NOT NULL default ''";
  195. $SQLquery .= ", `md5_data` varchar(32) NOT NULL default ''";
  196. $SQLquery .= ", `md5_data_source` varchar(32) NOT NULL default ''";
  197. $SQLquery .= ", `filesize` int(10) unsigned NOT NULL default '0'";
  198. $SQLquery .= ", `fileformat` varchar(255) NOT NULL default ''";
  199. $SQLquery .= ", `audio_dataformat` varchar(255) NOT NULL default ''";
  200. $SQLquery .= ", `video_dataformat` varchar(255) NOT NULL default ''";
  201. $SQLquery .= ", `audio_bitrate` float NOT NULL default '0'";
  202. $SQLquery .= ", `video_bitrate` float NOT NULL default '0'";
  203. $SQLquery .= ", `playtime_seconds` varchar(255) NOT NULL default ''";
  204. $SQLquery .= ", `tags` varchar(255) NOT NULL default ''";
  205. $SQLquery .= ", `artist` varchar(255) NOT NULL default ''";
  206. $SQLquery .= ", `title` varchar(255) NOT NULL default ''";
  207. $SQLquery .= ", `remix` varchar(255) NOT NULL default ''";
  208. $SQLquery .= ", `album` varchar(255) NOT NULL default ''";
  209. $SQLquery .= ", `genre` varchar(255) NOT NULL default ''";
  210. $SQLquery .= ", `comment` text NOT NULL";
  211. $SQLquery .= ", `track` varchar(7) NOT NULL default ''";
  212. $SQLquery .= ", `comments_all` longblob NOT NULL";
  213. $SQLquery .= ", `comments_id3v2` longblob NOT NULL";
  214. $SQLquery .= ", `comments_ape` longblob NOT NULL";
  215. $SQLquery .= ", `comments_lyrics3` longblob NOT NULL";
  216. $SQLquery .= ", `comments_id3v1` blob NOT NULL";
  217. $SQLquery .= ", `warning` longtext NOT NULL";
  218. $SQLquery .= ", `error` longtext NOT NULL";
  219. $SQLquery .= ", `track_volume` float NOT NULL default '0'";
  220. $SQLquery .= ", `encoder_options` varchar(255) NOT NULL default ''";
  221. $SQLquery .= ", `vbr_method` varchar(255) NOT NULL default ''";
  222. $SQLquery .= ", PRIMARY KEY (`ID`)";
  223. $SQLquery .= ")";
  224. mysqli_query_safe($con, $SQLquery);
  225. }
  226. $ExistingTableFields = array();
  227. $result = mysqli_query_safe($con, 'DESCRIBE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
  228. while ($row = mysqli_fetch_array($result)) {
  229. $ExistingTableFields[$row['Field']] = $row;
  230. }
  231. if (!isset($ExistingTableFields['encoder_options'])) { // Added in 1.7.0b2
  232. echo '<b>adding field `encoder_options`</b><br>';
  233. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `encoder_options` VARCHAR(255) default "" NOT NULL AFTER `error`');
  234. mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
  235. }
  236. if (isset($ExistingTableFields['track']) && ($ExistingTableFields['track']['Type'] != 'varchar(7)')) { // Changed in 1.7.0b2
  237. echo '<b>changing field `track` to VARCHAR(7)</b><br>';
  238. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `track` `track` VARCHAR(7) default "" NOT NULL');
  239. mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
  240. }
  241. if (!isset($ExistingTableFields['track_volume'])) { // Added in 1.7.0b5
  242. 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>';
  243. echo '<b>adding field `track_volume`</b><br>';
  244. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `track_volume` FLOAT NOT NULL AFTER `error`');
  245. mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
  246. }
  247. if (!isset($ExistingTableFields['remix'])) { // Added in 1.7.3b1
  248. echo '<b>adding field `encoder_options`, `alternate_name`, `parody`</b><br>';
  249. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `remix` VARCHAR(255) default "" NOT NULL AFTER `title`');
  250. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `alternate_name` VARCHAR(255) default "" NOT NULL AFTER `track`');
  251. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` ADD `parody` VARCHAR(255) default "" NOT NULL AFTER `alternate_name`');
  252. mysqli_query_safe($con, 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`');
  253. }
  254. if (isset($ExistingTableFields['comments_all']) && ($ExistingTableFields['comments_all']['Type'] != 'longblob')) { // Changed to "longtext" in 1.9.0, changed to "longblob" in 1.9.20-202010140821
  255. echo '<b>changing comments fields from text to longtext</b><br>';
  256. // no need to change id3v1
  257. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_all` `comments_all` LONGBLOB NOT NULL');
  258. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_id3v2` `comments_id3v2` LONGBLOB NOT NULL');
  259. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_ape` `comments_ape` LONGBLOB NOT NULL');
  260. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_lyrics3` `comments_lyrics3` LONGBLOB NOT NULL');
  261. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `comments_id3v1` `comments_id3v1` BLOB NOT NULL');
  262. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `warning` `warning` LONGTEXT NOT NULL');
  263. mysqli_query_safe($con, 'ALTER TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` CHANGE `error` `error` LONGTEXT NOT NULL');
  264. }
  265. function SynchronizeAllTags($filename, $synchronizefrom='all', $synchronizeto='A12', &$errors = array()) {
  266. global $getID3;
  267. set_time_limit(30);
  268. $ThisFileInfo = $getID3->analyze($filename);
  269. $getID3->CopyTagsToComments($ThisFileInfo);
  270. if ($synchronizefrom == 'all') {
  271. $SourceArray = (!empty($ThisFileInfo['comments']) ? $ThisFileInfo['comments'] : array());
  272. } elseif (!empty($ThisFileInfo['tags'][$synchronizefrom])) {
  273. $SourceArray = (!empty($ThisFileInfo['tags'][$synchronizefrom]) ? $ThisFileInfo['tags'][$synchronizefrom] : array());
  274. } else {
  275. die('ERROR: $ThisFileInfo[tags]['.$synchronizefrom.'] does not exist');
  276. }
  277. $SQLquery = 'DELETE';
  278. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  279. $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $filename).'")';
  280. mysqli_query_safe($con, $SQLquery);
  281. $TagFormatsToWrite = array();
  282. if ((strpos($synchronizeto, '2') !== false) && ($synchronizefrom != 'id3v2')) {
  283. $TagFormatsToWrite[] = 'id3v2.3';
  284. }
  285. if ((strpos($synchronizeto, 'A') !== false) && ($synchronizefrom != 'ape')) {
  286. $TagFormatsToWrite[] = 'ape';
  287. }
  288. if ((strpos($synchronizeto, 'L') !== false) && ($synchronizefrom != 'lyrics3')) {
  289. $TagFormatsToWrite[] = 'lyrics3';
  290. }
  291. if ((strpos($synchronizeto, '1') !== false) && ($synchronizefrom != 'id3v1')) {
  292. $TagFormatsToWrite[] = 'id3v1';
  293. }
  294. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.php', __FILE__, true);
  295. $tagwriter = new getid3_writetags;
  296. $tagwriter->filename = $filename;
  297. $tagwriter->tagformats = $TagFormatsToWrite;
  298. $tagwriter->overwrite_tags = true;
  299. $tagwriter->tag_encoding = $getID3->encoding;
  300. $tagwriter->tag_data = $SourceArray;
  301. if ($tagwriter->WriteTags()) {
  302. $errors = $tagwriter->errors;
  303. return true;
  304. }
  305. $errors = $tagwriter->errors;
  306. return false;
  307. }
  308. $IgnoreNoTagFormats = array('', 'png', 'jpg', 'gif', 'bmp', 'swf', 'pdf', 'zip', 'rar', 'mid', 'mod', 'xm', 'it', 's3m');
  309. if (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan']) || !empty($_REQUEST['rescanerrors'])) {
  310. $SQLquery = 'DELETE';
  311. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  312. $SQLquery .= ' WHERE (`fileformat` = "")';
  313. mysqli_query_safe($con, $SQLquery);
  314. $FilesInDir = array();
  315. if (!empty($_REQUEST['rescanerrors'])) {
  316. echo '<a href="'.htmlentities($_SERVER['PHP_SELF']).'">abort</a><hr>';
  317. echo 'Re-scanning all media files already in database that had errors and/or warnings in last scan<hr>';
  318. $SQLquery = 'SELECT `filename`';
  319. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  320. $SQLquery .= ' WHERE (`error` <> "")';
  321. $SQLquery .= ' OR (`warning` <> "")';
  322. $SQLquery .= ' ORDER BY `filename` ASC';
  323. $result = mysqli_query_safe($con, $SQLquery);
  324. while ($row = mysqli_fetch_array($result)) {
  325. if (!file_exists($row['filename'])) {
  326. echo '<b>File missing: '.$row['filename'].'</b><br>';
  327. $SQLquery = 'DELETE';
  328. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  329. $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
  330. mysqli_query_safe($con, $SQLquery);
  331. } else {
  332. $FilesInDir[] = $row['filename'];
  333. }
  334. }
  335. } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) {
  336. echo '<a href="'.htmlentities($_SERVER['PHP_SELF']).'">abort</a><hr>';
  337. echo 'Scanning all media files in <b>'.str_replace('\\', '/', realpath(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan'])).'</b> (and subdirectories)<hr>';
  338. $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`';
  339. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  340. $SQLquery .= ' GROUP BY `filename`';
  341. $SQLquery .= ' HAVING (`num` > 1)';
  342. $SQLquery .= ' ORDER BY `num` DESC';
  343. $result = mysqli_query_safe($con, $SQLquery);
  344. $DupesDeleted = 0;
  345. while ($row = mysqli_fetch_array($result)) {
  346. set_time_limit(30);
  347. $SQLquery = 'DELETE';
  348. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  349. $SQLquery .= ' WHERE `filename` LIKE "'.mysqli_real_escape_string($con, $row['filename']).'"';
  350. mysqli_query_safe($con, $SQLquery);
  351. $DupesDeleted++;
  352. }
  353. if ($DupesDeleted > 0) {
  354. echo 'Deleted <b>'.number_format($DupesDeleted).'</b> duplicate filenames<hr>';
  355. }
  356. if (!empty($_REQUEST['newscan'])) {
  357. $AlreadyInDatabase = array();
  358. set_time_limit(60);
  359. $SQLquery = 'SELECT `filename`';
  360. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  361. $SQLquery .= ' ORDER BY `filename` ASC';
  362. $result = mysqli_query_safe($con, $SQLquery);
  363. while ($row = mysqli_fetch_array($result)) {
  364. //$AlreadyInDatabase[] = strtolower($row['filename']);
  365. $AlreadyInDatabase[] = $row['filename'];
  366. }
  367. }
  368. $DirectoriesToScan = array(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : $_REQUEST['newscan']);
  369. $DirectoriesScanned = array();
  370. while (count($DirectoriesToScan) > 0) {
  371. foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) {
  372. if ($dir = opendir($startingdir)) {
  373. set_time_limit(30);
  374. echo '<b>'.str_replace('\\', '/', $startingdir).'</b><br>';
  375. flush();
  376. while (($file = readdir($dir)) !== false) {
  377. if (($file != '.') && ($file != '..')) {
  378. $RealPathName = realpath($startingdir.'/'.$file);
  379. if (is_dir($RealPathName)) {
  380. if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName, $DirectoriesToScan)) {
  381. $DirectoriesToScan[] = $RealPathName;
  382. }
  383. } elseif (is_file($RealPathName)) {
  384. if (!empty($_REQUEST['newscan'])) {
  385. if (!in_array(str_replace('\\', '/', $RealPathName), $AlreadyInDatabase)) {
  386. $FilesInDir[] = $RealPathName;
  387. }
  388. } elseif (!empty($_REQUEST['scan'])) {
  389. $FilesInDir[] = $RealPathName;
  390. }
  391. }
  392. }
  393. }
  394. closedir($dir);
  395. } else {
  396. echo '<div style="color: red;">Failed to open directory "<b>'.htmlentities($startingdir).'</b>"</div><br>';
  397. }
  398. $DirectoriesScanned[] = $startingdir;
  399. unset($DirectoriesToScan[$DirectoryKey]);
  400. }
  401. }
  402. echo '<i>List of files to scan complete (added '.number_format(count($FilesInDir)).' files to scan)</i><hr>';
  403. flush();
  404. }
  405. $FilesInDir = array_unique($FilesInDir);
  406. sort($FilesInDir);
  407. $starttime = time();
  408. $rowcounter = 0;
  409. $totaltoprocess = count($FilesInDir);
  410. foreach ($FilesInDir as $filename) {
  411. set_time_limit(300);
  412. echo '<br>'.date('H:i:s').' ['.number_format(++$rowcounter).' / '.number_format($totaltoprocess).'] '.str_replace('\\', '/', $filename);
  413. $ThisFileInfo = $getID3->analyze($filename);
  414. $getID3->CopyTagsToComments($ThisFileInfo);
  415. if (file_exists($filename)) {
  416. $ThisFileInfo['file_modified_time'] = filemtime($filename);
  417. $ThisFileInfo['md5_file'] = ($getid3_demo_mysqli_md5_file ? md5_file($filename) : '');
  418. }
  419. if (empty($ThisFileInfo['fileformat'])) {
  420. echo ' (<span style="color: #990099;">unknown file type</span>)';
  421. } else {
  422. if (!empty($ThisFileInfo['error'])) {
  423. echo ' (<span style="color: #FF0000;">errors</span>)';
  424. } elseif (!empty($ThisFileInfo['warning'])) {
  425. echo ' (<span style="color: #FF9999;">warnings</span>)';
  426. } else {
  427. echo ' (<span style="color: #009900;">OK</span>)';
  428. }
  429. $this_track_track = '';
  430. if (!empty($ThisFileInfo['comments']['track_number'])) {
  431. foreach ($ThisFileInfo['comments']['track_number'] as $key => $value) {
  432. if (strlen($value) > strlen($this_track_track)) {
  433. $this_track_track = str_pad($value, 2, '0', STR_PAD_LEFT);
  434. }
  435. }
  436. if (preg_match('#^([0-9]+)/([0-9]+)$#', $this_track_track, $matches)) {
  437. // change "1/5"->"01/05", "3/12"->"03/12", etc
  438. $this_track_track = str_pad($matches[1], 2, '0', STR_PAD_LEFT).'/'.str_pad($matches[2], 2, '0', STR_PAD_LEFT);
  439. }
  440. }
  441. $this_track_remix = '';
  442. $this_track_title = '';
  443. if (!empty($ThisFileInfo['comments']['title'])) {
  444. foreach ($ThisFileInfo['comments']['title'] as $possible_title) {
  445. if (strlen($possible_title) > strlen($this_track_title)) {
  446. $this_track_title = $possible_title;
  447. }
  448. }
  449. }
  450. $ParenthesesPairs = array('()', '[]', '{}');
  451. foreach ($ParenthesesPairs as $pair) {
  452. 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)) {
  453. $this_track_title = $matches[1][0];
  454. $this_track_remix = implode("\t", $matches[2]);
  455. }
  456. }
  457. if (!empty($_REQUEST['rescanerrors'])) {
  458. $SQLquery = 'UPDATE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` SET ';
  459. $SQLquery .= ' `last_modified` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"';
  460. $SQLquery .= ', `md5_file` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"';
  461. $SQLquery .= ', `md5_data` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"';
  462. $SQLquery .= ', `md5_data_source` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"';
  463. $SQLquery .= ', `filesize` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"';
  464. $SQLquery .= ', `fileformat` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"';
  465. $SQLquery .= ', `audio_dataformat` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"';
  466. $SQLquery .= ', `video_dataformat` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"';
  467. $SQLquery .= ', `vbr_method` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['mpeg']['audio']['VBR_method'] ) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '').'"';
  468. $SQLquery .= ', `audio_bitrate` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"';
  469. $SQLquery .= ', `video_bitrate` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"';
  470. $SQLquery .= ', `playtime_seconds` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"';
  471. $SQLquery .= ', `track_volume` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"';
  472. $SQLquery .= ', `comments_all` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"';
  473. $SQLquery .= ', `comments_id3v2` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"';
  474. $SQLquery .= ', `comments_ape` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"';
  475. $SQLquery .= ', `comments_lyrics3` = "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"';
  476. $SQLquery .= ', `comments_id3v1` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"';
  477. $SQLquery .= ', `warning` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"';
  478. $SQLquery .= ', `error` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"';
  479. $SQLquery .= ', `album` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"';
  480. $SQLquery .= ', `genre` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"';
  481. $SQLquery .= ', `comment` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"';
  482. $SQLquery .= ', `artist` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"';
  483. $SQLquery .= ', `tags` = "'. mysqli_real_escape_string($con, !empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"';
  484. $SQLquery .= ', `encoder_options` = "'. mysqli_real_escape_string($con, trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"';
  485. $SQLquery .= ', `title` = "'. mysqli_real_escape_string($con, $this_track_title).'"';
  486. $SQLquery .= ', `remix` = "'. mysqli_real_escape_string($con, $this_track_remix).'"';
  487. $SQLquery .= ', `track` = "'. mysqli_real_escape_string($con, $this_track_track).'"';
  488. $SQLquery .= ' WHERE (`filename` = "'. mysqli_real_escape_string($con, isset($ThisFileInfo['filenamepath']) ? $ThisFileInfo['filenamepath'] : '').'")';
  489. } elseif (!empty($_REQUEST['scan']) || !empty($_REQUEST['newscan'])) {
  490. $SQLquery = 'INSERT INTO `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'` (`filename`, `last_modified`, `md5_file`, `md5_data`, `md5_data_source`, `filesize`, `fileformat`, `audio_dataformat`, `video_dataformat`, `audio_bitrate`, `video_bitrate`, `playtime_seconds`, `tags`, `artist`, `title`, `remix`, `album`, `genre`, `comment`, `track`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`, `warning`, `error`, `track_volume`, `encoder_options`, `vbr_method`) VALUES (';
  491. $SQLquery .= '"'.mysqli_real_escape_string($con, !empty($ThisFileInfo['filenamepath'] ) ? $ThisFileInfo['filenamepath'] : '').'"'; // filename
  492. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['file_modified_time'] ) ? $ThisFileInfo['file_modified_time'] : '').'"'; // last_modified
  493. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_file'] ) ? $ThisFileInfo['md5_file'] : '').'"'; // md5_file
  494. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data'] ) ? $ThisFileInfo['md5_data'] : '').'"'; // md5_data
  495. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['md5_data_source'] ) ? $ThisFileInfo['md5_data_source'] : '').'"'; // md5_data_source
  496. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['filesize'] ) ? $ThisFileInfo['filesize'] : 0).'"'; // filesize
  497. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['fileformat'] ) ? $ThisFileInfo['fileformat'] : '').'"'; // fileformat
  498. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['dataformat'] ) ? $ThisFileInfo['audio']['dataformat'] : '').'"'; // audio_dataformat
  499. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['dataformat'] ) ? $ThisFileInfo['video']['dataformat'] : '').'"'; // video_dataformat
  500. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['audio']['bitrate'] ) ? floatval($ThisFileInfo['audio']['bitrate']) : 0).'"'; // audio_bitrate
  501. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['video']['bitrate'] ) ? floatval($ThisFileInfo['video']['bitrate']) : 0).'"'; // video_bitrate
  502. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['playtime_seconds'] ) ? floatval($ThisFileInfo['playtime_seconds']) : 0).'"'; // playtime_seconds
  503. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags'] ) ? implode("\t", array_keys($ThisFileInfo['tags'])) : '').'"'; // tags
  504. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['artist'] ) ? implode("\t", $ThisFileInfo['comments']['artist']) : '').'"'; // artist
  505. $SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_title ).'"'; // title
  506. $SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_remix ).'"'; // remix
  507. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['album'] ) ? implode("\t", $ThisFileInfo['comments']['album']) : '').'"'; // album
  508. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['genre'] ) ? implode("\t", $ThisFileInfo['comments']['genre']) : '').'"'; // genre
  509. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments']['comment'] ) ? implode("\t", $ThisFileInfo['comments']['comment']) : '').'"'; // comment
  510. $SQLquery .= ', "'.mysqli_real_escape_string($con, $this_track_track ).'"'; // track
  511. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['comments'] ) ? serialize($ThisFileInfo['comments']) : '').'"'; // comments_all
  512. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v2'] ) ? serialize($ThisFileInfo['tags']['id3v2']) : '').'"'; // comments_id3v2
  513. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['ape'] ) ? serialize($ThisFileInfo['tags']['ape']) : '').'"'; // comments_ape
  514. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['lyrics3'] ) ? serialize($ThisFileInfo['tags']['lyrics3']) : '').'"'; // comments_lyrics3
  515. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['tags']['id3v1'] ) ? serialize($ThisFileInfo['tags']['id3v1']) : '').'"'; // comments_id3v1
  516. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['warning'] ) ? implode("\t", $ThisFileInfo['warning']) : '').'"'; // warning
  517. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['error'] ) ? implode("\t", $ThisFileInfo['error']) : '').'"'; // error
  518. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['replay_gain']['track']['volume']) ? floatval($ThisFileInfo['replay_gain']['track']['volume']) : 0).'"'; // track_volume
  519. $SQLquery .= ', "'.mysqli_real_escape_string($con, trim((!empty($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : '').' '.(!empty($ThisFileInfo['audio']['encoder_options']) ? $ThisFileInfo['audio']['encoder_options'] : ''))).'"'; // encoder_options
  520. $SQLquery .= ', "'.mysqli_real_escape_string($con, !empty($ThisFileInfo['mpeg']['audio']['LAME']) ? 'LAME' : (!empty($ThisFileInfo['mpeg']['audio']['VBR_method']) ? $ThisFileInfo['mpeg']['audio']['VBR_method'] : '')).'"'; // vbr_method
  521. $SQLquery .= ')';
  522. }
  523. flush();
  524. mysqli_query_safe($con, $SQLquery);
  525. }
  526. }
  527. $SQLquery = 'OPTIMIZE TABLE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  528. mysqli_query_safe($con, $SQLquery);
  529. echo '<hr>Done scanning!<hr>';
  530. } elseif (!empty($_REQUEST['missingtrackvolume'])) {
  531. $MissingTrackVolumeFilesScanned = 0;
  532. $MissingTrackVolumeFilesAdjusted = 0;
  533. $MissingTrackVolumeFilesDeleted = 0;
  534. $SQLquery = 'SELECT `filename`';
  535. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  536. $SQLquery .= ' WHERE (`track_volume` = 0)';
  537. $SQLquery .= ' AND (`audio_bitrate` > 0)';
  538. $result = mysqli_query_safe($con, $SQLquery);
  539. echo 'Scanning <span ID="missingtrackvolumeNowScanning">0</span> / '.number_format(mysqli_num_rows($result)).' files for track volume information:<hr>';
  540. while ($row = mysqli_fetch_array($result)) {
  541. set_time_limit(30);
  542. echo '<script type="text/javascript">if (document.getElementById("missingtrackvolumeNowScanning")) document.getElementById("missingtrackvolumeNowScanning").innerHTML = "'.number_format($MissingTrackVolumeFilesScanned++).'";</script>. ';
  543. flush();
  544. if (file_exists($row['filename'])) {
  545. $ThisFileInfo = $getID3->analyze($row['filename']);
  546. if (!empty($ThisFileInfo['replay_gain']['track']['volume'])) {
  547. $MissingTrackVolumeFilesAdjusted++;
  548. $SQLquery = 'UPDATE `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  549. $SQLquery .= ' SET `track_volume` = "'.$ThisFileInfo['replay_gain']['track']['volume'].'"';
  550. $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
  551. mysqli_query_safe($con, $SQLquery);
  552. }
  553. } else {
  554. $MissingTrackVolumeFilesDeleted++;
  555. $SQLquery = 'DELETE';
  556. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  557. $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
  558. mysqli_query_safe($con, $SQLquery);
  559. }
  560. }
  561. echo '<hr>Scanned '.number_format($MissingTrackVolumeFilesScanned).' files with no track volume information.<br>';
  562. 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>';
  563. } elseif (!empty($_REQUEST['deadfilescheck'])) {
  564. $SQLquery = 'SELECT COUNT(*) AS `num`, `filename`';
  565. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  566. $SQLquery .= ' GROUP BY `filename`';
  567. $SQLquery .= ' ORDER BY `num` DESC';
  568. $result = mysqli_query_safe($con, $SQLquery);
  569. $DupesDeleted = 0;
  570. while ($row = mysqli_fetch_array($result)) {
  571. set_time_limit(30);
  572. if ($row['num'] <= 1) {
  573. break;
  574. }
  575. echo '<br>'.htmlentities($row['filename']).' (<font color="#FF9999">duplicate</font>)';
  576. $SQLquery = 'DELETE';
  577. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  578. $SQLquery .= ' WHERE `filename` LIKE "'.mysqli_real_escape_string($con, $row['filename']).'"';
  579. mysqli_query_safe($con, $SQLquery);
  580. $DupesDeleted++;
  581. }
  582. if ($DupesDeleted > 0) {
  583. echo '<hr>Deleted <b>'.number_format($DupesDeleted).'</b> duplicate filenames<hr>';
  584. }
  585. $SQLquery = 'SELECT `filename`, `filesize`, `last_modified`';
  586. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  587. $SQLquery .= ' ORDER BY `filename` ASC';
  588. $result = mysqli_query_safe($con, $SQLquery);
  589. $totalchecked = 0;
  590. $totalremoved = 0;
  591. $previousdir = '';
  592. while ($row = mysqli_fetch_array($result)) {
  593. $totalchecked++;
  594. set_time_limit(30);
  595. $reason = '';
  596. if (!file_exists($row['filename'])) {
  597. $reason = 'deleted';
  598. } elseif (filesize($row['filename']) != $row['filesize']) {
  599. $reason = 'filesize changed';
  600. } elseif (filemtime($row['filename']) != $row['last_modified']) {
  601. if (abs(filemtime($row['filename']) - $row['last_modified']) != 3600) {
  602. // off by exactly one hour == daylight savings time
  603. $reason = 'last-modified time changed';
  604. }
  605. }
  606. $thisdir = dirname($row['filename']);
  607. if ($reason) {
  608. $totalremoved++;
  609. echo '<br>'.htmlentities($row['filename']).' (<font color="#FF9999">'.$reason.'</font>)';
  610. flush();
  611. $SQLquery = 'DELETE';
  612. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  613. $SQLquery .= ' WHERE (`filename` = "'.mysqli_real_escape_string($con, $row['filename']).'")';
  614. mysqli_query_safe($con, $SQLquery);
  615. } elseif ($thisdir != $previousdir) {
  616. echo '. ';
  617. flush();
  618. }
  619. $previousdir = $thisdir;
  620. }
  621. 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>';
  622. } elseif (!empty($_REQUEST['encodedbydistribution'])) {
  623. if (!empty($_REQUEST['m3u'])) {
  624. header('Content-type: audio/x-mpegurl');
  625. echo '#EXTM3U'."\n";
  626. $SQLquery = 'SELECT `filename`, `comments_id3v2`';
  627. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  628. $SQLquery .= ' WHERE (`encoder_options` = "'.mysqli_real_escape_string($con, $_REQUEST['encodedbydistribution']).'")';
  629. $result = mysqli_query_safe($con, $SQLquery);
  630. $NonBlankEncodedBy = '';
  631. $BlankEncodedBy = '';
  632. while ($row = mysqli_fetch_array($result)) {
  633. set_time_limit(30);
  634. $CommentArray = unserialize($row['comments_id3v2']);
  635. if (isset($CommentArray['encoded_by'][0])) {
  636. $NonBlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n";
  637. } else {
  638. $BlankEncodedBy .= WindowsShareSlashTranslate($row['filename'])."\n";
  639. }
  640. }
  641. echo $NonBlankEncodedBy;
  642. echo $BlankEncodedBy;
  643. exit;
  644. } elseif (!empty($_REQUEST['showfiles'])) {
  645. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode('%')).'">show all</a><br>';
  646. echo '<table border="1">';
  647. $SQLquery = 'SELECT `filename`, `comments_id3v2`';
  648. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  649. $result = mysqli_query_safe($con, $SQLquery);
  650. while ($row = mysqli_fetch_array($result)) {
  651. set_time_limit(30);
  652. $CommentArray = unserialize($row['comments_id3v2']);
  653. if (($_REQUEST['encodedbydistribution'] == '%') || (!empty($CommentArray['encoded_by'][0]) && ($_REQUEST['encodedbydistribution'] == $CommentArray['encoded_by'][0]))) {
  654. echo '<tr><td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename'])).'">m3u</a></td>';
  655. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td></tr>';
  656. }
  657. }
  658. echo '</table>';
  659. } else {
  660. $SQLquery = 'SELECT `encoder_options`, `comments_id3v2`';
  661. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  662. $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC';
  663. $result = mysqli_query_safe($con, $SQLquery);
  664. $EncodedBy = array();
  665. while ($row = mysqli_fetch_array($result)) {
  666. set_time_limit(30);
  667. $CommentArray = unserialize($row['comments_id3v2']);
  668. if (isset($CommentArray['encoded_by'][0])) {
  669. if (isset($EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]])) {
  670. $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]]++;
  671. } else {
  672. $EncodedBy[$row['encoder_options']][$CommentArray['encoded_by'][0]] = 1;
  673. }
  674. }
  675. }
  676. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode('%').'&m3u=1').'">.m3u version</a><br>';
  677. echo '<table border="1"><tr><th>m3u</th><th>Encoder Options</th><th>Encoded By (ID3v2)</th></tr>';
  678. foreach ($EncodedBy as $key => $value) {
  679. echo '<tr><TD VALIGN="TOP"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode($key).'&showfiles=1&m3u=1').'">m3u</a></td>';
  680. echo '<TD VALIGN="TOP"><b>'.$key.'</b></td>';
  681. echo '<td><table border="0" WIDTH="100%">';
  682. arsort($value);
  683. foreach ($value as $string => $count) {
  684. echo '<tr><TD ALIGN="RIGHT" WIDTH="50"><i>'.number_format($count).'</i></td><td>&nbsp;</td>';
  685. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode($string).'&showfiles=1').'">'.$string.'</a></td></tr>';
  686. }
  687. echo '</table></td></tr>';
  688. }
  689. echo '</table>';
  690. }
  691. } elseif (!empty($_REQUEST['audiobitrates'])) {
  692. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.audio.mp3.php', __FILE__, true);
  693. $BitrateDistribution = array();
  694. $SQLquery = 'SELECT ROUND(audio_bitrate / 1000) AS `RoundBitrate`, COUNT(*) AS `num`';
  695. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  696. $SQLquery .= ' WHERE (`audio_bitrate` > 0)';
  697. $SQLquery .= ' GROUP BY `RoundBitrate`';
  698. $result = mysqli_query_safe($con, $SQLquery);
  699. while ($row = mysqli_fetch_array($result)) {
  700. $this_bitrate = getid3_mp3::ClosestStandardMP3Bitrate($row['RoundBitrate'] * 1000);
  701. if (isset($BitrateDistribution[$this_bitrate])) {
  702. $BitrateDistribution[$this_bitrate] += $row['num'];
  703. } else {
  704. $BitrateDistribution[$this_bitrate] = $row['num'];
  705. }
  706. }
  707. echo '<table border="1" cellspacing="0" cellpadding="3">';
  708. echo '<tr><th>Bitrate</th><th>Count</th></tr>';
  709. foreach ($BitrateDistribution as $Bitrate => $Count) {
  710. echo '<tr>';
  711. echo '<td align="right">'.round($Bitrate / 1000).' kbps</td>';
  712. echo '<td align="right">'.number_format($Count).'</td>';
  713. echo '</tr>';
  714. }
  715. echo '</table>';
  716. } elseif (!empty($_REQUEST['emptygenres'])) {
  717. $SQLquery = 'SELECT `fileformat`, `filename`, `genre`';
  718. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  719. $SQLquery .= ' WHERE (`genre` = "")';
  720. $SQLquery .= ' OR (`genre` = "Unknown")';
  721. $SQLquery .= ' OR (`genre` = "Other")';
  722. $SQLquery .= ' ORDER BY `filename` ASC';
  723. $result = mysqli_query_safe($con, $SQLquery);
  724. if (!empty($_REQUEST['m3u'])) {
  725. header('Content-type: audio/x-mpegurl');
  726. echo '#EXTM3U'."\n";
  727. while ($row = mysqli_fetch_array($result)) {
  728. if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) {
  729. echo WindowsShareSlashTranslate($row['filename'])."\n";
  730. }
  731. }
  732. exit;
  733. } else {
  734. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?emptygenres='.urlencode($_REQUEST['emptygenres']).'&m3u=1').'">.m3u version</a><br>';
  735. $EmptyGenreCounter = 0;
  736. echo '<table border="1" cellspacing="0" cellpadding="3">';
  737. echo '<tr><th>m3u</th><th>filename</th></tr>';
  738. while ($row = mysqli_fetch_array($result)) {
  739. if (!in_array($row['fileformat'], $IgnoreNoTagFormats)) {
  740. $EmptyGenreCounter++;
  741. echo '<tr>';
  742. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">m3u</a></td>';
  743. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  744. echo '</tr>';
  745. }
  746. }
  747. echo '</table>';
  748. echo '<b>'.number_format($EmptyGenreCounter).'</b> files with empty genres';
  749. }
  750. } elseif (!empty($_REQUEST['nonemptycomments'])) {
  751. $SQLquery = 'SELECT `filename`, `comment`';
  752. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  753. $SQLquery .= ' WHERE (`comment` <> "")';
  754. $SQLquery .= ' ORDER BY `comment` ASC';
  755. $result = mysqli_query_safe($con, $SQLquery);
  756. if (!empty($_REQUEST['m3u'])) {
  757. header('Content-type: audio/x-mpegurl');
  758. echo '#EXTM3U'."\n";
  759. while ($row = mysqli_fetch_array($result)) {
  760. echo WindowsShareSlashTranslate($row['filename'])."\n";
  761. }
  762. exit;
  763. } else {
  764. $NonEmptyCommentsCounter = 0;
  765. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?nonemptycomments='.urlencode($_REQUEST['nonemptycomments']).'&m3u=1').'">.m3u version</a><br>';
  766. echo '<table border="1" cellspacing="0" cellpadding="3">';
  767. echo '<tr><th>m3u</th><th>filename</th><th>comments</th></tr>';
  768. while ($row = mysqli_fetch_array($result)) {
  769. $NonEmptyCommentsCounter++;
  770. echo '<tr>';
  771. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">m3u</a></td>';
  772. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  773. if (strlen(trim($row['comment'])) > 0) {
  774. echo '<td>'.htmlentities($row['comment']).'</td>';
  775. } else {
  776. echo '<td><i>space</i></td>';
  777. }
  778. echo '</tr>';
  779. }
  780. echo '</table>';
  781. echo '<b>'.number_format($NonEmptyCommentsCounter).'</b> files with non-empty comments';
  782. }
  783. } elseif (!empty($_REQUEST['trackzero'])) {
  784. $SQLquery = 'SELECT `filename`, `track`';
  785. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  786. $SQLquery .= ' WHERE (`track` <> "")';
  787. $SQLquery .= ' AND ((`track` < "1")';
  788. $SQLquery .= ' OR (`track` > "99"))';
  789. $SQLquery .= ' ORDER BY `filename` ASC';
  790. $result = mysqli_query_safe($con, $SQLquery);
  791. if (!empty($_REQUEST['m3u'])) {
  792. header('Content-type: audio/x-mpegurl');
  793. echo '#EXTM3U'."\n";
  794. while ($row = mysqli_fetch_array($result)) {
  795. if ((strlen($row['track_number']) > 0) && ($row['track_number'] < 1) || ($row['track_number'] > 99)) {
  796. echo WindowsShareSlashTranslate($row['filename'])."\n";
  797. }
  798. }
  799. exit;
  800. } else {
  801. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?trackzero='.urlencode($_REQUEST['trackzero']).'&m3u=1').'">.m3u version</a><br>';
  802. $TrackZeroCounter = 0;
  803. echo '<table border="1" cellspacing="0" cellpadding="3">';
  804. echo '<tr><th>m3u</th><th>filename</th><th>track</th></tr>';
  805. while ($row = mysqli_fetch_array($result)) {
  806. if ((strlen($row['track_number']) > 0) && ($row['track_number'] < 1) || ($row['track_number'] > 99)) {
  807. $TrackZeroCounter++;
  808. echo '<tr>';
  809. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">m3u</a></td>';
  810. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  811. echo '<td>'.htmlentities($row['track_number']).'</td>';
  812. echo '</tr>';
  813. }
  814. }
  815. echo '</table>';
  816. echo '<b>'.number_format($TrackZeroCounter).'</b> files with track "zero"';
  817. }
  818. } elseif (!empty($_REQUEST['titlefeat'])) {
  819. $SQLquery = 'SELECT `filename`, `title`';
  820. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  821. $SQLquery .= ' WHERE (`title` LIKE "%feat.%")';
  822. $SQLquery .= ' ORDER BY `filename` ASC';
  823. $result = mysqli_query_safe($con, $SQLquery);
  824. if (!empty($_REQUEST['m3u'])) {
  825. header('Content-type: audio/x-mpegurl');
  826. echo '#EXTM3U'."\n";
  827. while ($row = mysqli_fetch_array($result)) {
  828. echo WindowsShareSlashTranslate($row['filename'])."\n";
  829. }
  830. exit;
  831. } else {
  832. echo '<b>'.number_format(mysqli_num_rows($result)).'</b> files with "feat." in the title (instead of the artist)<br><br>';
  833. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?titlefeat='.urlencode($_REQUEST['titlefeat']).'&m3u=1').'">.m3u version</a><br>';
  834. echo '<table border="1" cellspacing="0" cellpadding="3">';
  835. echo '<tr><th>m3u</th><th>filename</th><th>title</th></tr>';
  836. while ($row = mysqli_fetch_array($result)) {
  837. echo '<tr>';
  838. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">m3u</a></td>';
  839. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  840. echo '<td>'.preg_replace('#(feat\. .*)#i', '<b>\\1</b>', htmlentities($row['title'])).'</td>';
  841. echo '</tr>';
  842. }
  843. echo '</table>';
  844. }
  845. } elseif (!empty($_REQUEST['tracknoalbum'])) {
  846. $SQLquery = 'SELECT `filename`, `track`, `album`';
  847. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  848. $SQLquery .= ' WHERE (`track` <> "")';
  849. $SQLquery .= ' AND (`album` = "")';
  850. $SQLquery .= ' ORDER BY `filename` ASC';
  851. $result = mysqli_query_safe($con, $SQLquery);
  852. if (!empty($_REQUEST['m3u'])) {
  853. header('Content-type: audio/x-mpegurl');
  854. echo '#EXTM3U'."\n";
  855. while ($row = mysqli_fetch_array($result)) {
  856. echo WindowsShareSlashTranslate($row['filename'])."\n";
  857. }
  858. exit;
  859. } else {
  860. echo '<b>'.number_format(mysqli_num_rows($result)).'</b> files with a track number, but no album<br><br>';
  861. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?tracknoalbum='.urlencode($_REQUEST['tracknoalbum']).'&m3u=1').'">.m3u version</a><br>';
  862. echo '<table border="1" cellspacing="0" cellpadding="3">';
  863. echo '<tr><th>m3u</th><th>filename</th><th>track</th><th>album</th></tr>';
  864. while ($row = mysqli_fetch_array($result)) {
  865. echo '<tr>';
  866. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">m3u</a></td>';
  867. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  868. echo '<td>'.htmlentities($row['track_number']).'</td>';
  869. echo '<td>'.htmlentities($row['album']).'</td>';
  870. echo '</tr>';
  871. }
  872. echo '</table>';
  873. }
  874. } elseif (!empty($_REQUEST['synchronizetagsfrom']) && !empty($_REQUEST['filename'])) {
  875. echo 'Applying new tags from <b>'.$_REQUEST['synchronizetagsfrom'].'</b> in <b>'.htmlentities($_REQUEST['filename']).'</b><ul>';
  876. $errors = array();
  877. if (SynchronizeAllTags($_REQUEST['filename'], $_REQUEST['synchronizetagsfrom'], 'A12', $errors)) {
  878. echo '<li>Sucessfully wrote tags</li>';
  879. } else {
  880. echo '<li>Tag writing had errors: <ul><li>'.implode('</li><li>', $errors).'</li></ul></li>';
  881. }
  882. echo '</ul>';
  883. } elseif (!empty($_REQUEST['unsynchronizedtags'])) {
  884. $NotOKfiles = 0;
  885. $Autofixedfiles = 0;
  886. $FieldsToCompare = array('title', 'artist', 'album', 'year', 'genre', 'comment', 'track_number');
  887. $TagsToCompare = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false);
  888. $ID3v1FieldLengths = array('title'=>30, 'artist'=>30, 'album'=>30, 'year'=>4, 'genre'=>99, 'comment'=>28);
  889. if (strpos($_REQUEST['unsynchronizedtags'], '2') !== false) {
  890. $TagsToCompare['id3v2'] = true;
  891. }
  892. if (strpos($_REQUEST['unsynchronizedtags'], 'A') !== false) {
  893. $TagsToCompare['ape'] = true;
  894. }
  895. if (strpos($_REQUEST['unsynchronizedtags'], 'L') !== false) {
  896. $TagsToCompare['lyrics3'] = true;
  897. }
  898. if (strpos($_REQUEST['unsynchronizedtags'], '1') !== false) {
  899. $TagsToCompare['id3v1'] = true;
  900. }
  901. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?unsynchronizedtags='.urlencode($_REQUEST['unsynchronizedtags']).'&autofix=1').'">Auto-fix empty tags</a><br><br>';
  902. echo '<div id="Autofixing"></div>';
  903. echo '<table border="1" cellspacing="0" cellpadding="3">';
  904. echo '<tr>';
  905. echo '<th>View</th>';
  906. echo '<th>Filename</th>';
  907. echo '<th>Combined</th>';
  908. if ($TagsToCompare['id3v2']) {
  909. echo '<th><a href="'.htmlentities($_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>';
  910. }
  911. if ($TagsToCompare['ape']) {
  912. echo '<th><a href="'.htmlentities($_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>';
  913. }
  914. if ($TagsToCompare['lyrics3']) {
  915. echo '<th>Lyrics3</th>';
  916. }
  917. if ($TagsToCompare['id3v1']) {
  918. echo '<th><a href="'.htmlentities($_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>';
  919. }
  920. echo '</tr>';
  921. $SQLquery = 'SELECT `filename`, `comments_all`, `comments_id3v2`, `comments_ape`, `comments_lyrics3`, `comments_id3v1`';
  922. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  923. $SQLquery .= ' WHERE (`fileformat` = "mp3")';
  924. $SQLquery .= ' ORDER BY `filename` ASC';
  925. $result = mysqli_query_safe($con, $SQLquery);
  926. $lastdir = '';
  927. $serializedCommentsFields = array('all', 'id3v2', 'ape', 'lyrics3', 'id3v1');
  928. while ($row = mysqli_fetch_array($result)) {
  929. set_time_limit(30);
  930. if ($lastdir != dirname($row['filename'])) {
  931. echo '<script type="text/javascript">if (document.getElementById("Autofixing")) document.getElementById("Autofixing").innerHTML = "'.htmlentities($lastdir, ENT_QUOTES).'";</script>';
  932. flush();
  933. }
  934. $FileOK = true;
  935. $Mismatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false);
  936. $SemiMatched = array('id3v2'=>false, 'ape'=>false, 'lyrics3'=>false, 'id3v1'=>false);
  937. $EmptyTags = array('id3v2'=>true, 'ape'=>true, 'lyrics3'=>true, 'id3v1'=>true);
  938. foreach ($serializedCommentsFields as $field) {
  939. $Comments[$field] = array();
  940. ob_start();
  941. if ($unserialized = unserialize($row['comments_'.$field])) {
  942. $Comments[$field] = $unserialized;
  943. }
  944. $errormessage = ob_get_contents();
  945. ob_end_clean();
  946. }
  947. if (isset($Comments['ape']['tracknumber'])) {
  948. $Comments['ape']['track_number'] = $Comments['ape']['tracknumber'];
  949. unset($Comments['ape']['tracknumber']);
  950. }
  951. if (isset($Comments['ape']['track'])) {
  952. $Comments['ape']['track_number'] = $Comments['ape']['track'];
  953. unset($Comments['ape']['track']);
  954. }
  955. if (!empty($Comments['all']['track'])) {
  956. $besttrack = '';
  957. foreach ($Comments['all']['track'] as $key => $value) {
  958. if (strlen($value) > strlen($besttrack)) {
  959. $besttrack = $value;
  960. }
  961. }
  962. $Comments['all']['track_number'] = array(0=>$besttrack);
  963. }
  964. $ThisLine = '<tr>';
  965. $ThisLine .= '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">view</a></td>';
  966. $ThisLine .= '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  967. $tagvalues = '';
  968. foreach ($FieldsToCompare as $fieldname) {
  969. $tagvalues .= $fieldname.' = '.(!empty($Comments['all'][$fieldname]) ? implode(" \n", $Comments['all'][$fieldname]) : '')." \n";
  970. }
  971. $ThisLine .= '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?synchronizetagsfrom=all&filename='.urlencode($row['filename'])).'" title="'.htmlentities(rtrim($tagvalues, "\n"), ENT_QUOTES).'" target="retagwindow">all</a></td>';
  972. foreach ($TagsToCompare as $tagtype => $CompareThisTagType) {
  973. if ($CompareThisTagType) {
  974. $tagvalues = '';
  975. foreach ($FieldsToCompare as $fieldname) {
  976. if ($tagtype == 'id3v1') {
  977. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
  978. if (($fieldname == 'genre') && !empty($Comments['all'][$fieldname][0]) && !getid3_id3v1::LookupGenreID($Comments['all'][$fieldname][0])) {
  979. // non-standard genres can never match, so just ignore
  980. $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
  981. } elseif ($fieldname == 'comment') {
  982. if (isset($Comments[$tagtype][$fieldname][0]) && isset($Comments['all'][$fieldname][0]) && (rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 28)) != rtrim(substr($Comments['all'][$fieldname][0], 0, 28)))) {
  983. $tagvalues .= $fieldname.' = [['.$Comments[$tagtype][$fieldname][0].']]'."\n";
  984. if (trim(strtolower(RemoveAccents(substr($Comments[$tagtype][$fieldname][0], 0, 28)))) == trim(strtolower(RemoveAccents(substr($Comments['all'][$fieldname][0], 0, 28))))) {
  985. $SemiMatched[$tagtype] = true;
  986. } else {
  987. $Mismatched[$tagtype] = true;
  988. }
  989. $FileOK = false;
  990. } else {
  991. $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
  992. }
  993. } elseif ($fieldname == 'track_number') {
  994. // intval('01/20') == intval('1')
  995. $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '');
  996. $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '');
  997. if (intval($trackA) != intval($trackB)) {
  998. $tagvalues .= $fieldname.' = [['.$trackA.']]'."\n";
  999. $Mismatched[$tagtype] = true;
  1000. $FileOK = false;
  1001. } else {
  1002. $tagvalues .= $fieldname.' = '.$trackA."\n";
  1003. }
  1004. } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? rtrim(substr($Comments[$tagtype][$fieldname][0], 0, 30)) : '') != (isset($Comments['all'][$fieldname][0]) ? rtrim(substr($Comments['all'][$fieldname][0], 0, 30)) : '')) {
  1005. $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n";
  1006. if (strtolower(RemoveAccents(trim(substr((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : ''), 0, 30)))) == strtolower(RemoveAccents(trim(substr((isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : ''), 0, 30))))) {
  1007. $SemiMatched[$tagtype] = true;
  1008. } else {
  1009. $Mismatched[$tagtype] = true;
  1010. }
  1011. $FileOK = false;
  1012. if (!empty($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
  1013. $EmptyTags[$tagtype] = false;
  1014. }
  1015. } else {
  1016. $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
  1017. if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
  1018. $EmptyTags[$tagtype] = false;
  1019. }
  1020. }
  1021. } elseif (($tagtype == 'ape') && ($fieldname == 'year')) {
  1022. if (((isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : '')) && ((isset($Comments['ape']['year'][0]) ? $Comments['ape']['year'][0] : '') != (isset($Comments['all']['year'][0]) ? $Comments['all']['year'][0] : ''))) {
  1023. $tagvalues .= $fieldname.' = [['.(isset($Comments['ape']['date'][0]) ? $Comments['ape']['date'][0] : '').']]'."\n";
  1024. $Mismatched[$tagtype] = true;
  1025. $FileOK = false;
  1026. if (isset($Comments['ape']['date'][0]) && (strlen(trim($Comments['ape']['date'][0])) > 0)) {
  1027. $EmptyTags[$tagtype] = false;
  1028. }
  1029. } else {
  1030. $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
  1031. if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
  1032. $EmptyTags[$tagtype] = false;
  1033. }
  1034. }
  1035. } elseif (($fieldname == 'genre') && !empty($Comments['all'][$fieldname]) && !empty($Comments[$tagtype][$fieldname]) && in_array($Comments[$tagtype][$fieldname][0], $Comments['all'][$fieldname])) {
  1036. $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
  1037. if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
  1038. $EmptyTags[$tagtype] = false;
  1039. }
  1040. } elseif ((isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '') != (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '')) {
  1041. $skiptracknumberfield = false;
  1042. switch ($fieldname) {
  1043. case 'track':
  1044. case 'tracknumber':
  1045. case 'track_number':
  1046. $trackA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '');
  1047. $trackB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '');
  1048. if (intval($trackA) == intval($trackB)) {
  1049. $skiptracknumberfield = true;
  1050. }
  1051. break;
  1052. }
  1053. if (!$skiptracknumberfield) {
  1054. $tagvalues .= $fieldname.' = [['.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '').']]'."\n";
  1055. $tagA = (isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '');
  1056. $tagB = (isset($Comments['all'][$fieldname][0]) ? $Comments['all'][$fieldname][0] : '');
  1057. if (trim(strtolower(RemoveAccents($tagA))) == trim(strtolower(RemoveAccents($tagB)))) {
  1058. $SemiMatched[$tagtype] = true;
  1059. } else {
  1060. $Mismatched[$tagtype] = true;
  1061. }
  1062. $FileOK = false;
  1063. if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
  1064. $EmptyTags[$tagtype] = false;
  1065. }
  1066. }
  1067. } else {
  1068. $tagvalues .= $fieldname.' = '.(isset($Comments[$tagtype][$fieldname][0]) ? $Comments[$tagtype][$fieldname][0] : '')."\n";
  1069. if (isset($Comments[$tagtype][$fieldname][0]) && (strlen(trim($Comments[$tagtype][$fieldname][0])) > 0)) {
  1070. $EmptyTags[$tagtype] = false;
  1071. }
  1072. }
  1073. }
  1074. if ($EmptyTags[$tagtype]) {
  1075. $FileOK = false;
  1076. $ThisLine .= '<td bgcolor="#0099cc">';
  1077. } elseif ($SemiMatched[$tagtype]) {
  1078. $ThisLine .= '<td bgcolor="#ff9999">';
  1079. } elseif ($Mismatched[$tagtype]) {
  1080. $ThisLine .= '<td bgcolor="#ff0000">';
  1081. } else {
  1082. $ThisLine .= '<td bgcolor="#00cc00">';
  1083. }
  1084. $ThisLine .= '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?synchronizetagsfrom='.$tagtype.'&filename='.urlencode($row['filename'])).'" title="'.htmlentities(rtrim($tagvalues, "\n"), ENT_QUOTES).'" TARGET="retagwindow">'.$tagtype.'</a>';
  1085. $ThisLine .= '</td>';
  1086. }
  1087. }
  1088. $ThisLine .= '</tr>';
  1089. if (!$FileOK) {
  1090. $NotOKfiles++;
  1091. echo '<script type="text/javascript">if (document.getElementById("Autofixing")) document.getElementById("Autofixing").innerHTML = "'.htmlentities($row['filename'], ENT_QUOTES).'";</script>';
  1092. flush();
  1093. if (!empty($_REQUEST['autofix'])) {
  1094. $AnyMismatched = false;
  1095. foreach ($Mismatched as $key => $value) {
  1096. if ($value && ($EmptyTags["$key"] === false)) {
  1097. $AnyMismatched = true;
  1098. }
  1099. }
  1100. if ($AnyMismatched && empty($_REQUEST['autofixforcesource'])) {
  1101. echo $ThisLine;
  1102. } else {
  1103. $TagsToSynch = '';
  1104. foreach ($EmptyTags as $key => $value) {
  1105. if ($value) {
  1106. switch ($key) {
  1107. case 'id3v1':
  1108. $TagsToSynch .= '1';
  1109. break;
  1110. case 'id3v2':
  1111. $TagsToSynch .= '2';
  1112. break;
  1113. case 'ape':
  1114. $TagsToSynch .= 'A';
  1115. break;
  1116. }
  1117. }
  1118. }
  1119. $autofixforcesource = (!empty($_REQUEST['autofixforcesource']) ? $_REQUEST['autofixforcesource'] : 'all');
  1120. $TagsToSynch = (!empty($_REQUEST['autofixforcedest']) ? $_REQUEST['autofixforcedest'] : $TagsToSynch);
  1121. $errors = array();
  1122. if (SynchronizeAllTags($row['filename'], $autofixforcesource, $TagsToSynch, $errors)) {
  1123. $Autofixedfiles++;
  1124. echo '<tr bgcolor="#00CC00">';
  1125. } else {
  1126. echo '<tr bgcolor="#FF0000">';
  1127. }
  1128. echo '<td>&nbsp;</th>';
  1129. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename'])).'" title="'.htmlentities(implode("\n", $errors), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1130. echo '<td><table border="0">';
  1131. echo '<tr><td><b>'.$TagsToSynch.'</b></td></tr>';
  1132. echo '</table></td></tr>';
  1133. }
  1134. } else {
  1135. echo $ThisLine;
  1136. }
  1137. }
  1138. }
  1139. echo '</table><br>';
  1140. echo '<script type="text/javascript">if (document.getElementById("Autofixing")) document.getElementById("Autofixing").innerHTML = "";</script>';
  1141. echo 'Found <b>'.number_format($NotOKfiles).'</b> files with unsynchronized tags, and auto-fixed '.number_format($Autofixedfiles).' of them.';
  1142. } elseif (!empty($_REQUEST['filenamepattern'])) {
  1143. $patterns['A'] = 'artist';
  1144. $patterns['T'] = 'title';
  1145. $patterns['M'] = 'album';
  1146. $patterns['N'] = 'track';
  1147. $patterns['G'] = 'genre';
  1148. $patterns['R'] = 'remix';
  1149. $FieldsToUse = explode(' ', wordwrap(preg_replace('#[^A-Z]#i', '', $_REQUEST['filenamepattern']), 1, ' ', 1));
  1150. //$FieldsToUse = explode(' ', wordwrap($_REQUEST['filenamepattern'], 1, ' ', 1));
  1151. foreach ($FieldsToUse as $FieldID) {
  1152. $FieldNames[] = $patterns["$FieldID"];
  1153. }
  1154. $SQLquery = 'SELECT `filename`, `fileformat`, '.implode(', ', $FieldNames);
  1155. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1156. $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1157. $SQLquery .= ' ORDER BY `filename` ASC';
  1158. $result = mysqli_query_safe($con, $SQLquery);
  1159. echo 'Files that do not match naming pattern: (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?filenamepattern='.urlencode($_REQUEST['filenamepattern']).'&autofix=1').'">auto-fix</a>)<br>';
  1160. echo '<table border="1" cellspacing="0" cellpadding="3">';
  1161. 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>'.(empty($_REQUEST['autofix']) ? '<br>(click to rename file to this)' : '').'</td></tr>';
  1162. $nonmatchingfilenames = 0;
  1163. $Pattern = $_REQUEST['filenamepattern'];
  1164. $PatternLength = strlen($Pattern);
  1165. while ($row = mysqli_fetch_array($result)) {
  1166. set_time_limit(10);
  1167. $PatternFilename = '';
  1168. for ($i = 0; $i < $PatternLength; $i++) {
  1169. if (isset($patterns[$Pattern[$i]])) {
  1170. $PatternFilename .= trim(strtr($row[$patterns[$Pattern[$i]]], ':\\*<>|', ';-¤«»¦'), ' ');
  1171. } else {
  1172. $PatternFilename .= $Pattern[$i];
  1173. }
  1174. }
  1175. // Replace "~" with "-" if characters immediately before and after are both numbers,
  1176. // "/" has been replaced with "~" above which is good for multi-song medley dividers,
  1177. // but for things like 24/7, 7/8ths, etc it looks better if it's 24-7, 7-8ths, etc.
  1178. $PatternFilename = preg_replace('#([ a-z]+)/([ a-z]+)#i', '\\1~\\2', $PatternFilename);
  1179. $PatternFilename = str_replace('/', '×', $PatternFilename);
  1180. $PatternFilename = str_replace('?', '¿', $PatternFilename);
  1181. $PatternFilename = str_replace(' "', ' “', $PatternFilename);
  1182. $PatternFilename = str_replace('("', '(“', $PatternFilename);
  1183. $PatternFilename = str_replace('-"', '-“', $PatternFilename);
  1184. $PatternFilename = str_replace('" ', '” ', $PatternFilename.' ');
  1185. $PatternFilename = str_replace('"', '”', $PatternFilename);
  1186. $PatternFilename = str_replace(' ', ' ', $PatternFilename);
  1187. $ParenthesesPairs = array('()', '[]', '{}');
  1188. foreach ($ParenthesesPairs as $pair) {
  1189. // multiple remixes are stored tab-seperated in the database.
  1190. // change "{2000 Version\tSomebody Remix}" into "{2000 Version} {Somebody Remix}"
  1191. while (preg_match('#^(.*)'.preg_quote($pair[0]).'([^'.preg_quote($pair[1]).']*)('."\t".')([^'.preg_quote($pair[0]).']*)'.preg_quote($pair[1]).'#', $PatternFilename, $matches)) {
  1192. $PatternFilename = $matches[1].$pair[0].$matches[2].$pair[1].' '.$pair[0].$matches[4].$pair[1];
  1193. }
  1194. // remove empty parenthesized pairs (probably where no track numbers, remix version, etc)
  1195. $PatternFilename = preg_replace('#'.preg_quote($pair).'#', '', $PatternFilename);
  1196. // "[01] - Title With No Artist.mp3" ==> "[01] Title With No Artist.mp3"
  1197. $PatternFilename = preg_replace('#'.preg_quote($pair[1]).' +\- #', $pair[1].' ', $PatternFilename);
  1198. }
  1199. // get rid of leading & trailing spaces if end items (artist or title for example) are missing
  1200. $PatternFilename = trim($PatternFilename, ' -');
  1201. if (!$PatternFilename) {
  1202. // no tags to create a filename from -- skip this file
  1203. continue;
  1204. }
  1205. $PatternFilename .= '.'.$row['fileformat'];
  1206. $ActualFilename = basename($row['filename']);
  1207. if ($ActualFilename != $PatternFilename) {
  1208. $NotMatchedReasons = '';
  1209. if (strtolower($ActualFilename) === strtolower($PatternFilename)) {
  1210. $NotMatchedReasons .= 'Aa ';
  1211. } elseif (RemoveAccents($ActualFilename) === RemoveAccents($PatternFilename)) {
  1212. $NotMatchedReasons .= 'ée ';
  1213. }
  1214. $actualExt = '.'.fileextension($ActualFilename);
  1215. $patternExt = '.'.fileextension($PatternFilename);
  1216. $ActualFilenameNoExt = (($actualExt != '.') ? substr($ActualFilename, 0, 0 - strlen($actualExt)) : $ActualFilename);
  1217. $PatternFilenameNoExt = (($patternExt != '.') ? substr($PatternFilename, 0, 0 - strlen($patternExt)) : $PatternFilename);
  1218. if (strpos($PatternFilenameNoExt, $ActualFilenameNoExt) !== false) {
  1219. $DifferenceBoldedName = str_replace($ActualFilenameNoExt, '</b>'.$ActualFilenameNoExt.'<b>', $PatternFilenameNoExt);
  1220. } else {
  1221. $ShortestNameLength = min(strlen($ActualFilenameNoExt), strlen($PatternFilenameNoExt));
  1222. for ($DifferenceOffset = 0; $DifferenceOffset < $ShortestNameLength; $DifferenceOffset++) {
  1223. if ($ActualFilenameNoExt[$DifferenceOffset] !== $PatternFilenameNoExt[$DifferenceOffset]) {
  1224. break;
  1225. }
  1226. }
  1227. $DifferenceBoldedName = '</b>'.substr($PatternFilenameNoExt, 0, $DifferenceOffset).'<b>'.substr($PatternFilenameNoExt, $DifferenceOffset);
  1228. }
  1229. $DifferenceBoldedName .= (($actualExt == $patternExt) ? '</b>'.$patternExt.'<b>' : $patternExt);
  1230. echo '<tr>';
  1231. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename'])).'">view</a></td>';
  1232. echo '<td>&nbsp;'.$NotMatchedReasons.'</td>';
  1233. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($ActualFilename).'</a></td>';
  1234. if (!empty($_REQUEST['autofix'])) {
  1235. $results = '';
  1236. if (RenameFileFromTo($row['filename'], dirname($row['filename']).'/'.$PatternFilename, $results)) {
  1237. echo '<TD BGCOLOR="#009900">';
  1238. } else {
  1239. echo '<TD BGCOLOR="#FF0000">';
  1240. }
  1241. echo '<b>'.$DifferenceBoldedName.'</b></td>';
  1242. } else {
  1243. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?filenamepattern='.urlencode($_REQUEST['filenamepattern']).'&renamefilefrom='.urlencode($row['filename']).'&renamefileto='.urlencode(dirname($row['filename']).'/'.$PatternFilename)).'" title="'.htmlentities(basename($row['filename'])."\n".basename($PatternFilename), ENT_QUOTES).'" target="renamewindow">';
  1244. echo '<b>'.$DifferenceBoldedName.'</b></a></td>';
  1245. }
  1246. echo '</tr>';
  1247. $nonmatchingfilenames++;
  1248. }
  1249. }
  1250. echo '</table><br>';
  1251. echo 'Found '.number_format($nonmatchingfilenames).' files that do not match naming pattern<br>';
  1252. } elseif (!empty($_REQUEST['encoderoptionsdistribution'])) {
  1253. if (isset($_REQUEST['showtagfiles'])) {
  1254. $SQLquery = 'SELECT `filename`, `encoder_options` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1255. $SQLquery .= ' WHERE (`encoder_options` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['showtagfiles']).'")';
  1256. $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1257. $SQLquery .= ' ORDER BY `filename` ASC';
  1258. $result = mysqli_query_safe($con, $SQLquery);
  1259. if (!empty($_REQUEST['m3u'])) {
  1260. header('Content-type: audio/x-mpegurl');
  1261. echo '#EXTM3U'."\n";
  1262. while ($row = mysqli_fetch_array($result)) {
  1263. echo WindowsShareSlashTranslate($row['filename'])."\n";
  1264. }
  1265. exit;
  1266. } else {
  1267. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1').'">Show all Encoder Options</a><hr>';
  1268. echo 'Files with Encoder Options <b>'.htmlentities($_REQUEST['showtagfiles']).'</b>:<br>';
  1269. echo '<table border="1" cellspacing="0" cellpadding="3">';
  1270. while ($row = mysqli_fetch_array($result)) {
  1271. echo '<tr>';
  1272. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1273. echo '<td>'.$row['encoder_options'].'</td>';
  1274. echo '</tr>';
  1275. }
  1276. echo '</table>';
  1277. }
  1278. } elseif (!isset($_REQUEST['m3u'])) {
  1279. $SQLquery = 'SELECT `encoder_options`, COUNT(*) AS `num` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1280. $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1281. $SQLquery .= ' GROUP BY `encoder_options`';
  1282. $SQLquery .= ' ORDER BY (`encoder_options` LIKE "LAME%") DESC, (`encoder_options` LIKE "CBR%") DESC, `num` DESC, `encoder_options` ASC';
  1283. $result = mysqli_query_safe($con, $SQLquery);
  1284. echo 'Files with Encoder Options:<br>';
  1285. echo '<table border="1" cellspacing="0" cellpadding="3">';
  1286. echo '<tr><th>Encoder Options</th><th>Count</th><th>M3U</th></tr>';
  1287. while ($row = mysqli_fetch_array($result)) {
  1288. echo '<tr>';
  1289. echo '<td>'.$row['encoder_options'].'</td>';
  1290. echo '<TD ALIGN="RIGHT"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1&showtagfiles='.($row['encoder_options'] ? urlencode($row['encoder_options']) : '')).'">'.number_format($row['num']).'</a></td>';
  1291. echo '<TD ALIGN="RIGHT"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1&showtagfiles='.($row['encoder_options'] ? urlencode($row['encoder_options']) : '').'&m3u=.m3u').'">m3u</a></td>';
  1292. echo '</tr>';
  1293. }
  1294. echo '</table><hr>';
  1295. }
  1296. } elseif (!empty($_REQUEST['tagtypes'])) {
  1297. if (!isset($_REQUEST['m3u'])) {
  1298. $SQLquery = 'SELECT `tags`, COUNT(*) AS `num` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1299. $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1300. $SQLquery .= ' GROUP BY `tags`';
  1301. $SQLquery .= ' ORDER BY `num` DESC';
  1302. $result = mysqli_query_safe($con, $SQLquery);
  1303. echo 'Files with tags:<br>';
  1304. echo '<table border="1" cellspacing="0" cellpadding="3">';
  1305. echo '<tr><th>Tags</th><th>Count</th><th>M3U</th></tr>';
  1306. while ($row = mysqli_fetch_array($result)) {
  1307. echo '<tr>';
  1308. echo '<td>'.$row['tags'].'</td>';
  1309. echo '<td align="right"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?tagtypes=1&showtagfiles='.($row['tags'] ? urlencode($row['tags']) : '')).'">'.number_format($row['num']).'</a></td>';
  1310. echo '<td align="right"><a href="'.htmlentities($_SERVER['PHP_SELF'].'?tagtypes=1&showtagfiles='.($row['tags'] ? urlencode($row['tags']) : '').'&m3u=.m3u').'">m3u</a></td>';
  1311. echo '</tr>';
  1312. }
  1313. echo '</table><hr>';
  1314. }
  1315. if (isset($_REQUEST['showtagfiles'])) {
  1316. $SQLquery = 'SELECT `filename`, `tags` FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1317. $SQLquery .= ' WHERE (`tags` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['showtagfiles']).'")';
  1318. $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1319. $SQLquery .= ' ORDER BY `filename` ASC';
  1320. $result = mysqli_query_safe($con, $SQLquery);
  1321. if (!empty($_REQUEST['m3u'])) {
  1322. header('Content-type: audio/x-mpegurl');
  1323. echo '#EXTM3U'."\n";
  1324. while ($row = mysqli_fetch_array($result)) {
  1325. echo WindowsShareSlashTranslate($row['filename'])."\n";
  1326. }
  1327. exit;
  1328. } else {
  1329. echo '<table border="1" cellspacing="0" cellpadding="3">';
  1330. while ($row = mysqli_fetch_array($result)) {
  1331. echo '<tr>';
  1332. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1333. echo '<td>'.$row['tags'].'</td>';
  1334. echo '</tr>';
  1335. }
  1336. echo '</table>';
  1337. }
  1338. }
  1339. } elseif (!empty($_REQUEST['md5datadupes'])) {
  1340. $OtherFormats = '';
  1341. $AVFormats = '';
  1342. $SQLquery = 'SELECT `md5_data`, `filename`, COUNT(*) AS `num`';
  1343. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1344. $SQLquery .= ' WHERE (`md5_data` <> "")';
  1345. $SQLquery .= ' GROUP BY `md5_data`';
  1346. $SQLquery .= ' ORDER BY `num` DESC';
  1347. $result = mysqli_query_safe($con, $SQLquery);
  1348. while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) {
  1349. set_time_limit(30);
  1350. $filenames = array();
  1351. $tags = array();
  1352. $md5_data = array();
  1353. $SQLquery = 'SELECT `fileformat`, `filename`, `tags`';
  1354. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1355. $SQLquery .= ' WHERE (`md5_data` = "'.mysqli_real_escape_string($con, $row['md5_data']).'")';
  1356. $SQLquery .= ' ORDER BY `filename` ASC';
  1357. $result2 = mysqli_query_safe($con, $SQLquery);
  1358. while ($row2 = mysqli_fetch_array($result2)) {
  1359. $thisfileformat = $row2['fileformat'];
  1360. $filenames[] = $row2['filename'];
  1361. $tags[] = $row2['tags'];
  1362. $md5_data[] = $row['md5_data'];
  1363. }
  1364. $thisline = '<tr>';
  1365. $thisline .= '<TD VALIGN="TOP" style="font-family: monospace;">'.implode('<br>', $md5_data).'</td>';
  1366. $thisline .= '<TD VALIGN="TOP" NOWRAP>'.implode('<br>', $tags).'</td>';
  1367. $thisline .= '<TD VALIGN="TOP">'.implode('<br>', $filenames).'</td>';
  1368. $thisline .= '</tr>';
  1369. if (in_array($thisfileformat, $IgnoreNoTagFormats)) {
  1370. $OtherFormats .= $thisline;
  1371. } else {
  1372. $AVFormats .= $thisline;
  1373. }
  1374. }
  1375. echo 'Duplicated MD5_DATA (Audio/Video files):<table border="1" cellspacing="0" cellpadding="2">';
  1376. echo $AVFormats.'</table><hr>';
  1377. echo 'Duplicated MD5_DATA (Other files):<table border="1" cellspacing="0" cellpadding="2">';
  1378. echo $OtherFormats.'</table><hr>';
  1379. } elseif (!empty($_REQUEST['artisttitledupes'])) {
  1380. if (isset($_REQUEST['m3uartist']) && isset($_REQUEST['m3utitle'])) {
  1381. header('Content-type: audio/x-mpegurl');
  1382. echo '#EXTM3U'."\n";
  1383. $SQLquery = 'SELECT `filename`';
  1384. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1385. $SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $_REQUEST['m3uartist']).'")';
  1386. $SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $_REQUEST['m3utitle']).'")';
  1387. $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC';
  1388. $result = mysqli_query_safe($con, $SQLquery);
  1389. while ($row = mysqli_fetch_array($result)) {
  1390. echo WindowsShareSlashTranslate($row['filename'])."\n";
  1391. }
  1392. exit;
  1393. }
  1394. $SQLquery = 'SELECT `artist`, `title`, `filename`, COUNT(*) AS `num`';
  1395. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1396. $SQLquery .= ' WHERE (`artist` <> "")';
  1397. $SQLquery .= ' AND (`title` <> "")';
  1398. $SQLquery .= ' GROUP BY `artist`, `title`'.(!empty($_REQUEST['samemix']) ? ', `remix`' : '');
  1399. $SQLquery .= ' ORDER BY `num` DESC, `artist` ASC, `title` ASC, `playtime_seconds` ASC, `remix` ASC';
  1400. $result = mysqli_query_safe($con, $SQLquery);
  1401. $uniquetitles = 0;
  1402. $uniquefiles = 0;
  1403. if (!empty($_REQUEST['m3u'])) {
  1404. header('Content-type: audio/x-mpegurl');
  1405. echo '#EXTM3U'."\n";
  1406. while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) {
  1407. $SQLquery = 'SELECT `filename`';
  1408. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1409. $SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $row['artist']).'")';
  1410. $SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $row['title']).'")';
  1411. if (!empty($_REQUEST['samemix'])) {
  1412. $SQLquery .= ' AND (`remix` = "'.mysqli_real_escape_string($con, $row['remix']).'")';
  1413. }
  1414. $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC';
  1415. $result2 = mysqli_query_safe($con, $SQLquery);
  1416. while ($row2 = mysqli_fetch_array($result2)) {
  1417. echo WindowsShareSlashTranslate($row2['filename'])."\n";
  1418. }
  1419. }
  1420. exit;
  1421. } else {
  1422. echo 'Duplicated aritst + title: (<a href="'.htmlentities($_SERVER['PHP_SELF'].'?artisttitledupes=1&samemix=1').'">Identical Mix/Version only</a>)<br>';
  1423. echo '(<a href="'.htmlentities($_SERVER['PHP_SELF'].'?artisttitledupes=1&m3u=.m3u').'">.m3u version</a>)<br>';
  1424. echo '<table border="1" cellspacing="0" cellpadding="2">';
  1425. echo '<tr><th colspan="3">&nbsp;</th><th>Artist</th><th>Title</th><th>Version</th><th>&nbsp;</th><th>&nbsp;</th><th>Filename</th></tr>';
  1426. while (($row = mysqli_fetch_array($result)) && ($row['num'] > 1)) {
  1427. $uniquetitles++;
  1428. set_time_limit(30);
  1429. $filenames = array();
  1430. $artists = array();
  1431. $titles = array();
  1432. $remixes = array();
  1433. $bitrates = array();
  1434. $playtimes = array();
  1435. $SQLquery = 'SELECT `filename`, `artist`, `title`, `remix`, `audio_bitrate`, `vbr_method`, `playtime_seconds`, `encoder_options`';
  1436. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1437. $SQLquery .= ' WHERE (`artist` = "'.mysqli_real_escape_string($con, $row['artist']).'")';
  1438. $SQLquery .= ' AND (`title` = "'.mysqli_real_escape_string($con, $row['title']).'")';
  1439. $SQLquery .= ' ORDER BY `playtime_seconds` ASC, `remix` ASC, `filename` ASC';
  1440. $result2 = mysqli_query_safe($con, $SQLquery);
  1441. while ($row2 = mysqli_fetch_array($result2)) {
  1442. $uniquefiles++;
  1443. $filenames[] = $row2['filename'];
  1444. $artists[] = $row2['artist'];
  1445. $titles[] = $row2['title'];
  1446. $remixes[] = $row2['remix'];
  1447. if ($row2['vbr_method']) {
  1448. $bitrates[] = '<B'.($row2['encoder_options'] ? ' style="text-decoration: underline; cursor: help;" title="'.$row2['encoder_options'] : '').'">'.BitrateText($row2['audio_bitrate'] / 1000).'</b>';
  1449. } else {
  1450. $bitrates[] = BitrateText($row2['audio_bitrate'] / 1000);
  1451. }
  1452. $playtimes[] = getid3_lib::PlaytimeString($row2['playtime_seconds']);
  1453. }
  1454. echo '<tr>';
  1455. echo '<td nowrap valign="top">';
  1456. foreach ($filenames as $file) {
  1457. echo '<a href="'.htmlentities('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="'.htmlentities('Permanently delete '."\n".$file, ENT_QUOTES).'" target="deletedupewindow">delete</a><br>';
  1458. }
  1459. echo '</td>';
  1460. echo '<td nowrap valign="top">';
  1461. foreach ($filenames as $file) {
  1462. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($file)).'">play</a><br>';
  1463. }
  1464. echo '</td>';
  1465. echo '<td valign="middle" align="center" ><a href="'.htmlentities($_SERVER['PHP_SELF'].'?artisttitledupes=1&m3uartist='.urlencode($artists[0]).'&m3utitle='.urlencode($titles[0])).'">play all</a></td>';
  1466. echo '<td valign="top" nowrap>'.implode('<br>', $artists).'</td>';
  1467. echo '<td valign="top" nowrap>'.implode('<br>', $titles).'</td>';
  1468. echo '<td valign="top" nowrap>'.implode('<br>', $remixes).'</td>';
  1469. echo '<td valign="top" nowrap align="right">'.implode('<br>', $bitrates).'</td>';
  1470. echo '<td valign="top" nowrap align="right">'.implode('<br>', $playtimes).'</td>';
  1471. echo '<td valign="top" nowrap align="left"><table border="0" cellspacing="0" cellpadding="0">';
  1472. foreach ($filenames as $file) {
  1473. echo '<tr><td nowrap align="right"><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($file)).'"><span style="color: #339966;">'.dirname($file).'/</span>'.basename($file).'</a></td></tr>';
  1474. }
  1475. echo '</table></td>';
  1476. echo '</tr>';
  1477. }
  1478. }
  1479. echo '</table>';
  1480. echo number_format($uniquefiles).' files with '.number_format($uniquetitles).' unique <i>aritst + title</i><br>';
  1481. echo '<hr>';
  1482. } elseif (!empty($_REQUEST['filetypelist'])) {
  1483. list($fileformat, $audioformat) = explode('|', $_REQUEST['filetypelist']);
  1484. $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`';
  1485. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1486. $SQLquery .= ' WHERE (`fileformat` = "'.mysqli_real_escape_string($con, $fileformat).'")';
  1487. $SQLquery .= ' AND (`audio_dataformat` = "'.mysqli_real_escape_string($con, $audioformat).'")';
  1488. $SQLquery .= ' ORDER BY `filename` ASC';
  1489. $result = mysqli_query_safe($con, $SQLquery);
  1490. echo 'Files of format <b>'.$fileformat.'.'.$audioformat.'</b>:<table border="1" cellspacing="0" cellpadding="4">';
  1491. echo '<tr><th>file</th><th>audio</th><th>filename</th></tr>';
  1492. while ($row = mysqli_fetch_array($result)) {
  1493. echo '<tr>';
  1494. echo '<td>'.$row['fileformat'].'</td>';
  1495. echo '<td>'.$row['audio_dataformat'].'</td>';
  1496. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1497. echo '</tr>';
  1498. }
  1499. echo '</table><hr>';
  1500. } elseif (!empty($_REQUEST['trackinalbum'])) {
  1501. $SQLquery = 'SELECT `filename`, `album`';
  1502. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1503. $SQLquery .= ' WHERE (`album` LIKE "% [%")';
  1504. $SQLquery .= ' ORDER BY `album` ASC, `filename` ASC';
  1505. $result = mysqli_query_safe($con, $SQLquery);
  1506. if (!empty($_REQUEST['m3u'])) {
  1507. header('Content-type: audio/x-mpegurl');
  1508. echo '#EXTM3U'."\n";
  1509. while ($row = mysqli_fetch_array($result)) {
  1510. echo WindowsShareSlashTranslate($row['filename'])."\n";
  1511. }
  1512. exit;
  1513. } elseif (!empty($_REQUEST['autofix'])) {
  1514. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
  1515. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v2.php', __FILE__, true);
  1516. while ($row = mysqli_fetch_array($result)) {
  1517. set_time_limit(30);
  1518. $ThisFileInfo = $getID3->analyze($filename);
  1519. $getID3->CopyTagsToComments($ThisFileInfo);
  1520. if (!empty($ThisFileInfo['tags'])) {
  1521. $Album = trim(str_replace(strstr($ThisFileInfo['comments']['album'][0], ' ['), '', $ThisFileInfo['comments']['album'][0]));
  1522. $Track = (string) intval(str_replace(' [', '', str_replace(']', '', strstr($ThisFileInfo['comments']['album'][0], ' ['))));
  1523. if ($Track == '0') {
  1524. $Track = '';
  1525. }
  1526. if ($Album && $Track) {
  1527. echo '<hr>'.htmlentities($row['filename']).'<br>';
  1528. echo '<i>'.htmlentities($Album).'</i> (track #'.$Track.')<br>';
  1529. echo '<b>ID3v2:</b> '.(RemoveID3v2($row['filename'], false) ? 'removed' : 'REMOVAL FAILED!').', ';
  1530. $WriteID3v1_title = (isset($ThisFileInfo['comments']['title'][0]) ? $ThisFileInfo['comments']['title'][0] : '');
  1531. $WriteID3v1_artist = (isset($ThisFileInfo['comments']['artist'][0]) ? $ThisFileInfo['comments']['artist'][0] : '');
  1532. $WriteID3v1_year = (isset($ThisFileInfo['comments']['year'][0]) ? $ThisFileInfo['comments']['year'][0] : '');
  1533. $WriteID3v1_comment = (isset($ThisFileInfo['comments']['comment'][0]) ? $ThisFileInfo['comments']['comment'][0] : '');
  1534. $WriteID3v1_genreid = (isset($ThisFileInfo['comments']['genreid'][0]) ? $ThisFileInfo['comments']['genreid'][0] : '');
  1535. echo '<b>ID3v1:</b> '.(WriteID3v1($row['filename'], $WriteID3v1_title, $WriteID3v1_artist, $Album, $WriteID3v1_year, $WriteID3v1_comment, $WriteID3v1_genreid, $Track, false) ? 'updated' : 'UPDATE FAILED').'<br>';
  1536. } else {
  1537. echo ' . ';
  1538. }
  1539. } else {
  1540. echo '<hr>FAILED<br>'.htmlentities($row['filename']).'<hr>';
  1541. }
  1542. flush();
  1543. }
  1544. } else {
  1545. echo '<b>'.number_format(mysqli_num_rows($result)).'</b> files with <b>[??]</b>-format track numbers in album field:<br>';
  1546. if (mysqli_num_rows($result) > 0) {
  1547. echo '(<a href="'.htmlentities($_SERVER['PHP_SELF'].'?trackinalbum=1&m3u=.m3u').'">.m3u version</a>)<br>';
  1548. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?trackinalbum=1&autofix=1').'">Try to auto-fix</a><br>';
  1549. echo '<table border="1" cellspacing="0" cellpadding="4">';
  1550. while ($row = mysqli_fetch_array($result)) {
  1551. echo '<tr>';
  1552. echo '<td>'.$row['album'].'</td>';
  1553. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1554. echo '</tr>';
  1555. }
  1556. echo '</table>';
  1557. }
  1558. echo '<hr>';
  1559. }
  1560. } elseif (!empty($_REQUEST['fileextensions'])) {
  1561. $SQLquery = 'SELECT `filename`, `fileformat`, `audio_dataformat`, `video_dataformat`, `tags`';
  1562. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1563. $SQLquery .= ' ORDER BY `filename` ASC';
  1564. $result = mysqli_query_safe($con, $SQLquery);
  1565. $invalidextensionfiles = 0;
  1566. $invalidextensionline = '<table border="1" cellspacing="0" cellpadding="4">';
  1567. $invalidextensionline .= '<tr><th>file</th><th>audio</th><th>video</th><th>tags</th><th>actual</th><th>correct</th><th>filename</th></tr>';
  1568. while ($row = mysqli_fetch_array($result)) {
  1569. set_time_limit(30);
  1570. $acceptableextensions = AcceptableExtensions($row['fileformat'], $row['audio_dataformat'], $row['video_dataformat']);
  1571. $actualextension = strtolower(fileextension($row['filename']));
  1572. if ($acceptableextensions && !in_array($actualextension, $acceptableextensions)) {
  1573. $invalidextensionfiles++;
  1574. $invalidextensionline .= '<tr>';
  1575. $invalidextensionline .= '<td>'.$row['fileformat'].'</td>';
  1576. $invalidextensionline .= '<td>'.$row['audio_dataformat'].'</td>';
  1577. $invalidextensionline .= '<td>'.$row['video_dataformat'].'</td>';
  1578. $invalidextensionline .= '<td>'.$row['tags'].'</td>';
  1579. $invalidextensionline .= '<td>'.$actualextension.'</td>';
  1580. $invalidextensionline .= '<td>'.implode('; ', $acceptableextensions).'</td>';
  1581. $invalidextensionline .= '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1582. $invalidextensionline .= '</tr>';
  1583. }
  1584. }
  1585. $invalidextensionline .= '</table><hr>';
  1586. echo number_format($invalidextensionfiles).' files with incorrect filename extension:<br>';
  1587. echo $invalidextensionline;
  1588. } elseif (isset($_REQUEST['genredistribution'])) {
  1589. if (!empty($_REQUEST['m3u'])) {
  1590. header('Content-type: audio/x-mpegurl');
  1591. echo '#EXTM3U'."\n";
  1592. $SQLquery = 'SELECT `filename`';
  1593. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1594. $SQLquery .= ' WHERE (BINARY `genre` = "'.$_REQUEST['genredistribution'].'")';
  1595. $SQLquery .= ' AND (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1596. $SQLquery .= ' ORDER BY `filename` ASC';
  1597. $result = mysqli_query_safe($con, $SQLquery);
  1598. while ($row = mysqli_fetch_array($result)) {
  1599. echo WindowsShareSlashTranslate($row['filename'])."\n";
  1600. }
  1601. exit;
  1602. } else {
  1603. if ($_REQUEST['genredistribution'] == '%') {
  1604. $SQLquery = 'SELECT COUNT(*) AS `num`, `genre`';
  1605. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1606. $SQLquery .= ' WHERE (`fileformat` NOT LIKE "'.implode('") AND (`fileformat` NOT LIKE "', $IgnoreNoTagFormats).'")';
  1607. $SQLquery .= ' GROUP BY `genre`';
  1608. $SQLquery .= ' ORDER BY `num` DESC';
  1609. $result = mysqli_query_safe($con, $SQLquery);
  1610. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'module.tag.id3v1.php', __FILE__, true);
  1611. echo '<table border="1" cellspacing="0" cellpadding="4">';
  1612. echo '<tr><th>Count</th><th>Genre</th><th>m3u</th></tr>';
  1613. while ($row = mysqli_fetch_array($result)) {
  1614. $GenreID = getid3_id3v1::LookupGenreID($row['genre']);
  1615. if (is_numeric($GenreID)) {
  1616. echo '<tr bgcolor="#00FF00;">';
  1617. } else {
  1618. echo '<tr bgcolor="#FF9999;">';
  1619. }
  1620. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?genredistribution='.urlencode($row['genre'])).'">'.number_format($row['num']).'</a></td>';
  1621. echo '<td nowrap>'.str_replace("\t", '<br>', $row['genre']).'</td>';
  1622. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3u=.m3u&genredistribution='.urlencode($row['genre'])).'">.m3u</a></td>';
  1623. echo '</tr>';
  1624. }
  1625. echo '</table><hr>';
  1626. } else {
  1627. $SQLquery = 'SELECT `filename`, `genre`';
  1628. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1629. $SQLquery .= ' WHERE (`genre` LIKE "'.mysqli_real_escape_string($con, $_REQUEST['genredistribution']).'")';
  1630. $SQLquery .= ' ORDER BY `filename` ASC';
  1631. $result = mysqli_query_safe($con, $SQLquery);
  1632. echo '<a href="'.htmlentities($_SERVER['PHP_SELF'].'?genredistribution='.urlencode('%')).'">All Genres</a><br>';
  1633. echo '<table border="1" cellspacing="0" cellpadding="4">';
  1634. echo '<tr><th>Genre</th><th>m3u</th><th>Filename</th></tr>';
  1635. while ($row = mysqli_fetch_array($result)) {
  1636. echo '<tr>';
  1637. echo '<TD NOWRAP>'.str_replace("\t", '<br>', $row['genre']).'</td>';
  1638. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename'])).'">m3u</a></td>';
  1639. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1640. echo '</tr>';
  1641. }
  1642. echo '</table><hr>';
  1643. }
  1644. }
  1645. } elseif (!empty($_REQUEST['formatdistribution'])) {
  1646. $SQLquery = 'SELECT `fileformat`, `audio_dataformat`, COUNT(*) AS `num`';
  1647. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1648. $SQLquery .= ' GROUP BY `fileformat`, `audio_dataformat`';
  1649. $SQLquery .= ' ORDER BY `num` DESC';
  1650. $result = mysqli_query_safe($con, $SQLquery);
  1651. echo 'File format distribution:<table border="1" cellspacing="0" cellpadding="4">';
  1652. echo '<tr><th>Number</th><th>Format</th></tr>';
  1653. while ($row = mysqli_fetch_array($result)) {
  1654. echo '<tr>';
  1655. echo '<TD ALIGN="RIGHT">'.number_format($row['num']).'</td>';
  1656. echo '<td><a href="'.htmlentities($_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>';
  1657. echo '</tr>';
  1658. }
  1659. echo '</table><hr>';
  1660. } elseif (!empty($_REQUEST['errorswarnings'])) {
  1661. $SQLquery = 'SELECT `filename`, `error`, `warning`';
  1662. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1663. $SQLquery .= ' WHERE (`error` <> "")';
  1664. $SQLquery .= ' OR (`warning` <> "")';
  1665. $SQLquery .= ' ORDER BY `filename` ASC';
  1666. $result = mysqli_query_safe($con, $SQLquery);
  1667. if (!empty($_REQUEST['m3u'])) {
  1668. header('Content-type: audio/x-mpegurl');
  1669. echo '#EXTM3U'."\n";
  1670. while ($row = mysqli_fetch_array($result)) {
  1671. echo WindowsShareSlashTranslate($row['filename'])."\n";
  1672. }
  1673. exit;
  1674. } else {
  1675. echo number_format(mysqli_num_rows($result)).' files with errors or warnings:<br>';
  1676. echo '(<a href="'.htmlentities($_SERVER['PHP_SELF'].'?errorswarnings=1&m3u=.m3u').'">.m3u version</a>)<br>';
  1677. echo '<table border="1" cellspacing="0" cellpadding="4">';
  1678. echo '<tr><th>Filename</th><th>Error</th><th>Warning</th></tr>';
  1679. while ($row = mysqli_fetch_array($result)) {
  1680. echo '<tr>';
  1681. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td>';
  1682. echo '<td>'.(!empty($row['error']) ? '<li>'.str_replace("\t", '<li>', htmlentities($row['error'])).'</li>' : '&nbsp;').'</td>';
  1683. echo '<td>'.(!empty($row['warning']) ? '<li>'.str_replace("\t", '<li>', htmlentities($row['warning'])).'</li>' : '&nbsp;').'</td>';
  1684. echo '</tr>';
  1685. }
  1686. }
  1687. echo '</table><hr>';
  1688. } elseif (!empty($_REQUEST['fixid3v1padding'])) {
  1689. getid3_lib::IncludeDependency(GETID3_INCLUDEPATH.'write.id3v1.php', __FILE__, true);
  1690. $id3v1_writer = new getid3_write_id3v1;
  1691. $SQLquery = 'SELECT `filename`, `error`, `warning`';
  1692. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1693. $SQLquery .= ' WHERE (`fileformat` = "mp3")';
  1694. $SQLquery .= ' AND (`warning` <> "")';
  1695. $SQLquery .= ' ORDER BY `filename` ASC';
  1696. $result = mysqli_query_safe($con, $SQLquery);
  1697. $totaltofix = mysqli_num_rows($result);
  1698. $rowcounter = 0;
  1699. while ($row = mysqli_fetch_array($result)) {
  1700. set_time_limit(30);
  1701. if (strpos($row['warning'], 'Some ID3v1 fields do not use NULL characters for padding') !== false) {
  1702. set_time_limit(30);
  1703. $id3v1_writer->filename = $row['filename'];
  1704. echo ($id3v1_writer->FixID3v1Padding() ? '<span style="color: #009900;">fixed - ' : '<span style="color: #FF0000;">error - ');
  1705. } else {
  1706. echo '<span style="color: #0000FF;">No error? - ';
  1707. }
  1708. echo '['.++$rowcounter.' / '.$totaltofix.'] ';
  1709. echo htmlentities($row['filename']).'</span><br>';
  1710. flush();
  1711. }
  1712. } elseif (!empty($_REQUEST['vbrmethod'])) {
  1713. if ($_REQUEST['vbrmethod'] == '1') {
  1714. $SQLquery = 'SELECT COUNT(*) AS `num`, `vbr_method`';
  1715. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1716. $SQLquery .= ' GROUP BY `vbr_method`';
  1717. $SQLquery .= ' ORDER BY `vbr_method`';
  1718. $result = mysqli_query_safe($con, $SQLquery);
  1719. echo 'VBR methods:<table border="1" cellspacing="0" cellpadding="4">';
  1720. echo '<tr><th>Count</th><th>VBR Method</th></tr>';
  1721. while ($row = mysqli_fetch_array($result)) {
  1722. echo '<tr>';
  1723. echo '<TD ALIGN="RIGHT">'.htmlentities(number_format($row['num'])).'</td>';
  1724. if ($row['vbr_method']) {
  1725. echo '<td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?vbrmethod='.$row['vbr_method'], ENT_QUOTES).'">'.htmlentities($row['vbr_method']).'</a></td>';
  1726. } else {
  1727. echo '<td><i>CBR</i></td>';
  1728. }
  1729. echo '</tr>';
  1730. }
  1731. echo '</table>';
  1732. } else {
  1733. $SQLquery = 'SELECT `filename`';
  1734. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1735. $SQLquery .= ' WHERE (`vbr_method` = "'.mysqli_real_escape_string($con, $_REQUEST['vbrmethod']).'")';
  1736. $result = mysqli_query_safe($con, $SQLquery);
  1737. echo number_format(mysqli_num_rows($result)).' files with VBR_method of "'.$_REQUEST['vbrmethod'].'":<table border="1" cellspacing="0" cellpadding="3">';
  1738. while ($row = mysqli_fetch_array($result)) {
  1739. echo '<tr><td><a href="'.htmlentities($_SERVER['PHP_SELF'].'?m3ufilename='.urlencode($row['filename'])).'">m3u</a></td>';
  1740. echo '<td><a href="'.htmlentities('demo.browse.php?filename='.rawurlencode($row['filename']), ENT_QUOTES).'">'.htmlentities($row['filename']).'</a></td></tr>';
  1741. }
  1742. echo '</table>';
  1743. }
  1744. echo '<hr>';
  1745. } elseif (!empty($_REQUEST['correctcase'])) {
  1746. $SQLquery = 'SELECT `filename`, `fileformat`';
  1747. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1748. $SQLquery .= ' WHERE (`fileformat` <> "")';
  1749. $SQLquery .= ' ORDER BY `filename` ASC';
  1750. $result = mysqli_query_safe($con, $SQLquery);
  1751. 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>';
  1752. echo '<PRE>';
  1753. $lastdir = '';
  1754. while ($row = mysqli_fetch_array($result)) {
  1755. set_time_limit(30);
  1756. $CleanedFilename = CleanUpFileName($row['filename']);
  1757. if ($row['filename'] != $CleanedFilename) {
  1758. if (strtolower($lastdir) != strtolower(str_replace('/', '\\', dirname($row['filename'])))) {
  1759. $lastdir = str_replace('/', '\\', dirname($row['filename']));
  1760. echo 'cd "'.$lastdir.'"'."\n";
  1761. }
  1762. echo 'ren "'.basename($row['filename']).'" "'.basename(CleanUpFileName($row['filename'])).'"'."\n";
  1763. }
  1764. }
  1765. echo '</PRE>';
  1766. echo '<hr>';
  1767. }
  1768. function CleanUpFileName($filename) {
  1769. $DirectoryName = dirname($filename);
  1770. $FileExtension = fileextension(basename($filename));
  1771. $BaseFilename = basename($filename, '.'.$FileExtension);
  1772. $BaseFilename = strtolower($BaseFilename);
  1773. $BaseFilename = str_replace('_', ' ', $BaseFilename);
  1774. //$BaseFilename = str_replace('-', ' - ', $BaseFilename);
  1775. $BaseFilename = str_replace('(', ' (', $BaseFilename);
  1776. $BaseFilename = str_replace('( ', '(', $BaseFilename);
  1777. $BaseFilename = str_replace(')', ') ', $BaseFilename);
  1778. $BaseFilename = str_replace(' )', ')', $BaseFilename);
  1779. $BaseFilename = str_replace(' \'\'', ' “', $BaseFilename);
  1780. $BaseFilename = str_replace('\'\' ', '” ', $BaseFilename);
  1781. $BaseFilename = str_replace(' vs ', ' vs. ', $BaseFilename);
  1782. while (strstr($BaseFilename, ' ') !== false) {
  1783. $BaseFilename = str_replace(' ', ' ', $BaseFilename);
  1784. }
  1785. $BaseFilename = trim($BaseFilename);
  1786. return $DirectoryName.'/'.BetterUCwords($BaseFilename).'.'.strtolower($FileExtension);
  1787. }
  1788. function BetterUCwords($string) {
  1789. $stringlength = strlen($string);
  1790. $string[0] = strtoupper($string[0]);
  1791. for ($i = 1; $i < $stringlength; $i++) {
  1792. if (($string[$i - 1] == '\'') && ($i > 1) && (($string[$i - 2] == 'O') || ($string[$i - 2] == ' '))) {
  1793. // O'Clock, 'Em
  1794. $string[$i] = strtoupper($string[$i]);
  1795. } elseif (preg_match('#^[\'A-Za-z0-9À-ÿ]$#', $string[$i - 1])) {
  1796. $string[$i] = strtolower($string[$i]);
  1797. } else {
  1798. $string[$i] = strtoupper($string[$i]);
  1799. }
  1800. }
  1801. static $LowerCaseWords = array('vs.', 'feat.');
  1802. static $UpperCaseWords = array('DJ', 'USA', 'II', 'MC', 'CD', 'TV', '\'N\'');
  1803. $OutputListOfWords = array();
  1804. $ListOfWords = explode(' ', $string);
  1805. foreach ($ListOfWords as $ThisWord) {
  1806. if (in_array(strtolower(str_replace('(', '', $ThisWord)), $LowerCaseWords)) {
  1807. $ThisWord = strtolower($ThisWord);
  1808. } elseif (in_array(strtoupper(str_replace('(', '', $ThisWord)), $UpperCaseWords)) {
  1809. $ThisWord = strtoupper($ThisWord);
  1810. } elseif ((substr($ThisWord, 0, 2) == 'Mc') && (strlen($ThisWord) > 2)) {
  1811. $ThisWord[2] = strtoupper($ThisWord[2]);
  1812. } elseif ((substr($ThisWord, 0, 3) == 'Mac') && (strlen($ThisWord) > 3)) {
  1813. $ThisWord[3] = strtoupper($ThisWord[3]);
  1814. }
  1815. $OutputListOfWords[] = $ThisWord;
  1816. }
  1817. $UCstring = implode(' ', $OutputListOfWords);
  1818. $UCstring = str_replace(' From “', ' from “', $UCstring);
  1819. $UCstring = str_replace(' \'n\' ', ' \'N\' ', $UCstring);
  1820. return $UCstring;
  1821. }
  1822. echo '<hr><form action="'.htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES).'" method="get">';
  1823. echo '<b>Warning:</b> Scanning a new directory will erase all previous entries in the database!<br>';
  1824. echo 'Directory: <input type="text" name="scan" size="50" value="'.htmlentities(!empty($_REQUEST['scan']) ? $_REQUEST['scan'] : '', ENT_QUOTES).'"> ';
  1825. 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?\');">';
  1826. echo '</form>';
  1827. echo '<hr><form action="'.htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES).'" method="get">';
  1828. echo 'Re-scanning a new directory will only add new, previously unscanned files into the list (and not erase the database).<br>';
  1829. echo 'Directory: <input type="text" name="newscan" size="50" value="'.htmlentities(!empty($_REQUEST['newscan']) ? $_REQUEST['newscan'] : '', ENT_QUOTES).'"> ';
  1830. echo '<input type="submit" value="Go">';
  1831. echo '</form><hr>';
  1832. echo '<ul>';
  1833. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?deadfilescheck=1').'">Remove deleted or changed files from database</a></li>';
  1834. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?md5datadupes=1').'">List files with identical MD5_DATA values</a></li>';
  1835. echo '<li><a href="'.htmlentities($_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>';
  1836. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?fileextensions=1').'">File with incorrect file extension</a></li>';
  1837. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?formatdistribution=1').'">File Format Distribution</a></li>';
  1838. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?audiobitrates=1').'">Audio Bitrate Distribution</a></li>';
  1839. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?vbrmethod=1').'">VBR_Method Distribution</a></li>';
  1840. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?tagtypes=1').'">Tag Type Distribution</a></li>';
  1841. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?genredistribution='.urlencode('%')).'">Genre Distribution</a></li>';
  1842. //echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?missingtrackvolume=1').'">Scan for missing track volume information (update database from pre-v1.7.0b5)</a></li>';
  1843. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?encoderoptionsdistribution=1').'">Encoder Options Distribution</a></li>';
  1844. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?encodedbydistribution='.urlencode('%')).'">Encoded By (ID3v2) Distribution</a></li>';
  1845. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?trackinalbum=1').'">Track number in Album field</a></li>';
  1846. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?tracknoalbum=1').'">Track number, but no Album</a></li>';
  1847. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?titlefeat=1').'">"feat." in Title field</a></li>';
  1848. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?emptygenres=1').'">Blank genres</a></li>';
  1849. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?trackzero=1').'">Track "zero"</a></li>';
  1850. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?nonemptycomments=1').'">non-empty comments</a></li>';
  1851. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?unsynchronizedtags=2A1').'">Tags that are not synchronized</a> (<a href="'.$_SERVER['PHP_SELF'].'?unsynchronizedtags=2A1&autofix=1">autofix</a>)</li>';
  1852. echo '<li><a href="'.htmlentities($_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>';
  1853. //echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?filenamepattern='.urlencode('A - T')).'">Filenames that don\'t match pattern</a></li>';
  1854. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?correctcase=1').'">Correct filename case (Win/DOS)</a></li>';
  1855. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?fixid3v1padding=1').'">Fix ID3v1 invalid padding</a></li>';
  1856. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?errorswarnings=1').'">Files with Errors and/or Warnings</a></li>';
  1857. echo '<li><a href="'.htmlentities($_SERVER['PHP_SELF'].'?rescanerrors=1').'">Re-scan only files with Errors and/or Warnings</a></li>';
  1858. echo '</ul>';
  1859. $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`';
  1860. $SQLquery .= ' FROM `'.mysqli_real_escape_string($con, GETID3_DB_TABLE).'`';
  1861. $result = mysqli_query_safe($con, $SQLquery);
  1862. if ($row = mysqli_fetch_array($result)) {
  1863. echo '<hr size="1">';
  1864. echo '<div style="float: right;">';
  1865. echo 'Spent '.number_format(mysqli_query_safe($con, null), 3).' seconds querying the database<br>';
  1866. echo '</div>';
  1867. echo '<b>Currently in the database:</b><TABLE>';
  1868. echo '<tr><th align="left">Total Files</th><td>'.number_format($row['TotalFiles']).'</td></tr>';
  1869. echo '<tr><th align="left">Total Filesize</th><td>'.number_format($row['TotalFilesize'] / 1048576).' MB</td></tr>';
  1870. echo '<tr><th align="left">Total Playtime</th><td>'.number_format($row['TotalPlaytime'] / 3600, 1).' hours</td></tr>';
  1871. echo '<tr><th align="left">Average Filesize</th><td>'.number_format($row['AvgFilesize'] / 1048576, 1).' MB</td></tr>';
  1872. echo '<tr><th align="left">Average Playtime</th><td>'.getid3_lib::PlaytimeString($row['AvgPlaytime']).'</td></tr>';
  1873. echo '<tr><th align="left">Average Bitrate</th><td>'.BitrateText($row['AvgBitrate'] / 1000, 1).'</td></tr>';
  1874. echo '</table>';
  1875. echo '<br clear="all">';
  1876. }
  1877. echo '</body></html>';