pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Bash pastebin - collaborative debugging tool View Help


Posted by nordri on Sun 9 Mar 18:28
report abuse | download | new post

  1. #!/bin/bash
  2. #
  3. # Genera un listado con las peliculas del disco externo.
  4. #
  5. # Fede Diaz (nordri@...)
  6. # Febrero 2008 - Version 0.1
  7. # Marzo 2008 - Version 0.2 Genera informes en html con enlaces a filmaffinity
  8. #
  9.  
  10. PPATH="/mnt/backup/pelis"
  11. EMAILS="Escribe aquí las direcciones de correo separadas por comas"
  12. TMPPATH="/tmp/pelis.script"
  13. LISTA_TITULOS=$TMPPATH/listaTitulos.html
  14. LISTA_GENEROS=$TMPPATH/generos
  15. TITULOS_SIN_BARRAS=$TMPPATH/auxBarras.txt
  16. TITULOS_SIN_PUNTOS=$TMPPATH/auxPuntos.txt
  17. SERIES=$TMPPATH/series.lista
  18. DOCUS=$TMPPATH/docus.lista
  19.  
  20. # Funcion que elimina las barras ("/") de la cadena (Genero)
  21. function limpiaBarrasCadena() {
  22.   echo $1 | awk -F"/" '{ print $4 }'
  23. }
  24.  
  25. # Funcion que elimina el punto de extension de la cadena (Genero)
  26. function limpiaPuntoCadena() {
  27.   echo $1 | awk -F"." '{ print $1 }'
  28. }
  29.  
  30. # Funcion que formatea la cadena de pelicula para que solo quede el titulo
  31. function formateaPelicula() {
  32.   cat $1 | awk -F"/" '{ print $6 }' >> $TITULOS_SIN_BARRAS
  33.   cat $TITULOS_SIN_BARRAS | awk -F"." '{ print $1 }' >> $TITULOS_SIN_PUNTOS
  34.   rm $TITULOS_SIN_BARRAS
  35. }
  36.  
  37. # Funcion para anadir titulos
  38. function anadir(){
  39.   case $1 in
  40.     "pelicula")
  41.       TAM=`wc -l $2 | awk -F" " '{ print $1 }'`
  42.    
  43.       for i in `seq 1 $TAM`; do
  44.         TITULO=`head -n $i $2 | tail -1`;
  45.         generaHTML titulo "$TITULO";
  46.       done  
  47.       rm $TITULOS_SIN_PUNTOS
  48.     ;;
  49.     "serie")
  50.       ls $PPATH/Series >> $SERIES
  51.       TAM=`wc -l $SERIES | awk -F" " '{ print $1 }'`
  52.  
  53.       for i in `seq 1 $TAM`; do
  54.         TITULO=`head -n $i $SERIES | tail -1`;
  55.         generaHTML titulo "$TITULO";
  56.       done
  57.     ;;
  58.     "docu")
  59.       ls $PPATH/Documentales >> $DOCUS
  60.       TAM=`wc -l $DOCUS | awk -F" " '{ print $1 }'`
  61.  
  62.       for i in `seq 1 $TAM`; do
  63.         TITULO=`head -n $i $DOCUS | tail -1`;
  64.         generaHTML titulo "$TITULO";
  65.       done
  66.     ;;
  67.   esac
  68. }
  69.  
  70. # Genera el código HTML por casos. HEAD : Cabezera, GENERO : Genero del video,
  71. # TITULO : Titulo del video + link, CIERRA : Cierra la página.
  72. function generaHTML() {
  73.   case $1 in
  74.     "head")
  75.       echo "<html><head><title>El Listado de Películas</title></head><body bgcolor=\"#efefef\" text=\"black\" link=\"blue\" vlink=\"#551A8B\" alink=\"red\">" >> $LISTA_TITULOS
  76.     ;;
  77.     "genero")
  78.       echo "<p><b>Peliculas del Genero: "$2"</b></p>" >> $LISTA_TITULOS
  79.     ;;
  80.     "titulo")
  81.       echo "<li><a href=\"http://www.filmaffinity.com/es/search.php?stext=$2&stype%5B%5D=title&genre=&country=&fromyear=&toyear=\">"$2"</a></li>" >> $LISTA_TITULOS
  82.     ;;
  83.     "cierra")
  84.       echo "</body></html>" >> $LISTA_TITULOS
  85.     ;;
  86.   esac  
  87. }
  88.  
  89. function lista(){
  90.   if [ $1 == "empieza" ]; then
  91.     echo "<ol>" >> $LISTA_TITULOS
  92.   else
  93.     echo "</ol>" >> $LISTA_TITULOS
  94.   fi
  95. }
  96.  
  97. # Obtenemos los generos disponibles
  98. ls $PPATH > $LISTA_GENEROS
  99.  
  100. # Hacemos un bucle que clasificara el contenido de las carpetas
  101. # segun su genero y los guardara en ficheros distintos
  102. for GENERO in `cat $LISTA_GENEROS`; do
  103.   find $PPATH/$GENERO -iname "*.avi" | sort > $TMPPATH/$GENERO.lista;
  104. done
  105.  
  106. # Una vez que tenemos las pelis separas por genero las juntamos poniendo una
  107. # cabezera con el genero. Se hace en un nuevo bucle en el que al mismo tiempo
  108. # se le añade el formato a la cadena para que solo aparezca el titulo de la
  109. # pelicula.
  110. generaHTML head # Inserta la cabezera del código HTML
  111.  
  112. for GENERO in `ls $TMPPATH/*.lista`; do
  113.   GENERO_SIN_BARRAS=`limpiaBarrasCadena $GENERO`       
  114.   GENERO_SIN_PUNTO=`limpiaPuntoCadena $GENERO_SIN_BARRAS`
  115.  
  116.   generaHTML genero $GENERO_SIN_PUNTO
  117.   lista empieza # Inserta la etiqueta de lista HTML superada
  118.  
  119.   case $GENERO_SIN_PUNTO in
  120.     "Series")
  121.       anadir serie
  122.       ;;
  123.     "Documentales")
  124.       anadir docu
  125.       ;;
  126.     *)
  127.       formateaPelicula $GENERO # Se da formato al listado de pelis del Genero.
  128.       anadir pelicula $TITULOS_SIN_PUNTOS    # Se anade el listado de pelis del Genero.
  129.       ;;
  130.   esac
  131.  
  132.   lista termina # Cierra la lista HTML numerada
  133. done
  134.  
  135. # Escribimos el código HTML para cerrar la página
  136. generaHTML cierra
  137.  
  138. # Enviar la lista por correo.
  139. cat $LISTA_TITULOS | email --quiet --html --subject "Nuevo listado de peliculas" $EMAILS
  140.  
  141. # Limpiamos los ficheros generados.
  142. rm $TMPPATH/*

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post