sábado, 27 de diciembre de 2008

Convert ogg to mp3 respecting the heads

Este script te convierte archivos ogg en archivos mp3 manteniendo las cabeceras, es decir la metainformación de los archivos originales, como título, autor, etc. Es muy sencillo de usar:

ogg2mp3 files...

Te crea, por cada archivo .ogg que se le introduzca como parámetro, otro con el mismo nombre en mp3 en el directorio actual.



#!/bin/bash
###############################################################################
### Script to calculate the estimated time to finish a process. ###
### ###
### LICENSE: ###
### estimatetime is free software: you can redistribute it and/or modify ###
### it under the terms of the GNU General Public License as published by ###
### the Free Software Foundation, either version 3 of the License, or ###
### (at your option) any later version. ###
### ###
### estimatetime is distributed in the hope that it will be useful, ###
### but WITHOUT ANY WARRANTY; without even the implied warranty of ###
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ###
### GNU General Public License for more details. ###
### ###
### You should have received a copy of the GNU General Public License ###
### along with InTiMe. If not, see . ###
### ###
### AUTHORS: ###
### José Manuel Gómez Soriano ###
###############################################################################
usage()
{
echo `gettext "Usage"`":" `basename $0` "[files...]"
echo " " `basename $0` "-h"
echo `gettext "Convert serveral ogg files to mp3 respecting the sound file metadata."`
echo
echo -e " -h\t\t\t"`gettext "Show this help."`
}

while getopts "h" option
do
case "$option" in
h) usage; exit 0;;
[?]) usage; exit 1;;
esac
done
shift $(($OPTIND-1))

if [[ $# -lt 1 ]]
then
echo "One or more ogg files are necessary." > /etc/stderr
usage
exit 1
fi

for f in "$@"; do
echo $f
#f=$1
oggdec "$f" &&
filename=`echo $f | sed 's/\.ogg$//'` &&
info=`ogginfo "$f"` &&
title=`echo -e "$info" | grep 'TITLE' | sed 's/^\tTITLE=//'` &&
artist=`echo -e "$info" | grep 'ARTIST' | sed 's/^\tARTIST=//'` &&
album=`echo -e "$info" | grep 'ALBUM' | sed 's/^\tALBUM=//'` &&
year=`echo -e "$info" | grep 'DATE' | sed 's/^\tDATE=//'` &&
comment=`echo -e "$info" | grep 'COMMENT' | sed 's/^\tCOMMENT=//'` &&
track=`echo -e "$info" | grep 'TRACKNUMBER' | sed 's/^\tTRACKNUMBER=//'` &&
genre=`echo -e "$info" | grep 'GENRE' | sed 's/^\tGENRE=//' | awk -F '/' -F ' ' '{print $1}'` &&
if [[ -z $genre ]];
then
lame -h --tt "$title" --ta "$artist" --tl "$album" --ty "$year" --tc "$comment" --tn "$track" "$filename.wav" "$filename.mp3"
else
lame -h --tt "$title" --ta "$artist" --tl "$album" --ty "$year" --tc "$comment" --tn "$track" --tg "$genre" "$filename.wav" "$filename.mp3"
fi
rm "$filename.wav"
done


Convert xdxf to StarDict format in Linux

Para convertir de xdxf a StarDict formato es necesario tener instalada la herramienta tabfile o stardict-editor que permite convertir de un formato de texto tabulado a stardict. La herramienta tabfile, en Ubuntu 8.04 se encuenta en la siguiente ruta:

/usr/lib/stardict-tools/tabfile

Ahora sólo queda convertir de xdxf a este formato tabulado, para ello he realizado un pequeño script que usa el awk que lo permite hacer. El script es el siguiente:

----------- INICIO DEL SCRIPT: xdxf2tabfile -----------


#!/bin/bash
###############################################################################
### Script to calculate the estimated time to finish a process. ###
### ###
### LICENSE: ###
### estimatetime is free software: you can redistribute it and/or modify ###
### it under the terms of the GNU General Public License as published by ###
### the Free Software Foundation, either version 3 of the License, or ###
### (at your option) any later version. ###
### ###
### estimatetime is distributed in the hope that it will be useful, ###
### but WITHOUT ANY WARRANTY; without even the implied warranty of ###
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ###
### GNU General Public License for more details. ###
### ###
### You should have received a copy of the GNU General Public License ###
### along with InTiMe. If not, see . ###
### ###
### AUTHORS: ###
### José Manuel Gómez Soriano ###
###############################################################################
usage()
{
echo "Usage:" `basename $0` "file.xdxf > file.tab"
echo " " `basename $0` "-h"
echo `gettext "Convert the xdxf format to a text tab file."`
echo
echo -e " -h\t\t\t"`gettext "Show this help."`
}

while getopts "h" option
do
case "$option" in
h) usage; exit 0;;
[?]) usage; exit 1;;
esac
done
shift $(($OPTIND-1))

if [[ $# -ne 1 ]];
then
echo -e "ERROR: A file xdxf it is necessary as first parameter.\n" > /dev/stderr
usage
exit 1
fi

file=$1

if [[ !( -f $file ) ]]
then
echo -e "ERROR: The first parameter must be a file or -h.\n" > /dev/stderr
usage
exit 1
fi

awk '
BEGIN{
isword=0;
rep[" "]=" ";
rep["ɪ"]="ɪ";
rep["ú"]="ú";
rep["ə"]="ə";
rep["≈"]="≈";
rep["ó"]="ó";
rep["ñ"]="ñ";
rep["æ"]="æ";
rep["é"]="é";
rep["í"]="í";
rep["ʃ"]="ʃ";
rep["ʌ"]="ʌ";
rep["ɔ"]="ɔ";
rep["ʳ"]="ʳ";
rep["ɒ"]="ɒ";
rep["►"]=">";
rep["ɳ"]="ɳ";
rep["ʒ"]="ʒ";
rep["➣"]=">";
rep["á"]="á";
rep["¡"]="¡";
rep["♦"]="♦";
rep["ʊ"]="ʊ";
rep["¿"]="¿";
rep["ɜ"]="ɜ";
rep["ɑ"]="ɑ";
rep["Á"]="Á";
rep["ɵ"]="ɵ";
rep["Ÿ"]="Ÿ";
rep["ð"]="ð";
rep["➙"]=">";
rep["ü"]="ü";
rep["ð"]="ð";
rep["ɲ"]="ɲ";
rep["É"]="É";
rep["Ó"]="Ó";
rep["¨"]="¨";
rep["Í"]="Í";
rep["ê"]="ê";
rep["ª"]="ª";
rep["î"]="î";
rep["´"]="´";
rep["ç"]="ç";
rep["ï"]="ï";
rep["£"]="£";
rep["ɴ"]="ɴ";
rep["ρ"]="ρ";
rep["°"]="°";
rep["ã"]="ã";
rep["ô"]="ô";
rep["‚"]=",";
rep["Ú"]="Ú";
rep["à"]="à";
rep["â"]="â";
rep["è"]="è";
rep["œ"]="œ";
rep["•"]="·";
rep["º"]="º";
rep["è"]="è";
rep["è"]="è";
}
/.*<\/k>/{
gsub("|<\/k>","");
printf("%s\t",$0);
isword=1;
}
/<\/ar>/{print "";isword=0}
/[^<\/ar>]/{
if(isword==1) {
for(ex in rep)
gsub(ex,rep[ex]);
printf("%s\\n",$0)
}
}
' $file


----------- FINAL DEL SCRIPT: xdxf2tabfile -----------

El problema de este script es que no están incluidos todos los caracteres xx; pero si tu archivo xdxf estaba en utf-8 y no utilizaba estos caracteres entonces no habrá ningún problema. También puedes ir añadiendo estos caracteres en el array rep[].

Una vez ha sido creado este script los pasos son los siguientes:

xdxf2tabfile dic.xdxf > dic.tab
tabfile dic.tab

¡Y ha está!

domingo, 21 de diciembre de 2008

Activar el modo "Dedicate folder" en NetBeans

A partir de la versión 6.1 del Netbeans, existe la posibilidad de añadir las librerías al proyecto mediante un mecanismo de "importación" que coloca dichas librerías en el directorio lib/ de tu proyecto. Esto permite poder compartir por subversion esas librerías y compilarlas sin tener que modificar ninguna ruta en el build.xml. El problema es que la opción sólo te la ofrece el netbeans cuando creas un proyecto nuevo. Si no lo tienes creado debes hacer lo siguiente:

En el archivo nbproject/project.xml añadir las siguientes líneas:

<libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1">
    <definitions>./lib/nblibraries.properties</definitions>
</libraries>

Después del elemento data. Ejemplo.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
    <type>org.netbeans.modules.java.j2seproject</type>
    <configuration>
        <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
        ...
        </data>
        <libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1">
            <definitions>./lib/nblibraries.properties</definitions>
        </libraries>
    </configuration>
</project>


Después crear un archivo en lib/ llamado nblibraries.properties con el siguiente código:

libs.junit.classpath=\
    ${base}/junit/junit-3.8.2.jar
libs.junit_4.classpath=\
    ${base}/junit_4/junit-4.1.jar


A continuación ya se puede añadir librerías al proyecto.