Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Ambdós costats versió prèvia Revisió prèvia | |||
| misproyectos:procesadescargas [07/12/2017 16:33] – [método] mate | misproyectos:procesadescargas [04/09/2018 01:49] (actual) – suprimit mate | ||
|---|---|---|---|
| Línia 1: | Línia 1: | ||
| - | = procesa descargas | ||
| - | == objetivo | ||
| - | crear un método para gestionar la descarga de los ficheros **.torrent**, | ||
| - | == método | ||
| - | - esta parte indica la URL del site (conseguida a través del lector RSS) donde encontraremos el fichero .torrent (no el .torrent directamente) para descargarlo y proceder a su subida en el servidor externo con rTorrent, donde se procederá a su descarga | ||
| - | - la parte de sincronización entre el servidor y la raspberry (mediante '' | ||
| - | - el proceso de los ficheros descargados ya en local (desde la raspberry) y su " | ||
| - | == tecnologías | ||
| - | - lector de RSS | ||
| - | - sites de películas/ | ||
| - | - un servidor externo corriendo rTorrent | ||
| - | - una raspberry ejecutando tareas de sincronización de directorios | ||
| - | |||
| - | == 1 | ||
| - | <code bash newpct+down+scp+pass+kde.sh> | ||
| - | #!/bin/bash | ||
| - | |||
| - | |||
| - | # versiones | ||
| - | # PTE cambiar variable URL_TMP pot URL2 directamente | ||
| - | # | ||
| - | # 5.8 informar solo en caso de error del log de intento de conexión, si no, dar OK en popup emergente | ||
| - | # 5.7 modificación para nuevas URLs de tumejortorrent.com | ||
| - | # han modificado la ubicación de la URL (ahora está en una función llamada OpenTorrent), | ||
| - | # OK en sentencias IF, hacer que reconozca el patrón http:// | ||
| - | # 5.6 añadido soporte para las URLs de torrentrapid.com | ||
| - | # | ||
| - | # 5.5 | ||
| - | # 5.4.1 realizadas modificaciones para reconocer contraseñas del site " | ||
| - | # > No funciona pq la gente de " | ||
| - | # 5.4 | ||
| - | # | ||
| - | # 5.3 cambio de ficheros temporales a variables en memoria para procesamiento de URL | ||
| - | # 5.2 | ||
| - | # 5.1 añadida opción de ACTIVA_GUI, para desactivar si necesario las salidas por KDE | ||
| - | # 5.0 integración con KDE | ||
| - | # las contraseñas se guardan en fichero dentro del DIR_PASS | ||
| - | # 4.2 recuperación de contraseña | ||
| - | # versiones anteriores sin comentarios | ||
| - | |||
| - | # retales, mate, 03/10/2016 | ||
| - | # https:// | ||
| - | # http:// | ||
| - | # https:// | ||
| - | # https:// | ||
| - | |||
| - | # pruebas de conversación entre KDE y BASH | ||
| - | # kdialog --password " | ||
| - | |||
| - | # | ||
| - | # FUNCIONES | ||
| - | # | ||
| - | function aleatorio { | ||
| - | |||
| - | if [ " | ||
| - | NOMBRE=$(apg -a 0 -n 1 -q -MC -m 8); | ||
| - | fi | ||
| - | } | ||
| - | |||
| - | ACTIVA_GUI=1 # | ||
| - | SALIDA_BUCLE=0 # | ||
| - | CODIGO_SALIDA=0 # | ||
| - | PARAMETROS=$# | ||
| - | MOSTRAR_LOG=0 # | ||
| - | CODIGOS_ERROR=0 # | ||
| - | # y evitar que muestre el LOG si no es necesario | ||
| - | |||
| - | DIR_TORRENT="/ | ||
| - | SSH_KEY="/ | ||
| - | REMOTE_LOGIN=" | ||
| - | REMOTE_DIR_TORRENT="/ | ||
| - | DIR_PASS="/ | ||
| - | |||
| - | APP_NAME=" | ||
| - | |||
| - | |||
| - | |||
| - | export DISPLAY=: | ||
| - | |||
| - | while [ $SALIDA_BUCLE -eq 0 ] ; do | ||
| - | |||
| - | if [[ $PARAMETROS -ge 1 && ! -z " | ||
| - | |||
| - | URL=$1 | ||
| - | SALIDA_BUCLE=1 | ||
| - | ACTIVA_GUI=0 | ||
| - | MOSTRAR_LOG=1 | ||
| - | |||
| - | else | ||
| - | |||
| - | if [ $ACTIVA_GUI -eq 1 ]; then | ||
| - | sleep .3 | ||
| - | URL=$(kdialog --title " | ||
| - | else | ||
| - | read -p " | ||
| - | fi | ||
| - | |||
| - | if [ $? != 0 ]; then | ||
| - | echo " | ||
| - | exit | ||
| - | fi | ||
| - | |||
| - | fi | ||
| - | |||
| - | if [ " | ||
| - | # extrae el nombre del futuro archivo .torrent | ||
| - | NOMBRE=$(echo ${URL// | ||
| - | aleatorio # | ||
| - | |||
| - | wget -O / | ||
| - | |||
| - | # causística para tumerjortorrent.com | ||
| - | if [[ " | ||
| - | |||
| - | COUNTER_LOOP=3 | ||
| - | while [ $COUNTER_LOOP -ge 0 ]; do | ||
| - | case $COUNTER_LOOP in | ||
| - | 0) # v1 URL | ||
| - | # | ||
| - | URL_TMP=$(grep -o ' | ||
| - | [ -n " | ||
| - | ;; | ||
| - | 1) # v2 URL | ||
| - | # | ||
| - | URL_TMP=$(grep -o ' | ||
| - | ;; | ||
| - | 2) # v3 URL | ||
| - | # | ||
| - | URL_TMP=$(grep -o ' | ||
| - | [ -n " | ||
| - | ;; | ||
| - | 3) # v4 URL | ||
| - | URL_TMP=$(grep -o ' | ||
| - | ;; | ||
| - | esac | ||
| - | |||
| - | [ -z " | ||
| - | |||
| - | done | ||
| - | |||
| - | fi | ||
| - | |||
| - | # causística para newpct.com | ||
| - | if [[ " | ||
| - | |||
| - | # | ||
| - | URL_TMP=$(grep -o ' | ||
| - | |||
| - | fi | ||
| - | |||
| - | # causística para torrentlocura.com | ||
| - | if [[ " | ||
| - | |||
| - | URL_TMP=$(grep -o ' | ||
| - | [ -n " | ||
| - | fi | ||
| - | |||
| - | # causística para torrentrapid.com | ||
| - | if [[ " | ||
| - | |||
| - | URL_TMP=$(grep -o ' | ||
| - | [ -n " | ||
| - | fi | ||
| - | |||
| - | |||
| - | # procesa url | ||
| - | # | ||
| - | URL2=$URL_TMP | ||
| - | |||
| - | # descarga el torrent | ||
| - | wget $URL2 -O $DIR_TORRENT$NOMBRE.torrent | ||
| - | CODIGOS_ERROR_TEMP=$? | ||
| - | CODIGOS_ERROR=$[CODIGOS_ERROR+CODIGOS_ERROR_TEMP] | ||
| - | |||
| - | # subir el torrent al servidor de descargas | ||
| - | scp -i $SSH_KEY $DIR_TORRENT$NOMBRE.torrent $REMOTE_LOGIN: | ||
| - | CODIGOS_ERROR_TEMP=$? | ||
| - | CODIGOS_ERROR=$[CODIGOS_ERROR+CODIGOS_ERROR_TEMP] | ||
| - | |||
| - | |||
| - | # mira si tiene contraseña | ||
| - | if [[ " | ||
| - | grep -o '< | ||
| - | PASS=$(cat / | ||
| - | |||
| - | if [[ " | ||
| - | echo " | ||
| - | if [ $ACTIVA_GUI -eq 1 ]; then | ||
| - | kdialog --title " | ||
| - | fi | ||
| - | fi | ||
| - | if [[ " | ||
| - | echo " | ||
| - | if [ $ACTIVA_GUI -eq 1 ]; then | ||
| - | kdialog --title " | ||
| - | fi | ||
| - | touch " | ||
| - | fi | ||
| - | fi | ||
| - | |||
| - | unset NOMBRE | ||
| - | unset URL2 | ||
| - | unset PASS | ||
| - | unset CODIGOS_ERROR_TEMP | ||
| - | |||
| - | if [[ $ACTIVA_GUI -eq 1 || $MOSTRAR_LOG -eq 1 ]]; then | ||
| - | if [[ $CODIGOS_ERROR -ne 0 || $MOSTRAR_LOG -eq 1 ]]; then | ||
| - | kdialog --error "error subiendo .torrent" | ||
| - | kdialog --title " | ||
| - | else | ||
| - | kdialog --title " | ||
| - | fi | ||
| - | fi | ||
| - | |||
| - | CODIGOS_ERROR=0 | ||
| - | |||
| - | else | ||
| - | CODIGO_SALIDA=1 | ||
| - | if [ $ACTIVA_GUI -eq 1 ]; then | ||
| - | kdialog --title " | ||
| - | fi | ||
| - | fi | ||
| - | |||
| - | done | ||
| - | |||
| - | exit $CODIGO_SALIDA | ||
| - | </ | ||
| - | |||
| - | == 2 | ||
| - | == 3 | ||
| - | <code bash procesar.sh> | ||
| - | #!/bin/bash -x | ||
| - | |||
| - | # | ||
| - | # VARIABLES GLOBALES | ||
| - | # | ||
| - | DIR_ORIGEN="/ | ||
| - | DIR_DESTINO="/ | ||
| - | FICHERO_IGNORE=" | ||
| - | UNRAR="/ | ||
| - | ESRAR=" | ||
| - | |||
| - | # | ||
| - | # FUNCIONES | ||
| - | # | ||
| - | function mirarCarpeta() { | ||
| - | CARPETA=$1 | ||
| - | if [ ! -e " | ||
| - | mirarRARenCarpeta " | ||
| - | mirarFicherosCarpeta " | ||
| - | # else | ||
| - | # echo " | ||
| - | # echo " | ||
| - | fi | ||
| - | } | ||
| - | |||
| - | function mirarRARenCarpeta() { | ||
| - | # prueba a descomprimir un RAR (por si no lleva contraseña) | ||
| - | CARPETA=$1 | ||
| - | NOMBRE_CARPETA=${CARPETA## | ||
| - | |||
| - | for fichero in " | ||
| - | NOMBRE_FICHERO=${fichero## | ||
| - | EXTENSION=${NOMBRE_FICHERO## | ||
| - | |||
| - | if [ " | ||
| - | |||
| - | ESRAR=" | ||
| - | |||
| - | LLEVA_PASS=$($UNRAR l " | ||
| - | # mirar la lista de archivos, si aparece un * es que está encriptado | ||
| - | |||
| - | if [ " | ||
| - | # no lleva contraseña | ||
| - | |||
| - | $UNRAR e " | ||
| - | if [ " | ||
| - | rm " | ||
| - | rm " | ||
| - | rm " | ||
| - | fi | ||
| - | else | ||
| - | touch " | ||
| - | fi | ||
| - | fi | ||
| - | done | ||
| - | } | ||
| - | |||
| - | function mirarFicherosCarpeta { | ||
| - | CONTADOR=0 # | ||
| - | CARPETA=$1 | ||
| - | NOMBRE_CARPETA=${CARPETA## | ||
| - | |||
| - | # echo " | ||
| - | |||
| - | # se podría usar for fichero in " | ||
| - | # habría que mirar de ordenarlos antes de renombrarlos para que conserven el orden | ||
| - | # o igual dejarlos con el nombre original para hacerlo a mano | ||
| - | |||
| - | for fichero in " | ||
| - | NOMBRE_FICHERO=${fichero## | ||
| - | EXTENSION=${NOMBRE_FICHERO## | ||
| - | if [ " | ||
| - | ORIGEN=" | ||
| - | if [ $CONTADOR -eq 0 ]; then | ||
| - | DESTINO=" | ||
| - | else | ||
| - | DESTINO=" | ||
| - | fi | ||
| - | # echo -e " | ||
| - | # echo -e " | ||
| - | mv " | ||
| - | # | ||
| - | CONTADOR=$((CONTADOR + 1)) | ||
| - | fi | ||
| - | |||
| - | if [ " | ||
| - | rm " | ||
| - | fi | ||
| - | # echo " | ||
| - | done | ||
| - | |||
| - | # echo " | ||
| - | } | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | # | ||
| - | # MAIN | ||
| - | # | ||
| - | for carpeta in $DIR_ORIGEN/ | ||
| - | do | ||
| - | if [ -d " | ||
| - | ESRAR=" | ||
| - | mirarCarpeta " | ||
| - | # else | ||
| - | # echo "no directorio: $carpeta" | ||
| - | fi | ||
| - | done | ||
| - | |||
| - | # elimina las carpetas vacías | ||
| - | find " | ||
| - | </ | ||
| - | |||
| - | |||
| - | == OLD | ||
| - | <code bash procesa.sh> | ||
| - | #!/bin/bash | ||
| - | |||
| - | # | ||
| - | # VARIABLES GLOBALES | ||
| - | # | ||
| - | DIR_ORIGEN="/ | ||
| - | DIR_DESTINO="/ | ||
| - | FICHERO_IGNORE=" | ||
| - | |||
| - | # | ||
| - | # FUNCIONES | ||
| - | # | ||
| - | function mirarCarpeta() { | ||
| - | CARPETA=$1 | ||
| - | if [ ! -e " | ||
| - | mirarFicherosCarpeta " | ||
| - | else | ||
| - | echo " | ||
| - | echo " | ||
| - | fi | ||
| - | } | ||
| - | |||
| - | function mirarFicherosCarpeta { | ||
| - | CONTADOR=0 # | ||
| - | CARPETA=$1 | ||
| - | NOMBRE_CARPETA=${CARPETA## | ||
| - | |||
| - | echo " | ||
| - | |||
| - | # se podría usar for fichero in " | ||
| - | for fichero in " | ||
| - | NOMBRE_FICHERO=${fichero## | ||
| - | EXTENSION=${NOMBRE_FICHERO## | ||
| - | if [ " | ||
| - | ORIGEN=" | ||
| - | if [ $CONTADOR -eq 0 ]; then | ||
| - | DESTINO=" | ||
| - | else | ||
| - | DESTINO=" | ||
| - | fi | ||
| - | echo -e " | ||
| - | echo -e " | ||
| - | mv " | ||
| - | # | ||
| - | fi | ||
| - | CONTADOR=$((CONTADOR + 1)) | ||
| - | echo " | ||
| - | done | ||
| - | |||
| - | echo " | ||
| - | } | ||
| - | |||
| - | function borrarCarpetaVacia { | ||
| - | # esta función no se ejecuta | ||
| - | # no he encontrado una manera de comprobar si un directorio está vacío | ||
| - | # se utiliza un FIND al final del bucle de carpetas para eliminar las vacías | ||
| - | |||
| - | CARPETA=$1 | ||
| - | |||
| - | if [ -s " | ||
| - | echo " | ||
| - | else | ||
| - | echo "no existe o está vacío?" | ||
| - | fi | ||
| - | } | ||
| - | |||
| - | |||
| - | # | ||
| - | # MAIN | ||
| - | # | ||
| - | for carpeta in $DIR_ORIGEN/ | ||
| - | do | ||
| - | if [ -d " | ||
| - | mirarCarpeta " | ||
| - | else | ||
| - | echo "no directorio: $carpeta" | ||
| - | fi | ||
| - | done | ||
| - | |||
| - | # elimina las carpetas vacías | ||
| - | find " | ||
| - | </ | ||