function writeId3Tags($filepath, $track) { $album = $track['albums'][0]; // Определяем информацию $tags = array('name' => $track['title'], 'artists' => $track['artists'][0]['name'], 'album' => $album['title'], 'year' => $album['year'], 'comment' => '', 'genre' => $album['genre'], 'track' => null); foreach ($tags as &$value) { if (is_string($value)) { $value = iconv('utf-8', 'windows-1251//ignore', $value); } } unset($value); $id3 = new MP3_Id(); $result = $id3->read($filepath); // Ошибка "Tag not found" игнорируется if (PEAR::isError($result) && $result->getCode() !== PEAR_MP3_ID_TNF) { throw new Exception($result->getMessage()); } $id3->setTag($tags); // Записываем информацию в тег $result = $id3->write(); if (PEAR::isError($result)) { throw new Exception($result->getMessage()); } return true; }
function initialize($Media) { if (isset($Media->objects['MP3_Id'])) { return true; } if (!isset($Media->file)) { return false; } $Object = new MP3_Id(); $Object->read($Media->file); $Object->study(); $Media->objects['MP3_Id'] =& $Object; return true; }
function printXML($arr) { foreach ($arr as $key => $val) { if (is_array($val)) { $folder_title = substr($key, $omit_folder_chars); ksort($val); printXML($val); } else { $file = $val; if (substr($file, -3) == 'mp3' || substr($file, -3) == 'MP3') { $file_title = substr($file, 0, strlen($file) - 4); // ID3v1 and ID3v2 tags parser $nome_arq = $file; $myId3 = new ID3($nome_arq); if ($myId3->getInfo()) { $f_title = $myId3->getTitle(); $f_artist = $myId3->getArtist(); } if (!$myId3->getArtist()) { $id3 = new MP3_Id(); $result = $id3->read($file); $f_title = $id3->getTag('name'); $f_artist = $id3->getTag('artists'); } if ($f_artist == '0' && $f_title == '0') { $arr_names = explode('/', strrev($nome_arq)); $substr = substr($arr_names[0], 4, strlen($arr_names[0])); $arr_names_last = explode('_', strrev($substr)); $f_artist = ''; $f_title = strrev($substr); } if ($f_artist == '0') { $f_artist = ''; } $f_id = str_replace("/", "", $file_title); $f_id = str_replace(".", "", $f_id); $f_id = str_replace(">", "", $f_id); $f_id = str_replace("<", "", $f_id); $f_id = str_replace("=", "", $f_id); $f_id = str_replace("(", "", $f_id); $f_id = str_replace(")", "", $f_id); $f_id = str_replace("\"", "", $f_id); if ($sEncoding = mb_detect_encoding($f_title, 'auto', true) != 'UTF-8') { $f_title = mb_convert_encoding($f_title, 'UTF-8', $sEncoding); } if ($sEncoding = mb_detect_encoding($f_artist, 'auto', true) != 'UTF-8') { $f_artist = mb_convert_encoding($f_artist, 'UTF-8', $sEncoding); } $f_title = conv($f_title); $f_artist = conv($f_artist); if (substr($f_title, 0, 4) == 'ÿþ') { $f_title = substr($f_title, 4); } if (substr($f_artist, 0, 4) == 'ÿþ') { $f_artist = substr($f_artist, 4); } $f_title = str_replace(">", "", $f_title); $f_title = str_replace("<", "", $f_title); $f_artist = str_replace(">", "", $f_artist); $f_artist = str_replace("<", "", $f_artist); $f_id = encoding($f_id); $path = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $path = dirname($path); $defaul_dir = substr($val, 0, strrpos($val, '/')); $file_name_ = substr(strrchr($val, '/'), 1); $url_dec = rawurlencode($file_name_); $val = $defaul_dir . '/' . $url_dec; $file = $val; $file = 'http://' . $path . '/' . $file; // Writing in XML print ' <song id="' . $f_id . '" title="' . $f_title . '" artist="' . $f_artist . '" src="' . $file . '" />'; } } } }
break; } $im1 = ImageCreateTrueColor($tn_width, $tn_height); imagecopyresized($im1, $im, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height); $path = "{$filesroot}/graftemp"; $imagnam = "{$path}/{$namefile}.temp.png"; imageJpeg($im1, $imagnam, $quality); echo "<p><img src='" . $imagnam . "' alt=''/></p>"; imagedestroy($im); imagedestroy($im1); @chmod("{$imagnam}", 0644); echo $widthf . ' x ' . $heightf . 'px<br/>'; } if ($prg == "mp3") { $id3 = new MP3_Id(); $result = $id3->read("{$adrfile['adres']}/{$adrfile['name']}"); $result = $id3->study(); echo '<p>'; if (!empty($id3->artists)) { echo '<div><b>' . $lng_dl['artist'] . ':</b> ' . $id3->artists . '</div>'; } if (!empty($id3->album)) { echo '<div><b>' . $lng_dl['album'] . ':</b> ' . $id3->album . '</div>'; } if (!empty($id3->year)) { echo '<div><b>' . $lng_dl['released'] . ':</b> ' . $id3->year . '</div>'; } if (!empty($id3->name)) { echo '<div><b>' . $lng['title'] . ':</b> ' . $id3->name . '</div>'; } echo '</p>';