#!/bin/bash # example: goear corey+sunglasses+at+night # author: at least 3 bash coders #Si el usuario no pone lo que busca en la linea de comandos, se lo pedimos. ################## if [ -z "$1" ]; then echo "Sintaxis:" echo " $0 <artist+word1+word2>" echo Note: Argument must be plus\(+\) separated or between \"\" exit fi ################## tmpdir=/tmp prefix=$RANDOM SEARCH=$tmpdir/$prefix-titulos.txt CANCIONES=$tmpdir/$prefix-canciones.txt ENLACES=$tmpdir/$prefix-enlaces.txt TITULOS=$tmpdir/$prefix-titulos.txt TODOWNLOAD=$tmpdir/$prefix-download.txt ################## if [ $1 ]; then TITULO="$@" else echo "Title and Artist:" read TITULO fi #Descargamos el PHP correspondiente al título. wget http://goear.com/search.php?q="$TITULO" -O $SEARCH #line number containing links is always changing so looking for a pattern head -$(grep -i -n -e 'ventana independiente' $SEARCH | cut -d ":" -f 1) $SEARCH | tail -1 > $CANCIONES #Mediante ER, obtenemos una lista de canciones y una lista de enlaces. #By using RegExp... we get song list and links egrep -o 'listen/......./[^"]' $CANCIONES > $ENLACES egrep -o '"Escuchar[^"]' $CANCIONES | grep -v 'en una ventana independiente' > $TITULOS #Mostramos al usuario los que ha encontrado en la primera página. Linea=1 cat $TITULOS | while read line; do { echo $Linea: ${line:9} let 'Linea += 1' } done #Si no encuentra nada, sale. CONDICION=`wc -l $TITULOS | awk '{print $1}'` if [ $CONDICION == 0 ]; then echo "No hay resultados. Prueba buscando otra cosa." rm -f $SEARCH $CANCIONES $ENLACES $TITULOS exit fi #Leemos qué canción quiere el usuario bajarse. echo "¿Cuál te quieres bajar? Indica el número: (0 para Cancelar)" read NUMERO #Cero para Cancelar if [ $NUMERO = 0 ]; then rm -f $SEARCH $CANCIONES $ENLACES $TITULOS echo "Hasta pronto." exit fi #Concatenamos http://www.goear.com con el contenido de aBajar.txt. #PD: Alguien sabe hacerlo de manera más sencilla? GOEAR=http://www.goear.com/ head -$NUMERO $ENLACES | tail -1 > $TODOWNLOAD for LISTEN in `cat $TODOWNLOAD` do ENLACE=${GOEAR}${LISTEN} done echo $ENLACE #A partir de aquí el script no es mío, pero es muy sencillo de leer. fileid=`echo $ENLACE | cut -d '/' -f 5` xmlurl="http://www.goear.com/tracker758.php?f="$fileid infoline=`wget -qO- $xmlurl | grep ".mp3"` mp3url=`echo $infoline | cut -d '"' -f6` artist=`echo $infoline | cut -d '"' -f10` title=`echo $infoline | cut -d '"' -f12` rm -f $SEARCH $CANCIONES $ENLACES $TITULOS $TODOWNLOAD wget $mp3url -O "$artist"_-_"$title.mp3" #mplayer -cache 1024 -softvol -softvol-max 1000 $mp3url