function addFolder($folder){ $dir_iterator = new RecursiveDirectoryIterator($folder); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); Log_("Запускаю сканирование по каталогу $folder"); $count_tracks = $size_tracks = 0; $current_date = date("Y-m-d H:i:s"); $cc = 0; foreach ($iterator as $file) { if( $file != '.' && $file != '..') if( $file->isFile() ) { if( $file->getExtension() == 'mp3' ) { $tags = mp3tags($file); $filename = $file; $cover = dirname($filename)."/cover.jpg"; if (mb_detect_encoding($filename, 'UTF-8', true) === false) { // $filename = iconv("windows-1251","UTF-8",$filename); echo "Coding into WINDOWS-1251<br>"; $filename = iconv("WINDOWS-1251","UTF-8",$filename); $cover = dirname($filename)."/cover.jpg"; } $artist = iconv("windows-1251","UTF-8",$tags["ARTISTS"]); $album = iconv("windows-1251","UTF-8",$tags["ALBUM"]); $title = iconv("windows-1251","UTF-8",$tags["NAME"]); $genre = getGenre($tags["GENRENO"]); $year = $tags["YEAR"]; $size_tracks += $file->getSize(); $count_tracks ++; $filename = mysql_real_escape_string($filename); $artist = mysql_real_escape_string($artist); $album = mysql_real_escape_string($album); $title = mysql_real_escape_string($title); $cover = mysql_real_escape_string($cover); addToTable($artist, $album, $title, $genre, $year, $filename, $cover, $current_date); Log_("Добавление файла: $filename"); Log_("С тегами: $artist - $album - $title - $genre - $year"); // echo "$artist|$album|$title|$genre|$year<br> $filename"; // echo "<hr><br>"; } } } Log_("Сканирование завершено. Добавлено файлов $count_tracks."); $size_tracks_mb = round($size_tracks / 1000000000,2); $mas = getInfoTable(); $size_tracks_mb += $mas["size"]; $count_tracks += $mas["count"]; setInfoToTable($count_tracks, $size_tracks_mb); return 1; }
function myscan(&$arr, $dir) { $cont = glob($dir . "/*"); // echo "myscan"; foreach ($cont as $file) { if (is_dir($file)) { if ($file != '.' && $file != '..') { myscan($arr, $file); } } else { if (strpos($file, ".mp3") != false) { $tags = mp3tags($file); // print_r($tags); $artist = $tags["ARTISTS"]; $filename = substr($file, DIR_CUT_COUNT); $filename = iconv("windows-1251", "UTF-8", $filename); $artist = iconv("windows-1251", "UTF-8", $tags["ARTISTS"]); $album = iconv("windows-1251", "UTF-8", $tags["ALBUM"]); $title = iconv("windows-1251", "UTF-8", $tags["NAME"]); $genre = getGenre($tags["GENRENO"]); $year = $tags["YEAR"]; $cover = substr(dirname($file) . "/cover.jpg", DIR_CUT_COUNT); $cover = substr(dirname(iconv("windows-1251", "UTF-8", $file)) . "/cover.jpg", DIR_CUT_COUNT); $filename = mysql_real_escape_string($filename); $artist = mysql_real_escape_string($artist); $album = mysql_real_escape_string($album); $title = mysql_real_escape_string($title); $cover = mysql_real_escape_string($cover); //записываем в базу данных $sql = "insert into " . MUSIC_TABLE . " (artist,albums,tracks,filename,cover,genre,year) values \n\t\t\t\t('{$artist}','{$album}','{$title}','{$filename}','{$cover}','{$genre}','{$year}')"; $q = mysql_query($sql) or die(mysql_error()); echo "{$artist}|{$album}|{$title}|{$genre}|{$year}<br>{$filename}"; echo "<hr><br>"; } } } }
$query = mysql_query("create table if not exists `user_playlist` (\r\n\t\t\t\t\t\t\t`id` int(11) not null auto_increment,\r\n\t\t\t\t\t\t\t`id_user` varchar(30) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`name` varchar(300) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`date` datetime COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`social` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`social_ratng` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\tprimary key(id))") or die(mysql_error()); $query = mysql_query("create table if not exists `playlists` (\r\n\t\t\t\t\t\t\t`id` int(11) not null auto_increment,\r\n\t\t\t\t\t\t\t`id_pls` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`name_pls` varchar(30) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`id_user` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`id_track` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`date` datetime COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`social` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`social_rating` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\tprimary key(id))") or die(mysql_error()); $query = mysql_query("create table if not exists `users` (\r\n\t\t\t\t\t\t\t`id` int(11) not null auto_increment,\r\n\t\t\t\t\t\t\t`login` varchar(40) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`password` varchar(50) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`salt` varchar(50) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`date_reg` datetime COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`date_last` datetime COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`admin` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`pid` varchar(50) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\tprimary key(id))") or die(mysql_error()); // таблица настроек $query = mysql_query("create table if not exists `settings` (\r\n\t\t\t\t\t\t\t`id` int(11) not null auto_increment,\r\n\t\t\t\t\t\t\t`id_user` int(11) COLLATE utf8_general_ci NOT NULL,\r\n\t\t\t\t\t\t\t`volume` int(11) COLLATE utf8_general_ci NOT NULL DEFAULT 8,\r\n\t\t\t\t\t\t\tprimary key(id))") or die(mysql_error()); $dir_iterator = new RecursiveDirectoryIterator("music"); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); // could use CHILD_FIRST if you so wish $count_tracks = $size_tracks = 0; $current_date = date("Y-m-d H:i:s"); $cc = 0; foreach ($iterator as $file) { if ($file != '.' && $file != '..') { if ($file->isFile()) { if ($file->getExtension() == 'mp3') { $tags = mp3tags($file); $filename = $file; $cover = dirname($filename) . "/cover.jpg"; if (mb_detect_encoding($filename, 'UTF-8', true) === false) { // $filename = iconv("windows-1251","UTF-8",$filename); echo "Coding into WINDOWS-1251<br>"; $filename = iconv("WINDOWS-1251", "UTF-8", $filename); $cover = dirname($filename) . "/cover.jpg"; } $artist = iconv("windows-1251", "UTF-8", $tags["ARTISTS"]); $album = iconv("windows-1251", "UTF-8", $tags["ALBUM"]); $title = iconv("windows-1251", "UTF-8", $tags["NAME"]); $genre = getGenre($tags["GENRENO"]); $year = $tags["YEAR"]; $size_tracks += $file->getSize(); $count_tracks++;