4 require_once 'HTML/Template/Sigma.php';
13 $name = basename($argv[0]);
14 echo "Modo de uso:\n";
15 echo " $name <volumen> [<directorio>] [<filename>]\n\n";
16 echo "Por defecto se usa el directorio actual y se guarda el resultado en MP3_<volumen>.glabels\n";
21 $dir = @$argv[2] ? $argv[2] : '.';
22 $filename = @$argv[3] ? $argv[3] : "MP3_$numero.glabels";
23 $template = 'Template.MP3.glabels';
24 $template_dir = '/home/luca/mp3_labels';
28 while (($f = $d->read()) !== false) {
29 if (is_dir("$dir/$f") and $f != '.' and $f != '..') {
31 while (($f2 = $d2->read()) !== false) {
32 if (is_dir("$dir/$f/$f2") and $f2 != '.' and $f2 != '..') {
34 $d3 = dir("$dir/$f/$f2");
35 while (($f3 = $d3->read()) !== false) {
36 if (preg_match('/\.mp3$/i', $f3)) {
41 if (preg_match('/(\d{4}) - (.*)/', $f2, $m)) {
42 $datos[ucwords($f)][] = ucwords("$m[2] [$m[1]]");
44 $datos[ucwords($f)][] = ucwords($f2);
54 $tpl =& new HTML_Template_Sigma($template_dir);
55 $tpl->loadTemplateFile($template);
56 $tpl->setGlobalVariable(array(
64 foreach ($datos as $artista => $albums) {
65 if ($y > Y_MAX and !@$col2) {
70 $tpl->setVariable(array(
73 'LINEA_Y' => $y + PUNTOS - 1,
74 'LINEA_ANCHO' => strlen($artista) * 6,
75 'ARTISTA' => translate($artista),
78 for ($i = 0; $i < count($albums); $i++) {
80 $tpl->setVariable('ALBUM', translate($albums[$i]));
82 $tpl->parse('ALBUMS');
84 $y += PUNTOS * ($i + 2);
85 $tpl->parse('ARTISTAS');
88 $results = $tpl->get();
90 $fo = fopen($filename, 'w');
95 function translate($str) {
96 static $tabla = array();
98 $tabla = get_html_translation_table(HTML_ENTITIES);
100 foreach ($tabla as $char => $void) {
101 $tabla[$char] = '&#' . ord($char) . ';';
104 return strtr($str, $tabla);