diff --git a/include/config.inc.php b/include/config.inc.php
index 6a3f44d..bb2d13b 100644
--- a/include/config.inc.php
+++ b/include/config.inc.php
@@ -385,6 +385,16 @@
+// +------------------------------------------------------------------------+
+// | Limit of displayed tracks in current playlist |
+// +------------------------------------------------------------------------+
+// | theoretically ten thousands of tracks could be in current playlist |
+// | which causes every browser to freeze |
+// +------------------------------------------------------------------------+
+$cfg['current_playlist_max_displayed_items'] = 500;
+
+
+
// +------------------------------------------------------------------------+
// | Binary directory |
@@ -887,6 +897,7 @@
// | $cfg['php_info'] - displays 'PHP information' in 'Configuration' |
// +------------------------------------------------------------------------+
$cfg['debug'] = false;
+$cfg['debug_memory'] = false;
$cfg['php_info'] = true;
diff --git a/include/initialize.inc.php b/include/initialize.inc.php
index a576ce8..b027925 100644
--- a/include/initialize.inc.php
+++ b/include/initialize.inc.php
@@ -1,10 +1,10 @@
\ No newline at end of file
diff --git a/include/tagProcessor.inc.php b/include/tagProcessor.inc.php
new file mode 100644
index 0000000..e5474a6
--- /dev/null
+++ b/include/tagProcessor.inc.php
@@ -0,0 +1,273 @@
+. |
+// +------------------------------------------------------------------------+
+
+
+// +------------------------------------------------------------------------+
+// | tag properties |
+// +------------------------------------------------------------------------+
+function parseTrackArtist($data) {
+ if (isset($data['comments']['artist'][0])) {
+ return $data['comments']['artist'][0];
+ }
+ return 'Unknown TrackArtist';
+}
+
+function parseTrackTitle($data) {
+ if(isset($data['comments']['title'][0])) {
+ return $data['comments']['title'][0];
+ }
+ return 'Unknown Title';
+}
+
+function parseGenre($data) {
+ if (isset($data['comments']['genre'][0])) {
+ return $data['comments']['genre'][0];
+ }
+ return 'Unknown Genre';
+}
+
+function parseTrackNumber($data) {
+ if (isset($data['comments']['track'][0])) {
+ return postProcessTrackNumber($data['comments']['track'][0]);
+ }
+ if (isset($data['comments']['tracknumber'][0])) {
+ return postProcessTrackNumber($data['comments']['tracknumber'][0]);
+ }
+ if (isset($data['comments']['track_number'][0])) {
+ return postProcessTrackNumber($data['comments']['track_number'][0]);
+ }
+ // TODO: handling NULL-values when building the query. for now return a string
+ return 'NULL';
+}
+
+function postProcessTrackNumber($numberString) {
+ //support for track_number in form: 01/11
+ $numbers = explode("/", $numberString);
+ return $numbers[0];
+}
+
+function parseYear($data) {
+ if (isset($data['comments']['year'][0])) {
+ return postProcessYear($data['comments']['year'][0]);
+ }
+ if (isset($data['comments']['date'][0])) {
+ return postProcessYear($data['comments']['date'][0]);
+ }
+ if (isset($data['comments']['creation_date'][0])) {
+ return postProcessYear($data['comments']['creation_date'][0]);
+ }
+ // TODO: handling NULL-values when building the query. for now return a string
+ return 'NULL';
+}
+
+function postProcessYear($yearString) {
+ if (preg_match('#[1][9][0-9]{2}|[2][0-9]{3}#', $yearString, $match)) {
+ $yearString = $match[0];
+ }
+ return intval($yearString);
+}
+
+function parseComment($data) {
+ if(isset($data['comments']['comment']) === FALSE) {
+ return '';
+ }
+ if(is_array($data['comments']['comment']) === FALSE) {
+ return '';
+ }
+ $commentsArray = array_values($data['comments']['comment']);
+ if(isset($commentsArray[0])) {
+ return $commentsArray[0];
+ }
+ return '';
+}
+
+// TODO: this function is currently not used but removed from old fileInfo() code-mess
+// consider to make use of it within fileStructure() or whereelse needed
+function parseAlbumArtist($data) {
+ if (isset($data['comments']['albumartist'][0])) {
+ return $data['comments']['albumartist'][0];
+ }
+ if (isset($data['comments']['band'][0])) {
+ return $data['comments']['band'][0];
+ }
+ return 'Unknown AlbumArtist';
+}
+
+
+
+
+function parseMimeType($data) {
+ if(isset($data['mime_type'])) {
+ return $data['mime_type'];
+ }
+ return 'application/octet-stream';
+}
+
+function parseError($data) {
+ if (isset($data['error'])) {
+ return implode('
', $data['error']);
+ }
+ return '';
+}
+
+// +------------------------------------------------------------------------+
+// | audio tech properties |
+// +------------------------------------------------------------------------+
+function parseMiliseconds($data) {
+ if(isset($data['playtime_seconds'])) {
+ return round($data['playtime_seconds'] * 1000);
+ }
+ return 0;
+}
+
+function parseAudioBitRate($data) {
+ if(isset($data['audio']['bitrate'])) {
+ return round($data['audio']['bitrate']); // integer in database
+ }
+ return 0;
+}
+
+function parseAudioBitRateMode($data) {
+ if(isset($data['audio']['bitrate_mode'])) {
+ return $data['audio']['bitrate_mode'];
+ }
+ return '';
+}
+
+function parseAudioBitsPerSample($data) {
+ if(isset($data['audio']['bits_per_sample'])) {
+ return $data['audio']['bits_per_sample'];
+ }
+ return 16;
+}
+
+function parseAudioSampleRate($data) {
+ if(isset($data['audio']['sample_rate'])) {
+ return $data['audio']['sample_rate'];
+ }
+ return 44100;
+}
+
+function parseAudioChannels($data) {
+ if(isset($data['audio']['channels'])) {
+ return $data['audio']['channels'];
+ }
+ return 2;
+}
+
+function parseAudioLossless($data) {
+ if(empty($data['audio']['lossless']) == false) {
+ return 1;
+ }
+ return 0;
+}
+
+function parseAudioCompressionRatio($data) {
+ if(isset($data['audio']['compression_ratio'])) {
+ return $data['audio']['compression_ratio'];
+ }
+ return 0;
+}
+
+function parseAudioDataformat($data) {
+ if(isset($data['audio']['dataformat'])) {
+ return $data['audio']['dataformat'];
+ }
+ return '';
+}
+
+function parseAudioEncoder($data) {
+ if(isset($data['audio']['encoder'])) {
+ return $data['audio']['encoder'];
+ }
+ return 'Unknown encoder';
+}
+
+function parseAudioProfile($data) {
+ if(parseAudioLossless($data) === 1) {
+ return (parseAudioCompressionRatio($data) == 1)
+ ? 'Lossless'
+ : 'Lossless compression';
+ }
+ if(isset($data['aac']['header']['profile_text'])) {
+ return $data['aac']['header']['profile_text'];
+ }
+ if(isset($data['mpc']['header']['profile'])) {
+ return $data['mpc']['header']['profile'];
+ }
+ return parseAudioBitRateMode($data) . ' ' . round(parseAudioBitRate($data) / 1000, 1) . ' kbps';
+}
+
+function parseAudioDynamicRange($data) {
+ if(isset($data['comments']['dynamic range'][0])) {
+ return intval($data['comments']['dynamic range'][0]);
+ }
+ if(isset($data['tags']['id3v2']['text']['DYNAMIC RANGE'])) {
+ return intval($data['tags']['id3v2']['text']['DYNAMIC RANGE']);
+ }
+ // TODO: handling NULL-values when building the query. for now return a string
+ return 'NULL';
+}
+
+
+// +------------------------------------------------------------------------+
+// | video tech properties |
+// +------------------------------------------------------------------------+
+function parseVideoDataformat($data) {
+ if(isset($data['video']['dataformat'])) {
+ return $data['video']['dataformat'];
+ }
+ return '';
+}
+
+function parseVideoCodec($data) {
+ if(isset($data['video']['codec'])) {
+ return $data['video']['codec'];
+ }
+ return 'Unknown codec';
+}
+
+function parseVideoResolutionX($data) {
+ if(isset($data['video']['resolution_x'])) {
+ return intval($data['video']['resolution_x']);
+ }
+ return 0;
+}
+
+function parseVideoResolutionY($data) {
+ if(isset($data['video']['resolution_y'])) {
+ return intval($data['video']['resolution_y']);
+ }
+ return 0;
+}
+
+function parseVideoFrameRate($data) {
+ if(isset($data['video']['frame_rate'])) {
+ return intval($data['video']['frame_rate']);
+ }
+ return 0;
+}
+
diff --git a/playlist.php b/playlist.php
index b6a8f7e..c4d3bbe 100644
--- a/playlist.php
+++ b/playlist.php
@@ -1,10 +1,10 @@
-
+ $cfg['current_playlist_max_displayed_items']) {
+ $min_index = $listpos;
+ $max_index = $listpos + $cfg['current_playlist_max_displayed_items'];
+ if(($listlength - $cfg['current_playlist_max_displayed_items']) < $listpos ) {
+ $min_index = $listlength - $cfg['current_playlist_max_displayed_items'];
+ $max_index = $cfg['current_playlist_max_displayed_items'];
+ }
+ $string_listlength = '(showing '.($min_index+1) . '-' . ($max_index+1) . ' of ' . $listlength . ' Tracks)';
+}
+?>
@@ -213,9 +232,34 @@ $playtime = array(); $track_id = array(); $playlistTT = 0; -for ($i=0; $i < $listlength; $i++) - { - $query = mysqli_query($db,'SELECT track.title, track.artist, track.track_artist, track.featuring, track.miliseconds, track.track_id, track.genre, album.genre_id, track.audio_dataformat, track.audio_bits_per_sample, track.audio_sample_rate, track.album_id, track.number, track.track_id, track.year as trackYear FROM track, album WHERE track.album_id=album.album_id AND track.relative_file = "' . mysqli_real_escape_string($db,$file[$i]) . '"'); +for ($i=0; $i < $listlength; $i++) { + if($i < $min_index || $i > $max_index) { + // TODO: display 'show more'-links in frontend to ajax-load a bunch of not rendered playlistitems at begin and end of current playlist + // or a pagination for current playlist? + // TODO: reload playlist when pressing "play-next-button" to assure the current track will be displayed + continue; + } + $query = $db->query(' + SELECT + track.title, + track.artist, + track.track_artist, + track.featuring, + track.miliseconds, + track.track_id, + track.genre, + album.genre_id, + track.audio_dataformat, + track.audio_bits_per_sample, + track.audio_sample_rate, + track.album_id, + track.number, + track.track_id, + track.year as trackYear + FROM track, album + WHERE track.album_id=album.album_id + AND track.relative_file = "' . $db->real_escape_string($file[$i]) . '";' + ); $table_track = mysqli_fetch_assoc($query); $playtime[] = (int) $table_track['miliseconds']; $playlistTT = $playlistTT + (int) $table_track['miliseconds']; diff --git a/update.php b/update.php index c191b18..017caf5 100644 --- a/update.php +++ b/update.php @@ -40,11 +40,6 @@ ignore_user_abort(true); //exit(); -$logFile = ''; -if ($cfg['debug']) { - $logFile = NJB_HOME_DIR . 'tmp/update_log.txt'; - ini_set('log_errors', 'On'); -} $cfg['menu'] = 'config'; @@ -52,7 +47,7 @@ $flag = (int) getpost('flag'); -if ($logFile != '') error_log("Update started " . $logFile . "\n", 3, $logFile); +cliLog("Update started"); if (PHP_SAPI == 'cli') cliUpdate(); elseif ($action == 'update') update(); @@ -72,7 +67,7 @@ // +------------------------------------------------------------------------+ function update() { - global $cfg, $db, $lastGenre_id, $getID3, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter, $last_update, $file, $logFile; + global $cfg, $db, $lastGenre_id, $getID3, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter, $last_update, $file; authenticate('access_admin', false, true); @@ -82,7 +77,7 @@ function update() { $cfg['cli_update'] = false; $startTime = new DateTime(); - if ($logFile != '') error_log("Update start time: " . date("Ymd H:i:s") . "\n", 3, $logFile); + cliLog("Update start time: " . date("Ymd H:i:s")); $path = $cfg['media_dir']; $curFilesCounter = 0; @@ -261,8 +256,8 @@ function show_update_progress() { if ($cfg['image_size'] != NJB_IMAGE_SIZE || $cfg['image_quality'] != NJB_IMAGE_QUALITY) { mysqli_query($db,'TRUNCATE TABLE bitmap'); - mysqli_query($db,'UPDATE server SET value = "' . mysqli_real_escape_string($db,NJB_IMAGE_SIZE) . '" WHERE name = "image_size" LIMIT 1'); - mysqli_query($db,'UPDATE server SET value = "' . mysqli_real_escape_string($db,NJB_IMAGE_QUALITY) . '" WHERE name = "image_quality" LIMIT 1'); + mysqli_query($db,'UPDATE server SET value = "' . $db->real_escape_string(NJB_IMAGE_SIZE) . '" WHERE name = "image_size" LIMIT 1'); + mysqli_query($db,'UPDATE server SET value = "' . $db->real_escape_string(NJB_IMAGE_QUALITY) . '" WHERE name = "image_quality" LIMIT 1'); } mysqli_query($db,'UPDATE album SET updated = 0'); @@ -309,7 +304,7 @@ function show_update_progress() { //mysqli_query($db,'DELETE FROM genre WHERE NOT updated'); - mysqli_query($db,'UPDATE server SET value = "' . mysqli_real_escape_string($db,$cfg['new_escape_char_hash']) . '" WHERE name = "escape_char_hash" LIMIT 1'); + mysqli_query($db,'UPDATE server SET value = "' . $db->real_escape_string($cfg['new_escape_char_hash']) . '" WHERE name = "escape_char_hash" LIMIT 1'); $no_image = mysqli_num_rows(mysqli_query($db,'SELECT album_id FROM bitmap WHERE flag = 0')); $image_error = mysqli_num_rows(mysqli_query($db,'SELECT album_id FROM bitmap WHERE flag = 10')); @@ -345,7 +340,7 @@ function show_update_progress() { $cfg['timer'] = 0; // force update - fileInfo(); + fileInfoLoop(); updateGenre(); @@ -389,7 +384,7 @@ function show_update_progress() { last_update = '" . date('Y-m-d, H:i:s') . "' "); - if ($logFile != '') error_log("Update stop time: " . date("Ymd H:i:s") . "\n", 3, $logFile); + cliLog("Update stop time: " . date("Ymd H:i:s")); backgroundQueries(); } else { @@ -414,65 +409,83 @@ function show_update_progress() { // | Recursive scan | // +------------------------------------------------------------------------+ function recursiveScan($dir) { - global $cfg, $db, $logFile; - - $album_id = ''; - $file = array(); - $filename = array(); - - if ($logFile != '') error_log("recursiveScan: " . $dir . "\n", 3, $logFile); - if ($cfg['ignore_media_dir_access_error']) { - $entries = @scandir($dir); - } - else { - $entries = @scandir($dir) or message(__FILE__, __LINE__, 'error', '[b]Failed to open directory:[/b][br]' . $dir . '[list][*]Check media_dir value in the config.inc.php file[*]Check file permission[/list]'); - } - - foreach ($entries as $entry) { - if ($entry[0] != '.' && in_array($entry, $cfg['directory_blacklist']) === FALSE) { - if (is_dir($dir . $entry . '/')) - recursiveScan($dir . $entry . '/'); - else { - $extension = substr(strrchr($entry, '.'), 1); - $extension = strtolower($extension); - if (in_array($extension, $cfg['media_extension'])) { - $entry = iconv(NJB_DEFAULT_FILESYSTEM_CHARSET, 'UTF-8', $entry); - $dir_d = iconv(NJB_DEFAULT_FILESYSTEM_CHARSET, 'UTF-8', $dir); - $file[] = $dir_d . $entry; - $filename[] = substr($entry, 0, -strlen($extension) - 1); - } - elseif ($extension == 'id') - $album_id = substr($entry, 0, -3); - } - } - } - - - if (count($file) > 0) { - mysqli_query($db,"UPDATE album_id SET - updated = '1' - WHERE - path = '" . mysqli_real_escape_string($db,$dir) . "' - LIMIT 1"); - - if (mysqli_affected_rows($db) == 0) { - if ($album_id == '') $album_id = base_convert(uniqid(), 16, 36); - $album_add_time = time(); - mysqli_query($db,"INSERT INTO album_id (album_id, path, album_add_time, updated) VALUES - ('" . mysqli_real_escape_string($db,$album_id) . "','" . mysqli_real_escape_string($db,$dir) . "','" . $album_add_time . "','1')"); - } - else { - $ids = mysqli_query($db,"SELECT album_id, album_add_time FROM album_id WHERE - path = '" . mysqli_real_escape_string($db,$dir) . "' LIMIT 1"); - $row = mysqli_fetch_assoc($ids); - $album_id = $row["album_id"]; - $album_add_time = $row["album_add_time"]; - } - - if ($logFile != '') error_log( "Going into fileStructure for album_id: " . $album_id . "\n", 3, $logFile); - - fileStructure($dir, $file, $filename, $album_id, $album_add_time); + global $cfg, $db; + + $album_id = ''; + $file = array(); + $filename = array(); + + cliLog("recursiveScan: " . $dir); + // TODO: consider to remove. @see https://github.com/ArturSierzant/OMPD/issues/15 + if ($cfg['ignore_media_dir_access_error']) { + $entries = @scandir($dir); + } + else { + $entries = @scandir($dir) or message(__FILE__, __LINE__, 'error', '[b]Failed to open directory:[/b][br]' . $dir . '[list][*]Check media_dir value in the config.inc.php file[*]Check file permission[/list]'); + } + + foreach ($entries as $entry) { + if ($entry[0] === '.' || in_array($entry, $cfg['directory_blacklist']) === TRUE) { + continue; + } + if (is_dir($dir . $entry . '/')) { + recursiveScan($dir . $entry . '/'); + continue; + } + + $extension = strtolower(substr(strrchr($entry, '.'), 1)); + if (in_array($extension, $cfg['media_extension'])) { + $entry = iconv(NJB_DEFAULT_FILESYSTEM_CHARSET, 'UTF-8', $entry); + $dir_d = iconv(NJB_DEFAULT_FILESYSTEM_CHARSET, 'UTF-8', $dir); + $file[] = $dir_d . $entry; + $filename[] = substr($entry, 0, -strlen($extension) - 1); + continue; + } + if ($extension == 'id') { + $album_id = substr($entry, 0, -3); + } } + + if (count($file) === 0) { + unset($entries); + unset($entry); + unset($filename); + unset($file); + unset($dir); + return; + } + + $db->query(" + UPDATE album_id + SET updated = '1' + WHERE path = '" . $db->real_escape_string($dir) . "' + LIMIT 1" + ); + if ($db->affected_rows == 0) { + $album_id = ($album_id == '') ? base_convert(uniqid(), 16, 36) : $album_id; + $album_add_time = time(); + $db->query(" + INSERT INTO album_id + (album_id, path, album_add_time, updated) + VALUES + ('" . $album_id . "', + '" . $db->real_escape_string($dir) . "', + '" . $album_add_time . "','1')" + ); + } else { + $result = $db->query(" + SELECT album_id, album_add_time + FROM album_id + WHERE path = '" . $db->real_escape_string($dir) . "' + LIMIT 1" + ); + $row = $result->fetch_assoc(); + $album_id = $row["album_id"]; + $album_add_time = $row["album_add_time"]; + $result->free_result(); + } + cliLog("Going into fileStructure for album_id: " . $album_id); + fileStructure($dir, $file, $filename, $album_id, $album_add_time); } @@ -519,7 +532,7 @@ function countDirectories($base_dir) { // | File structure | // +------------------------------------------------------------------------+ Function fileStructure($dir, $file, $filename, $album_id, $album_add_time) { - global $cfg, $db, $lastGenre_id, $getID3, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter, $prevDirsCounter, $last_update, $logFile, $image, $flag, $image_front; + global $cfg, $db, $lastGenre_id, $getID3, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter, $prevDirsCounter, $last_update, $flag, $image_front; // Also needed for track update! @@ -533,7 +546,9 @@ function countDirectories($base_dir) { $aGenre = 'Unknown Genre'; $aGenre_id = 0; $album_dr = NULL; + $isUpdateRequired = false; + $new_array = array(); if ($cfg['name_source'] != 'tags') { if (preg_match('#^(0{0,1}1)(0{1,3}1)+\.\s+.+#', $filename[0], $match) && preg_match('#^(\d{' . strlen($match[1] . $match[2]) . '})+\.\s+.+#', $filename[count($filename)-1])) { @@ -586,7 +601,7 @@ function countDirectories($base_dir) { $isUpdateRequired = true; } else { - $q = mysqli_query($db,'SELECT relative_file, filemtime FROM track WHERE album_id = BINARY "' . mysqli_real_escape_string($db,$album_id) . '"'); + $q = mysqli_query($db,'SELECT relative_file, filemtime FROM track WHERE album_id = BINARY "' . $db->real_escape_string($album_id) . '"'); while($row = mysqli_fetch_assoc($q)){ $row['relative_file'] = $cfg['media_dir'] . $row['relative_file']; //$new_array[$row['relative_file']] = $row['filemtime']; @@ -613,7 +628,7 @@ function countDirectories($base_dir) { } if ($isUpdateRequired) { - if ($logFile != '') error_log("fileStructure file[0]: " . $file[0] . "\n", 3, $logFile); + cliLog("fileStructure file[0]: " . $file[0]); $file_d = iconv('UTF-8', NJB_DEFAULT_FILESYSTEM_CHARSET, $file[0]); @@ -677,14 +692,14 @@ function countDirectories($base_dir) { $album = basename($dir); } - /* $result = mysqli_query($db,'SELECT genre_id FROM genre WHERE genre="' . mysqli_real_escape_string($db,$aGenre) . '"'); + /* $result = mysqli_query($db,'SELECT genre_id FROM genre WHERE genre="' . $db->real_escape_string($aGenre) . '"'); $row=mysqli_fetch_assoc($result); $aGenre_id=$row["genre_id"]; if (mysqli_num_rows($result)==0) { mysqli_query($db,'INSERT INTO genre (genre_id, genre, updated) - VALUES ("' . mysqli_real_escape_string($db,$lastGenre_id) . '", - "' . mysqli_real_escape_string($db,$aGenre) . '", + VALUES ("' . $db->real_escape_string($lastGenre_id) . '", + "' . $db->real_escape_string($aGenre) . '", 1)'); $aGenre_id = $lastGenre_id; ++$lastGenre_id; @@ -692,7 +707,7 @@ function countDirectories($base_dir) { } else { $result = mysqli_query($db,"update genre set updated = 1 - WHERE genre = '". mysqli_real_escape_string($db,$aGenre) ."';"); + WHERE genre = '". $db->real_escape_string($aGenre) ."';"); } */ @@ -702,9 +717,9 @@ function countDirectories($base_dir) { // Update/Insert album information on the end of this function to be able to include image_id // - - if ($cfg['cli_update'] && $cfg['cli_silent_update'] == false) - echo $artist_alphabetic . ' - ' . $album . "\n"; + // TODO: cli_update is not possible anymore, right? + // if ($cfg['cli_update'] && $cfg['cli_silent_update'] == false) + // echo $artist_alphabetic . ' - ' . $album . "\n"; // Track update @@ -712,14 +727,14 @@ function countDirectories($base_dir) { $number = NULL; for ($i=0; $i < count($filename); $i++) { - if ($logFile != '') error_log("fileStructure TrackUpdate: " . $file[$i] . "\n", 3, $logFile); + cliLog("fileStructure TrackUpdate: " . $file[$i]); $relative_file = substr($file[$i], strlen($cfg['media_dir'])); mysqli_query($db,'UPDATE track SET updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" - AND relative_file = BINARY "' . mysqli_real_escape_string($db,$relative_file) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" + AND relative_file = BINARY "' . $db->real_escape_string($relative_file) . '" LIMIT 1'); if ($cfg['force_filename_update'] || mysqli_affected_rows($db) == 0) { @@ -790,39 +805,39 @@ function countDirectories($base_dir) { if (mysqli_affected_rows($db) == 0) mysqli_query($db,'INSERT INTO track (artist, featuring, title, relative_file, disc, number, album_id, updated) - VALUES ("' . mysqli_real_escape_string($db,$track_artist) . '", - "' . mysqli_real_escape_string($db,$featuring) . '", - "' . mysqli_real_escape_string($db,$title) . '", - "' . mysqli_real_escape_string($db,$relative_file) . '", + VALUES ("' . $db->real_escape_string($track_artist) . '", + "' . $db->real_escape_string($featuring) . '", + "' . $db->real_escape_string($title) . '", + "' . $db->real_escape_string($relative_file) . '", ' . (int) $disc . ', ' . ((is_null($number)) ? 'NULL' : (int) $number) . ', - "' . mysqli_real_escape_string($db,$album_id) . '", + "' . $db->real_escape_string($album_id) . '", 1)'); else mysqli_query($db,'UPDATE track SET - artist = "' . mysqli_real_escape_string($db,$track_artist) . '", - featuring = "' . mysqli_real_escape_string($db,$featuring) . '", - title = "' . mysqli_real_escape_string($db,$title) . '", - relative_file = "' . mysqli_real_escape_string($db,$relative_file) . '", + artist = "' . $db->real_escape_string($track_artist) . '", + featuring = "' . $db->real_escape_string($featuring) . '", + title = "' . $db->real_escape_string($title) . '", + relative_file = "' . $db->real_escape_string($relative_file) . '", disc = ' . (int) $disc . ', number = ' . ((is_null($number)) ? 'NULL' : (int) $number) . ', - album_id = "' . mysqli_real_escape_string($db,$album_id) . '", + album_id = "' . $db->real_escape_string($album_id) . '", updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" - AND relative_file = BINARY "' . mysqli_real_escape_string($db,$relative_file) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" + AND relative_file = BINARY "' . $db->real_escape_string($relative_file) . '" LIMIT 1'); } } - + unset($ThisFileInfo); } else { $q = mysqli_query($db,'SELECT relative_file FROM track - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '"'); + WHERE album_id = "' . $db->real_escape_string($album_id) . '"'); $rows = mysqli_num_rows($q); if ($rows == count($filename)) { mysqli_query($db,'UPDATE track SET updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" '); } else { @@ -831,8 +846,8 @@ function countDirectories($base_dir) { mysqli_query($db,'UPDATE track SET updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" - AND relative_file = BINARY "' . mysqli_real_escape_string($db,$relative_file) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" + AND relative_file = BINARY "' . $db->real_escape_string($relative_file) . '" LIMIT 1'); } } @@ -844,11 +859,11 @@ function countDirectories($base_dir) { $flag = 0; // No image $misc_tracks = false; - if ($logFile != '') error_log("fileStructure ImageUpdate: " . $file[0] . "\n", 3, $logFile); + cliLog("fileStructure ImageUpdate: " . $file[0]); $dir_d = iconv('UTF-8', NJB_DEFAULT_FILESYSTEM_CHARSET, $dir); - if ($logFile != '') error_log("fileStructure ImageUpdate d: " . var_export(is_file($dir . $cfg['image_front'] . '.jpg'),true) . "\n", 3, $logFile); + cliLog("fileStructure ImageUpdate d: " . var_export(is_file($dir . $cfg['image_front'] . '.jpg'),true)); if (is_file($dir . $cfg['image_front'] . '.jpg')) { $image = $dir . $cfg['image_front'] . '.jpg'; $flag = 3;} // Stored image elseif (is_file($dir . $cfg['image_front'] . '.png')) { $image = $dir . $cfg['image_front'] . '.png'; $flag = 3; } // Stored image @@ -859,7 +874,7 @@ function countDirectories($base_dir) { } elseif ($cfg['image_read_embedded']) { - if ($logFile != '') error_log("fileStructure ImageUpdateEmbeded: " . $file[0] . "\n", 3, $logFile); + cliLog("fileStructure ImageUpdateEmbeded: " . $file[0]); $file_d = iconv('UTF-8', NJB_DEFAULT_FILESYSTEM_CHARSET, $file[0]); $ThisFileInfo = $getID3->analyze($file_d); getid3_lib::CopyTagsToComments($ThisFileInfo); @@ -876,6 +891,7 @@ function countDirectories($base_dir) { } unset($getID3); + unset($ThisFileInfo); } $relative_dir = substr($dir, strlen($cfg['media_dir'])); @@ -900,16 +916,16 @@ function countDirectories($base_dir) { $filesize = filesize($image); $filemtime = filemtime($image); - $query = mysqli_query($db,'SELECT filesize, filemtime, image_id, flag FROM bitmap WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '"'); + $query = mysqli_query($db,'SELECT filesize, filemtime, image_id, flag FROM bitmap WHERE album_id = "' . $db->real_escape_string($album_id) . '"'); $bitmap = mysqli_fetch_assoc($query); if ($bitmap['filesize'] == $filesize && filemtimeCompare($bitmap['filemtime'], $filemtime)) { - /* image_front = "' . mysqli_real_escape_string($db,$image_front) . '", - image_back = "' . mysqli_real_escape_string($db,$image_back) . '", */ + /* image_front = "' . $db->real_escape_string($image_front) . '", + image_back = "' . $db->real_escape_string($image_back) . '", */ mysqli_query($db,'UPDATE bitmap SET updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" LIMIT 1'); $image_id = $bitmap['image_id']; } @@ -919,74 +935,74 @@ function countDirectories($base_dir) { $image_id = (($flag == 3) ? $album_id : 'no_image'); $image_id .= '_' . base_convert(NJB_IMAGE_SIZE * 100 + NJB_IMAGE_QUALITY, 10, 36) . base_convert($filemtime, 10, 36) . base_convert($filesize, 10, 36); - //if ($logFile != '') error_log("imagesize - image_id - image: " . $imagesize . " - " . $image_id . " - " . $image . " - " . $filesize . " - " . $filemtime . "\n", 3, $logFile); + //cliLog("imagesize - image_id - image: " . $imagesize . " - " . $image_id . " - " . $image . " - " . $filesize . " - " . $filemtime); $image_front = iconv(NJB_DEFAULT_FILESYSTEM_CHARSET, 'UTF-8', $image_front); if ($bitmap['filemtime']) mysqli_query($db,'UPDATE bitmap SET - image = "' . mysqli_real_escape_string($db,resampleImage($image)) . '", + image = "' . $db->real_escape_string(resampleImage($image)) . '", filesize = ' . (int) $filesize . ', filemtime = ' . (int) $filemtime . ', flag = ' . (int) $flag . ', - image_front = "' . mysqli_real_escape_string($db,$image_front) . '", - image_back = "' . mysqli_real_escape_string($db,$image_back) . '", + image_front = "' . $db->real_escape_string($image_front) . '", + image_back = "' . $db->real_escape_string($image_back) . '", image_front_width = ' . ($flag == 3 ? $imagesize[0] : 0) . ', image_front_height = ' . ($flag == 3 ? $imagesize[1] : 0) . ', - image_id = "' . mysqli_real_escape_string($db,$image_id) . '", + image_id = "' . $db->real_escape_string($image_id) . '", updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" LIMIT 1'); else mysqli_query($db,'INSERT INTO bitmap (image, filesize, filemtime, flag, image_front, image_back, image_front_width, image_front_height, image_id, album_id, updated) - VALUES ("' . mysqli_real_escape_string($db,resampleImage($image)) . '", + VALUES ("' . $db->real_escape_string(resampleImage($image)) . '", ' . (int) $filesize . ', ' . (int) $filemtime . ', ' . (int) $flag . ', - "' . mysqli_real_escape_string($db,$image_front) . '", - "' . mysqli_real_escape_string($db,$image_back) . '", + "' . $db->real_escape_string($image_front) . '", + "' . $db->real_escape_string($image_back) . '", ' . ($flag == 3 ? $imagesize[0] : 0) . ', ' . ($flag == 3 ? $imagesize[1] : 0) . ', - "' . mysqli_real_escape_string($db,$image_id) . '", - "' . mysqli_real_escape_string($db,$album_id) . '", + "' . $db->real_escape_string($image_id) . '", + "' . $db->real_escape_string($album_id) . '", 1)'); } if ($isUpdateRequired) { mysqli_query($db,'UPDATE album SET - artist_alphabetic = "' . mysqli_real_escape_string($db,$artist_alphabetic) . '", - artist = "' . mysqli_real_escape_string($db,$artist) . '", - album = "' . mysqli_real_escape_string($db,$album) . '", + artist_alphabetic = "' . $db->real_escape_string($artist_alphabetic) . '", + artist = "' . $db->real_escape_string($artist) . '", + album = "' . $db->real_escape_string($album) . '", year = ' . ((is_null($year)) ? 'NULL' : (int) $year) . ', month = ' . ((is_null($month)) ? 'NULL' : (int) $month) . ', discs = ' . (int) $discs . ', - image_id = "' . mysqli_real_escape_string($db,$image_id) . '", - genre_id = "' . mysqli_real_escape_string($db,$aGenre_id) .'", + image_id = "' . $db->real_escape_string($image_id) . '", + genre_id = "' . $db->real_escape_string($aGenre_id) .'", updated = 1, album_dr = ' . ((is_null($album_dr)) ? 'NULL' : (int) $album_dr) . ' - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" LIMIT 1'); } else { mysqli_query($db,'UPDATE album SET - image_id = "' . mysqli_real_escape_string($db,$image_id) . '", + image_id = "' . $db->real_escape_string($image_id) . '", updated = 1 - WHERE album_id = "' . mysqli_real_escape_string($db,$album_id) . '" + WHERE album_id = "' . $db->real_escape_string($album_id) . '" LIMIT 1'); } if (mysqli_affected_rows($db) == 0) mysqli_query($db,'INSERT INTO album (artist_alphabetic, artist, album, year, month, genre_id, album_add_time, discs, image_id, album_id, updated, album_dr) VALUES ( - "' . mysqli_real_escape_string($db,$artist_alphabetic) . '", - "' . mysqli_real_escape_string($db,$artist) . '", - "' . mysqli_real_escape_string($db,$album) . '", + "' . $db->real_escape_string($artist_alphabetic) . '", + "' . $db->real_escape_string($artist) . '", + "' . $db->real_escape_string($album) . '", ' . ((is_null($year)) ? 'NULL' : (int) $year) . ', ' . ((is_null($month)) ? 'NULL' : (int) $month) . ', ' . (int) $aGenre_id . ', ' . (int) $album_add_time . ', ' . (int) $discs . ', - "' . mysqli_real_escape_string($db,$image_id) . '", - "' . mysqli_real_escape_string($db,$album_id) . '", + "' . $db->real_escape_string($image_id) . '", + "' . $db->real_escape_string($album_id) . '", 1, ' . ((is_null($album_dr)) ? 'NULL' : (int) $album_dr) . ')'); // Close getID3 @@ -995,245 +1011,149 @@ function countDirectories($base_dir) { }; - // +------------------------------------------------------------------------+ -// | File info | +// | File info loop | // +------------------------------------------------------------------------+ -function fileInfo() { - global $cfg, $db, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter, $prevDirsCounter, $prevFilesCounter, $logFile; - - - $year = NULL; - $dr = NULL; - // Initialize getID3 - $getID3 = new getID3; - //initial settings for getID3: - include 'include/getID3init.inc.php'; - - $updated = false; - $query = mysqli_query($db,'SELECT relative_file, filesize, filemtime, album_id FROM track WHERE updated ORDER BY relative_file'); - $filesCounter = mysqli_num_rows($query); - while ($track = mysqli_fetch_assoc($query)) { - ++$curFilesCounter; - $file = $cfg['media_dir'] . $track['relative_file']; - //convert file names to default charset - $file = iconv('UTF-8', NJB_DEFAULT_FILESYSTEM_CHARSET, $file); - if ($logFile != '') error_log( "fileInfo: " . $file . "\n", 3, $logFile); - if (is_file($file) == false) - message(__FILE__, __LINE__, 'error', '[b]Failed to read file:[/b][br]' . $file . '[list][*]Update again[*]Check file permission[/list]'); - - $filemtime = filemtime($file); - $filesize = filesize($file); - $force_filename_update = false; - - if ($filesize != $track['filesize'] || filemtimeCompare($filemtime, $track['filemtime']) == false || $force_filename_update) { - if ($cfg['cli_update'] == false && ((microtime(true) - $cfg['timer']) * 1000) > $cfg['update_refresh_time'] && ($curFilesCounter/$filesCounter > ($prevFilesCounter/$filesCounter + 0.005))) { - $prevFilesCounter = $curFilesCounter; - - mysqli_query($db,'update update_progress set - file_info = " |