Exemplo n.º 1
0
function recursiveValidate($dir)
{
    global $cfg, $db;
    $entries = @scandir($dir) or message(__FILE__, __LINE__, 'error', '[b]Failed to open directory:[/b][br]' . $dir);
    foreach ($entries as $entry) {
        if (!in_array($entry, array('.', '..', 'index.php'))) {
            if (is_dir($dir . $entry . '/')) {
                recursiveValidate($dir . $entry . '/');
                if (strlen($entry) != 1) {
                    @rmdir($dir . $entry . '/');
                }
            } else {
                $file = $dir . $entry;
                $relative_file = substr($file, strlen(NJB_HOME_DIR));
                $query = mysql_query('SELECT filesize, filemtime FROM cache
					WHERE relative_file = "' . mysql_real_escape_string($relative_file) . '"');
                $cache = mysql_fetch_assoc($query);
                if (filesize($file) == $cache['filesize'] && filemtimeCompare(filemtime($file), $cache['filemtime'])) {
                    mysql_query('UPDATE cache
						SET updated			= 1
						WHERE relative_file	= "' . mysql_real_escape_string($relative_file) . '"');
                } else {
                    @unlink($file);
                    // File can be in use by another process.
                    // So don't give an error message when the file can't be deleted.
                }
            }
        }
    }
}
Exemplo n.º 2
0
function fileInfo()
{
    global $cfg, $db, $dirsCounter, $filesCounter, $curFilesCounter, $curDirsCounter, $prevDirsCounter, $prevFilesCounter;
    $year = NULL;
    $dr = NULL;
    // Initialize getID3
    $getID3 = new getID3();
    //initial settings for getID3:
    include 'include/getID3init.inc.php';
    /* 
    	// Force update all tracks on new getID3() or netjukebox update.php version. 
    	$new_getid3_hash = hmacmd5($getID3->version(), file_get_contents(NJB_HOME_DIR . 'update.php'));
    	if ($new_getid3_hash != $cfg['getid3_hash']) {
    		mysql_query('UPDATE track SET filemtime = 0 WHERE 1');
    		mysql_query('UPDATE server SET value = "' . mysql_real_escape_string($new_getid3_hash) . '" WHERE name = "getid3_hash" LIMIT 1');
    	}
    */
    $updated = false;
    $query = mysql_query('SELECT relative_file, filesize, filemtime, album_id FROM track WHERE updated ORDER BY relative_file');
    $filesCounter = mysql_num_rows($query);
    while ($track = mysql_fetch_assoc($query)) {
        ++$curFilesCounter;
        $file = $cfg['media_dir'] . $track['relative_file'];
        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;
                mysql_query('update update_progress set 
				file_info = "<div class=\'out\'><div class=\'in\' style=\'width:' . html(floor($curFilesCounter / $filesCounter * 200)) . 'px\'></div></div> ' . html(floor($curFilesCounter / $filesCounter * 100)) . '%"');
                // echo '<script type="text/javascript"> document.getElementById(\'fileinfo\').innerHTML="<div class=\'out\'><div class=\'in\' style=\'width:' . $curFilesCounter/$filesCounter * 200 . 'px\'></div></div> ' . html(floor($curFilesCounter/$filesCounter * 100)) . '%";</script>' . "\n";
                // @ob_flush();
                // flush();
                $cfg['timer'] = microtime(true);
                $updated = true;
            }
            if ($cfg['cli_update'] && $cfg['cli_silent_update'] == false) {
                echo $file . "\n";
            }
            $ThisFileInfo = $getID3->analyze($file);
            getid3_lib::CopyTagsToComments($ThisFileInfo);
            //print $ThisFileInfo['id3v1']['genre'];
            $mime_type = isset($ThisFileInfo['mime_type']) ? $ThisFileInfo['mime_type'] : 'application/octet-stream';
            $miliseconds = isset($ThisFileInfo['playtime_seconds']) ? round($ThisFileInfo['playtime_seconds'] * 1000) : 0;
            $audio_bitrate = 0;
            $audio_bits_per_sample = 0;
            $audio_sample_rate = 0;
            $audio_channels = 0;
            $audio_lossless = 0;
            $audio_compression_ratio = 0;
            $audio_dataformat = '';
            $audio_encoder = '';
            $audio_bitrate_mode = '';
            $audio_profile = '';
            $video_dataformat = '';
            $video_codec = '';
            $video_resolution_x = 0;
            $video_resolution_y = 0;
            $video_framerate = 0;
            $track_id = $track['album_id'] . '_' . fileId($file);
            $error = isset($ThisFileInfo['error']) ? implode('<br>', $ThisFileInfo['error']) : '';
            if (isset($ThisFileInfo['comments']['albumartist'][0])) {
                $artist = $ThisFileInfo['comments']['albumartist'][0];
            } elseif (isset($ThisFileInfo['comments']['band'][0])) {
                $artist = $ThisFileInfo['comments']['band'][0];
            } else {
                $artist = 'Unknown AlbumArtist';
            }
            //if (isset($ThisFileInfo['comments']['artist'][1]))
            //	$track_artist = $ThisFileInfo['comments']['artist'][1];
            if (isset($ThisFileInfo['comments']['artist'][0])) {
                $track_artist = $ThisFileInfo['comments']['artist'][0];
            } else {
                $track_artist = 'Unknown TrackArtist';
            }
            //if (isset($ThisFileInfo['comments']['title'][1]))
            //	$title = $ThisFileInfo['comments']['title'][1];
            if (isset($ThisFileInfo['comments']['title'][0])) {
                $title = $ThisFileInfo['comments']['title'][0];
            } else {
                $title = 'Unknown Title';
            }
            if (isset($ThisFileInfo['comments']['genre'][0])) {
                $genre = $ThisFileInfo['comments']['genre'][0];
            } else {
                $genre = 'Unknown Genre';
            }
            $a = array_values($ThisFileInfo['comments']['comment']);
            if (isset($a[0])) {
                $comment = $a[0];
            } else {
                $comment = '';
            }
            if (isset($ThisFileInfo['comments']['year'][0])) {
                $year = $ThisFileInfo['comments']['year'][0];
            } elseif (isset($ThisFileInfo['comments']['date'][0])) {
                $year = $ThisFileInfo['comments']['date'][0];
            }
            if (preg_match('#[1][9][0-9]{2}|[2][0-9]{3}#', $year, $match)) {
                $year = $match[0];
            }
            if (isset($ThisFileInfo['comments']['dynamic range'][0])) {
                $dr = $ThisFileInfo['comments']['dynamic range'][0];
            } elseif (isset($ThisFileInfo['tags']['id3v2']['text']['DYNAMIC RANGE'])) {
                $dr = $ThisFileInfo['tags']['id3v2']['text']['DYNAMIC RANGE'];
            }
            /* if (isset($ThisFileInfo['comments']['date'][0])) $year = $ThisFileInfo['comments']['date'][0];
            			elseif (isset($ThisFileInfo['comments']['year'][0])) $year = $ThisFileInfo['comments']['year'][0]; */
            if (isset($ThisFileInfo['audio']['dataformat'])) {
                $audio_dataformat = $ThisFileInfo['audio']['dataformat'];
                $audio_encoder = isset($ThisFileInfo['audio']['encoder']) ? $ThisFileInfo['audio']['encoder'] : 'Unknown encoder';
                if (isset($ThisFileInfo['mpc']['header']['profile'])) {
                    $audio_profile = $ThisFileInfo['mpc']['header']['profile'];
                }
                if (isset($ThisFileInfo['aac']['header']['profile_text'])) {
                    $audio_profile = $ThisFileInfo['aac']['header']['profile_text'];
                }
                if (empty($ThisFileInfo['audio']['lossless']) == false) {
                    $audio_lossless = 1;
                    if (empty($ThisFileInfo['audio']['compression_ratio']) == false) {
                        if ($ThisFileInfo['audio']['compression_ratio'] == 1) {
                            $audio_profile = 'Lossless';
                        } else {
                            $audio_profile = 'Lossless compression';
                        }
                    } else {
                        $audio_profile = 'Lossless';
                    }
                }
                if (isset($ThisFileInfo['audio']['compression_ratio'])) {
                    $audio_compression_ratio = $ThisFileInfo['audio']['compression_ratio'];
                }
                if (isset($ThisFileInfo['audio']['bitrate_mode'])) {
                    $audio_bitrate_mode = $ThisFileInfo['audio']['bitrate_mode'];
                }
                if (isset($ThisFileInfo['audio']['bitrate'])) {
                    $audio_bitrate = $ThisFileInfo['audio']['bitrate'];
                }
                if (!$audio_profile) {
                    $audio_profile = $audio_bitrate_mode . ' ' . round($audio_bitrate / 1000, 1) . '  kbps';
                }
                $audio_bits_per_sample = isset($ThisFileInfo['audio']['bits_per_sample']) ? $ThisFileInfo['audio']['bits_per_sample'] : 16;
                $audio_sample_rate = isset($ThisFileInfo['audio']['sample_rate']) ? $ThisFileInfo['audio']['sample_rate'] : 44100;
                $audio_channels = isset($ThisFileInfo['audio']['channels']) ? $ThisFileInfo['audio']['channels'] : 2;
                $audio_bitrate = round($audio_bitrate);
                // integer in database
            }
            if (isset($ThisFileInfo['video']['dataformat'])) {
                $video_dataformat = $ThisFileInfo['video']['dataformat'];
                $video_codec = isset($ThisFileInfo['video']['codec']) ? $ThisFileInfo['video']['codec'] : 'Unknown codec';
                if (isset($ThisFileInfo['video']['resolution_x'])) {
                    $video_resolution_x = $ThisFileInfo['video']['resolution_x'];
                }
                if (isset($ThisFileInfo['video']['resolution_y'])) {
                    $video_resolution_y = $ThisFileInfo['video']['resolution_y'];
                }
                if (isset($ThisFileInfo['video']['frame_rate'])) {
                    $video_framerate = $ThisFileInfo['video']['frame_rate'] . ' fps';
                }
            }
            mysql_query('UPDATE track SET
				mime_type					= "' . mysql_real_escape_string($mime_type) . '",
				filesize					= ' . (int) $filesize . ',
				filemtime					= ' . (int) $filemtime . ',
				miliseconds					= ' . (int) $miliseconds . ',
				audio_bitrate				= ' . (int) $audio_bitrate . ',
				audio_bits_per_sample		= ' . (int) $audio_bits_per_sample . ',
				audio_sample_rate			= ' . (int) $audio_sample_rate . ',
				audio_channels				= ' . (int) $audio_channels . ',
				audio_lossless				= ' . (int) $audio_lossless . ',
				audio_compression_ratio		= ' . (double) $audio_compression_ratio . ',			
				audio_dataformat			= "' . mysql_real_escape_string($audio_dataformat) . '",
				audio_encoder 				= "' . mysql_real_escape_string($audio_encoder) . '",
				audio_profile				= "' . mysql_real_escape_string($audio_profile) . '",
				video_dataformat			= "' . mysql_real_escape_string($video_dataformat) . '",
				video_codec					= "' . mysql_real_escape_string($video_codec) . '",
				video_resolution_x			= ' . (int) $video_resolution_x . ',
				video_resolution_y			= ' . (int) $video_resolution_y . ',
				video_framerate				= ' . (int) $video_framerate . ',
				error						= "' . mysql_real_escape_string($error) . '",
				track_id					= "' . mysql_real_escape_string($track_id) . '",
				genre			= "' . mysql_real_escape_string($genre) . '",
				title			= "' . mysql_real_escape_string($title) . '",
				artist			= "' . mysql_real_escape_string($track_artist) . '",
				comment			= "' . mysql_real_escape_string($comment) . '",
				track_artist			= "' . mysql_real_escape_string($track_artist) . '",
				year			= ' . (is_null($year) ? 'NULL' : (int) $year) . ',
				dr		= ' . (is_null($dr) ? 'NULL' : (int) $dr) . '
				WHERE relative_file 		= BINARY "' . mysql_real_escape_string($track['relative_file']) . '"');
        }
        if ($updated && (microtime(true) - $cfg['timer']) * 1000 > 500) {
            echo '<script type="text/javascript">document.getElementById(\'fileinfo\').innerHTML=\'<img src="' . $cfg['img'] . 'small_animated_progress.gif" alt="" class="small">\';</script>' . "\n";
            @ob_flush();
            flush();
            $updated = false;
        }
        if ($cfg['name_source'] != 'tags') {
            $result = mysql_query('SELECT genre_id FROM genre WHERE genre="' . mysql_real_escape_string($genre) . '"');
            if (mysql_num_rows($result) == 0) {
                mysql_query('INSERT INTO genre (genre_id, genre)
							VALUES ("' . mysql_real_escape_string($lastGenre_id) . '",
									"' . mysql_real_escape_string($genre) . '")');
                $aGenre_id = $lastGenre_id;
                ++$lastGenre_id;
            } else {
                $row = mysql_fetch_assoc($result);
                $genre_id = $row["genre_id"];
            }
        }
    }
    // Close getID3
    unset($getID3);
}