#!/usr/bin/php4 -qC
[] []\n\n";
echo "Por defecto se usa el directorio actual y se guarda el resultado en MP3_.glabels\n";
exit;
}
$numero = $argv[1];
$dir = @$argv[2] ? $argv[2] : '.';
$filename = @$argv[3] ? $argv[3] : "videos-dvd-$numero.glabels";
$template = 'Template.VIDEOS.glabels';
$template_dir = '.';
$datos = array();
$d = dir($dir);
while (($f = $d->read()) !== false) {
if (is_dir("$dir/$f") and $f != '.' and $f != '..') {
$d2 = dir("$dir/$f");
while (($f2 = $d2->read()) !== false) {
if (in_array(strtolower(preg_replace('/.*\.(.*)/', '$1', $f2)), $extensiones)) {
# Es un video
$datos[ucwords($f)][] = ucwords(preg_replace('/(.*)\..*/', '$1', $f2));
}
}
} elseif (in_array(strtolower(preg_replace('/.*\.(.*)/', '$1', $f)), $extensiones)) {
# Es un video
if (preg_match('/(.*) - (.*)/', $f, $m)) {
$datos[ucwords(preg_replace('/(.*)\..*/', '$1', $m[1]))][] = ucwords(preg_replace('/(.*)\..*/', '$1', $m[2]));
} else {
$datos[ucwords(preg_replace('/(.*)\..*/', '$1', $f))] = array();
}
}
}
if ($datos) {
$tpl =& new HTML_Template_Sigma($template_dir);
$tpl->loadTemplateFile($template);
$tpl->setGlobalVariable(array(
'N' => sprintf("%02d", $numero),
'PUNTOS' => PUNTOS,
));
$x = X_BASE;
$y = Y_BASE;
ksort($datos);
foreach ($datos as $artista => $albums) {
if ($y > Y_MAX and !@$col2) {
$x = X_COL2;
$y = Y_BASE;
$col2 = true;
}
$tpl->setVariable(array(
'X' => $x,
'TEXTO_Y' => $y,
'LINEA_Y' => $y + PUNTOS + 2.5,
'LINEA_ANCHO' => strlen($artista) * 2.5 + 25 / strlen($artista),
'ARTISTA' => translate($artista),
));
sort($albums);
for ($i = 0; $i < count($albums); $i++) {
// assign data
$tpl->setVariable('ALBUM', translate($albums[$i]));
// process the block
$tpl->parse('ALBUMS');
}
$y += PUNTOS * ($i + 2);
$tpl->parse('ARTISTAS');
}
$results = $tpl->get();
$fo = fopen($filename, 'w');
fputs($fo, $results);
fclose($fo);
}
function translate($str) {
static $tabla = array();
if (!@$tabla) {
$tabla = get_html_translation_table(HTML_ENTITIES);
array_shift($tabla);
foreach ($tabla as $char => $void) {
$tabla[$char] = '' . ord($char) . ';';
}
}
return strtr($str, $tabla);
}
# vim: set et sw=4 :
?>