Discussione: registrare in mp3?
View Single Post
Old 20-11-2011, 14:43   #16
Gimli[2BV!2B]
Senior Member
 
L'Avatar di Gimli[2BV!2B]
 
Iscritto dal: Feb 2006
Città: Parma
Messaggi: 3008
Codice:
#!/bin/bash

#Script per il recupero dei file *.ra della trasmissione radiofonica "Alle otto della sera"
#Organizzazione dati sui server:
# - Indice generale
# - Indici serie: ogni indice di serie contiene link a file *.ram, uno per puntata
# - File *.ram: contengono praticamente solo del testo, cioè il link allo stream .*ra
#
# Versione 1.1 (18/10/2009) Alcuni stream sono di tipo pnm, mplayer non li può usare
#                           Basta riscrivere l'indirizzo in rstp://...
# Versione 2   (18/10/2009) Recupero contenuti accessori: html, immagine, altri file...
# Versione 2.1 (20/10/2009) Meno file *ram da scaricare in caso di download terminato
#                           File html migliorati
# Versione 3   (15/05/2010) Nuovo sito RAI; le nuove pagine dovrebbero rimanere stabili
#                           per qualche tempo dopo la grande migrazione a SilverLight...
# Versione 3.1 (09/06/2010) RealMedia Analyzer
#                           Nome stream o nome file?
#                           Riscrittura dei messaggi di output durante l'esecuzione
#                           Trap Ctrl C per pulire in uscita
#                           MPlayer non da errore in caso di Ctrl C, test output
# Versione 3.2 (21/08/2011) Maggiore efficienza riavviando lo script
#                           Vari controlli errori
# Versione 3.3 (19/11/2011) Argomento obbligatorio: all, list oppure lista codici serie
#                           Vari controlli errori
# Versione 4.0 (20/11/2011) Recupero di alcune serie legacy inaccessibili
#                           Riscrittura spezzando la procedura in funzioni più leggibili
# Versione 4.1 (20/11/2011) Gestione corretta delle 3 serie con codice "mestiere_artista"

if [ $# -eq "0" ]    # Nessun argomento?
then
  echo "Utilizzo:"
  echo "	`basename $0` all          -> Scarica tutte le serie"
  echo "	`basename $0` list         -> Elenca le serie disponibili ed esce"
  echo "	`basename $0` [codice_serie] [codice_serie] -> Scarica la/le serie selezionata/e"
  exit 0
fi

export ALL=1
export LIST=0
declare -a SERIES_SELECTED
declare -a SERIES_LEGACY_TITLE
declare -a SERIES_LEGACY_CODE

#Puntate non elencate nel nuovo sito RAI
SERIES_LEGACY_TITLE+=("Chung Kuo-Cina, l'Impero di Mezzo")
SERIES_LEGACY_CODE+=("chungkuo")
SERIES_LEGACY_TITLE+=("Il Globo, la mappa, il Mondo")
SERIES_LEGACY_CODE+=("globo")
SERIES_LEGACY_TITLE+=("Il mestiere dell'artista. L'Ottocento")
SERIES_LEGACY_CODE+=("ilmestieredellartista800")
SERIES_LEGACY_TITLE+=("Sex and the Polis")
SERIES_LEGACY_CODE+=("sexandthepolis")

#Completamente inaccessibile nel nuovo sito RAI
SERIES_LEGACY_TITLE+=("Le porte dei sogni")
SERIES_LEGACY_CODE+=("portedeisogni")

#Il codice utilizzato non è univoco.
ARTISTI_CODE+=("mestiere_artista1")
ARTISTI_TEXT+=("Strinati preferisce raccontare quelle vicende attraverso le testimonianze dei contemporanei")
ARTISTI_CODE+=("mestiere_artista2")
ARTISTI_TEXT+=("vivo per secoli e ancora adesso influenza il nostro modo di porci di fronte")

#Non so dove sia, i link sono rotti e non esite una pagina legacy
#SERIES_LEGACY_TITLE+=("Il divano di Istanbul")
#SERIES_LEGACY_CODE+=("ildivanodiistanbul")"

NO_RMA=0

DELIM=""
for option in "$@"; do
  case "$option" in
    all)  ALL=1;;
    list) export LIST=1; export ALL=0;;
    --no-rma) export NO_RMA=1;;
    *)    export ALL=0; SERIES_SELECTED+=("$option");;
  esac
done

function IsSerieSelected()
{
  if [ -z "$1" ]; then
    return 1
  fi

  if [[ $LIST -eq 1 ]]; then
    return 0
  fi

  if [[ $ALL -eq 1 ]] && [[ ${#SERIES_SELECTED[@]} -eq 0 ]]; then
    return 0
  fi

  for serie in ${SERIES_SELECTED[@]}; do
    if [ "$serie" == "$1" ]; then
      return 0
    fi
  done

  return 1
}

function RemoveSelected()
{
  IDX=0
  for serie in ${SERIES_SELECTED[@]}; do
    if [[ "$serie" == "$1" ]]; then
      unset SERIES_SELECTED[IDX]
    fi
    ((IDX++))
  done
}

function CheckRemainingSelected()
{
  if [[ $ALL -eq 0 ]] && [[ ${#SERIES_SELECTED[@]} -eq 0 ]]; then
    return 1
  fi

  return 0
}

function GetCodeFromTitle()
{
  if [[ -z "$1" ]]; then
    return 1
  fi

  for (( i = 0 ; i < ${#SERIES_LEGACY_TITLE[*]} ; i++ )); do
    if [[ "${SERIES_LEGACY_TITLE[$i]}" =~ "$1" ]] || [[ "$1" =~ "${SERIES_LEGACY_TITLE[$i]}" ]]; then
      echo ${SERIES_LEGACY_CODE[$i]}
      return 0
    fi
  done

  return 1
}

function GetCodeFromText()
{
  if [[ ! -z "$1" ]] && [[ -f "$1" ]]; then
    for (( i = 0 ; i < ${#ARTISTI_TEXT[*]} ; i++ )); do
      RESULT_GREP=$(grep -c "${ARTISTI_TEXT[$i]}" "$1");
      if [[ $RESULT_GREP -gt 0 ]]; then
        echo "${ARTISTI_CODE[$i]}"
        break ;
      fi
    done
  fi
}

function GetDirectLink()
{
  REDIRECT=$(wget -q -O - "http://www.rai.it/$1") ;
  if [[ "$?" -ne 0 ]]; then
    echo -ne "\nwget redirect failed!\n";
    exit 1;
  fi
  echo -ne "http://www.rai.it/" ;
  echo $REDIRECT | sed \
    -e "s;.*document.location[[:space:]]*=[[:space:]]*';;" \
    -e "s/'[[:space:]]*;.*//" ;
  unset REDIRECT ;
}

function DownloadIndexSerie()
{
  #creo cartelle di lavoro numerate, una per serie
  if [[ ! -d "serie$1" ]]; then
    mkdir "serie$1" ;
  fi

  SUFFIX="" ;
  if [[ $3 -eq 0 ]]; then
    LINK_DIRECT=$(GetDirectLink "$2") ;
  else
    LINK_DIRECT="$2" ;
    SUFFIX="_legacy" ;
  fi

  if [[ ! -f  "serie$1/index$SUFFIX.htm" ]]; then
    wget -q -O - "$LINK_DIRECT" > "serie$1/index$SUFFIX.htm"
    if [[ "$?" -ne 0 ]]; then
      rm "serie$1/index$SUFFIX.htm" ;
      unset LINK_DIRECT ;
      return 1 ;
    fi
    unset LINK_DIRECT ;
  fi
  return 0 ;
}

function GetHTMLtitle()
{
  export TITLE_HTML=$(sed \
    -e '/<div class="Titolo">/!d' \
    -e 's/^[[:space:]]*<div class="Titolo">//' \
    -e 's\</div>[[:space:]]*\\' "$1") ;

  TITLE=$(perl -MHTML::Entities -e 'print decode_entities($ENV{'TITLE_HTML'});') ;
  unset -v TITLE_HTML ;
  echo "$TITLE" ;
}

function GetSeries()
{
  sed \
    -e '/<a href="\/dl\/Radio2\/sito\/item\/ContentItem-[A-Za-z0-9-]\{36\}.html">segue...<\/a>/!d' \
    -e 's;^<a href=";;' -e 's;".*$;;' "$1" ;
}

function GetEpisodes()
{
  sed \
    -e '/^<a onclick="return[[:space:]]*openAudioPopup(.ContentItem-[A-Za-z0-9-]\{36\}.)[[:space:]]*;"[[:space:]]*href="/!d' \
    -e 's/^<a onclick="return[[:space:]]*openAudioPopup(.ContentItem-[A-Za-z0-9-]\{36\}.)[[:space:]]*;"[[:space:]]*href="//' \
    -e 's/.html">[^\n^$]*<\/a>/.html/' "$1" ;
}

function GetRAM()
{
  sed \
    -e '/<embed [Cc][Oo][Nn][Ss][Oo][Ll][Ee]="[[:alpha:]]*" [Nn][Oo][Ll][Oo][Gg][Oo]="[[:alpha:]]*" [Aa][Uu][Tt][Oo][Ss][Tt][Aa][Rr][Tt]="[[:alpha:]]*" [Cc][Ee][Nn][Tt][Ee][Rr]="[[:alpha:]]*" [Cc][Oo][Nn][Tt][Rr][Oo][Ll][Ss]="[[:alpha:]]*" src="http:\/\/www.rai.it\/dl\/audio\/[^\n^$]*.ram"/!d' \
    -e 's/<embed [Cc][Oo][Nn][Ss][Oo][Ll][Ee]="[[:alpha:]]*" [Nn][Oo][Ll][Oo][Gg][Oo]="[[:alpha:]]*" [Aa][Uu][Tt][Oo][Ss][Tt][Aa][Rr][Tt]="[[:alpha:]]*" [Cc][Ee][Nn][Tt][Ee][Rr]="[[:alpha:]]*" [Cc][Oo][Nn][Tt][Rr][Oo][Ll][Ss]="[[:alpha:]]*" src="//' \
    -e 's/.ram".*$/.ram/' "$1" ;
}

function GetStream()
{
  STREAM=$(wget -q -O - "$1") ;
  if [[ "$?" -ne 0 ]]; then
    return 1 ;
  fi
  #pulizia necessaria...
  STREAM=$(echo $STREAM | sed -e 's/.*rtsp:\/\/*/rtsp:\/\//' -e 's/.ra[^[:print:]]*$/.ra/') ;
  #alcuni sono rappresentati come stream pnm -> li forzo ad rtsp
  echo $(echo $STREAM | sed -e 's/.*pnm:\/\/*/rtsp:\/\//') ;
  unset STREAM ;
}

function DownloadStream()
{
  if [[ ! -f "../$1/$2" ]]; then
    #se il file non esiste procedo con il download
    printf "\n%s" "In download: $2 = $3" ;
    OUTPUT=$(mplayer -noconsolecontrols -nojoystick -nolirc -quiet -prefer-ipv4 -noframedrop -dumpfile \
      ../$1/$2 -dumpstream $3 2>&1) ;

    if [[ "$?" -ne 0 ]] || [[ -z $(echo $OUTPUT | grep "Stream EOF detected") ]]; then
      echo -ne "\nMPlayer failed!\n" ;
      rm "../$1/$2" ;
      return 1 ;
    fi
    if [[ EXIT_AS_SOON_AS_POSS -eq 1 ]]; then
      return 3 ;
    fi
  else
    #il file esiste già.
    #Due casi possibili:
    # - è già stato scaricato in un'esecuzione precedente
    # - è stato solamente iniziato, è sfuggito alle trap ed è incompleto...
    # QUESTO SCRIPT NON SI ACCORGE DI EVENTUALI FILE INCOMPLETI E NON LI SCARICA PIU'
    # Tenta di intercettare il termine dell'esecuzione dello script rimuovendo eventuali
    # file incompleti (ma se, per esempio, manca la corrente...)
    printf "\n%s" "Già scaricato: $1/$2 = $3" ;
  fi
  return 0 ;
}

function ProcessStandard()
{
  # 1 -> $EPISODES
  # 2 -> $NR_INDEX
  NR_EPISODE=1 ;

  for episode in $1; do
    if [[ ! -f  "serie$2/$NR_EPISODE.htm" ]]; then
      wget -q -O - "$episode" > "serie$2/$NR_EPISODE.htm"
      if [[ "$?" -ne 0 ]]; then
        echo -ne "\nwget episode failed!\n" ;
        rm "serie$2/$NR_EPISODE.htm" ;
        return 1 ;
      fi
    fi

    #estraggo il link al file *.ram
    RAM=$(GetRAM "serie$2/$NR_EPISODE.htm")

    if [[ -z $RAM ]]; then
      if [[ $LIST -eq 0 ]]; then
        echo -ne "\n\"$TEMP_FOLDER/serie$2/$NR_EPISODE.htm -> Non esiste un riferimento corretto al file audio\n" ;
        echo -ne "Potrebbe trattarsi di un'errore nella pagina HTML o un tag <embed> dalla sintassi inaspettata\n" ;
      fi
      ((NR_EPISODE++)) ;
      continue ;
    fi

    ProcessStream "$RAM" "$2" 0 ;
    case $? in
      1) return 1 ;;
      2) return 2 ;;
      3) return 3 ;;
      *) ;;
    esac

    ((NR_EPISODE++)) ;
  done
  return 0 ;
}

function ProcessLegacy()
{
  #recupero indici serie
  SUFFIX="_legacy" ;
  if ( ! DownloadIndexSerie "$NR_INDEX" "$1" 1 ); then
    if [[ $LIST -eq 0 ]]; then
      echo -ne "\nwget index $NR_INDEX failed!\n";
    fi
    return 1 ;
  fi

  if [[ ! -f "serie$2/index$SUFFIX.htm" ]]; then
    return 1 ;
  fi

  RAMS=$(sed \
    -e '/Q_CANALE=http:\/\/www.radio.rai.it\/\/radio2\/alleotto\//!d'\
    -e 's/.*Q_CANALE=[^h]*//'\
    -e 's/.ram.,.*$/.ram/' "serie$2/index$SUFFIX.htm" | uniq | sort) ;

  for ram in $RAMS; do
    ProcessStream "$ram" "$2" 1 ;
    case $? in
      1) return 1 ;;
      2) return 2 ;;
      3) return 3 ;;
      *) ;;
    esac
  done
  return 0 ;
}

function ProcessStream()
{
  # 1 -> $ram
  # 2 -> $NR_INDEX
  # 3 -> $FLAG_LEGACY
  #recupero l'indirizzo dello stream *.ra
  STREAM=$(GetStream "$1") ;

  #suddivido i file per serie: estraggo i nomi necessari
  FILE_NAME=$(echo $1 | sed 's/.*\///' | sed 's/m$//') ;
  STREAM_NAME=$(echo $STREAM | sed -e 's/.*\///') ;
  if [[ ${#FILE_NAME} -le ${#STREAM_NAME} ]]; then
    FILE_NAME="$STREAM_NAME" ;
  fi
  SERIE_NAME_PREV="$SERIE_NAME" ;
  export SERIE_NAME=$(echo $STREAM | sed -e 's/\/[^\/]*$//' -e 's/.*\///') ;

  if [[ "$SERIE_NAME" == "mestiere_artista" ]]; then
    SERIE_NAME_TMP=$(GetCodeFromText "serie$2/index.htm") ;
    if [[ ! -z "$SERIE_NAME_TMP" ]]; then
      SERIE_NAME="$SERIE_NAME_TMP" ;
    fi
  fi

  if [[ ! -z $SERIE_NAME_PREV ]] && [[ "$SERIE_NAME_PREV" != "$SERIE_NAME" ]]; then
    if [[ "$SERIE_NAME" =~ "$SERIE_NAME_PREV" ]] || [[ "$SERIE_NAME_PREV" =~ "$SERIE_NAME" ]]; then
      export SERIE_NAME="$SERIE_NAME_PREV";
    fi
  fi

  if [[ -f "../$SERIE_NAME/$FILE_FLAG_DONE" ]]; then
    return 1
  fi

  if ( ! IsSerieSelected "$SERIE_NAME" ); then
    return 1
  fi

  if [[ -z $SERIE_NAME_PREV ]] || [[ "$SERIE_NAME_PREV" != "$SERIE_NAME" ]]; then
    if [[ $LIST -eq 1 ]]; then
#      echo "[*][b]Codice[/b]: $SERIE_NAME" ;
#      echo "[b]Titolo[/b]: [url=http://www.rai.it/$serie]\"$TITLE\"[/url]" ;
      echo "Codice: $SERIE_NAME" ;
      echo "Titolo: \"$TITLE\"" ;
      echo -ne "URL: http://www.rai.it/$serie\n\n" ;
      return 2
    fi

    #creazione cartelle serie
    if [[ ! -d "../$SERIE_NAME" ]]; then
      mkdir "../$SERIE_NAME"
      printf "\n\n%s" "Inizio download serie \"$SERIE_NAME\"" ;
    else
      printf "\n\n%s" "Proseguo download serie \"$SERIE_NAME\"" ;
    fi
  fi

  if [[ $LIST -eq 1 ]]; then
    return 2
  fi

  #creazione indice html
  CreateHTMLindex "$SERIE_NAME" "$2" "$3" ;

  if [[ -n $STREAM_NAME ]] && [[ -f "../$SERIE_NAME/$STREAM_NAME" ]] && [[ "${STREAM_NAME}" != "${FILE_NAME}"  ]]; then
    mv "../$SERIE_NAME/$STREAM_NAME" "../$SERIE_NAME/$FILE_NAME"
  fi

  if ( ! DownloadStream "$SERIE_NAME" "$FILE_NAME" "$STREAM" ); then
    export SERIE_DONE=0;
  else
    if [[ EXIT_AS_SOON_AS_POSS -eq 1 ]]; then
      if [[ -f "../$SERIE_NAME/$FILE_NAME" ]]; then
        rm "../$SERIE_NAME/$FILE_NAME" ;
      fi
      return 3 ;
    fi
    ProcessRMA "$SERIE_NAME/$FILE_NAME" ;
  fi

  if [[ EXIT_AS_SOON_AS_POSS -eq 1 ]]; then
    return 3 ;
  fi

  return 0 ;
}

#Viene creata una paginetta html con la descrizione di ogni serie
#testata html
function GetHead()
{
  echo -ne "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" ;
  echo -ne "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" ;
  echo -ne "<html>\n<head>\n" ;
  echo -ne "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\"/>\n" ;
  echo -ne "<title>RADIO DUE - Alle 8 della sera - $1</title>\n" ;
  echo -ne "<style TYPE=\"text/css\">\n<!--\n\n" ;
}

#qui in mezzo includo le stile da css

#fine testata
HEAD_CLOSE="\n\n"
HEAD_CLOSE="$HEAD_CLOSE-->\n"
HEAD_CLOSE="$HEAD_CLOSE</style>\n</head>\n<body>\n"

#coda html
TAIL="</body>\n</html>"

function GetHTMLcontent()
{
  sed \
    -n -e '/ id=\"SitoBody\">/,/<div class=\"Bot\"><\/div>/p'\
    -e 's/<div class=\"Bot\"><\/div>/<div class=\"Bot\"><\/div><\/div>/' "$1" ;
}

function GetHTMLcontentLegacy()
{
  sed \
    -n -e '/<span class=\"solotesto\"> Alle otto della sera <\/span><\/div>/,/<div class=\"schede_interne_\(contenuti\|riascolta_a4\)\">/p' \
    -e '/<div class=\"schede_interne_\(contenuti\|riascolta_a4\)\">/d' "$1" ;
}

function CreateHTMLindex()
{
  if [[ -f "../$1/$1.html" ]]; then
    return 0
  fi

  LEGACY=$3 ;
  if [ "$1" != "portedeisogni" ]; then
    LEGACY=0 ;
  fi

  echo -e "\nCreazione indice html: $1/$1.html" ;
  GetHead "$TITLE" > "../$1/$1.html" ;
  cat style.css >> "../$1/$1.html" ;
  echo -e $HEAD_CLOSE >> "../$1/$1.html" ;
  SUFFIX="" ;
  if [[ $LEGACY -eq 0 ]]; then
    GetHTMLcontent "serie$2/index.htm" >> "../$1/$1.html"
  else
    SUFFIX="_legacy" ;
    GetHTMLcontentLegacy "serie$2/index$SUFFIX.htm" >> "../$1/$1.html"
  fi
  echo -e $TAIL >> "../$1/$1.html" ;

  #recupero eventuale immagine
  IMAGE=$(sed -e '/<img src=\"/!d' -e 's/.*<img src=\"//' -e 's/\"[[:space:]]*[[:alpha:]]*=\".*$//' "../$1/$1.html") ;
  if [[ ! -z $IMAGE ]]; then
    IMAGE_NAME=`echo $IMAGE | sed -e 's/.*\///'`
    echo "L'indice contiene un'immagine -> $1/contenuti/$IMAGE_NAME"
    if [[ ! -d "../$1/contenuti" ]]; then
      mkdir "../$1/contenuti"
    fi

    if [[ ! -f "../$1/contenuti/$IMAGE_NAME" ]]; then
      if [[ $LEGACY -eq 0 ]]; then
        wget -q -O - "$IMAGE" > "../$1/contenuti/$IMAGE_NAME" ;
      else
        wget -q -O - "http://www.radio.rai.it$IMAGE" > "../$1/contenuti/$IMAGE_NAME" ;
      fi
      if [[ "$?" -ne 0 ]]; then echo -ne "\nwget image failed!\n"; rm "../$1/contenuti/$IMAGE_NAME"; fi
    fi

    #riscritture indirizzo immagine: da remota a locale
    LOCAL_NAME="contenuti/$IMAGE_NAME"
    sed -i 's;'$IMAGE';'$LOCAL_NAME';g' "../$1/$1.html"
  fi

  #alcune serie hanno anche dei contenuti aggiuntivi: li recupero
  LINKS=$(sed -e '/<a href=\"/!d' -e 's/<a href=\"/\n/g' ../$1/$1.html | sed -e '/http:/!d' -e 's/\">.*$//') ;
  if [[ ! -z $LINKS ]]; then
    if [[ ! -d "../$1/contenuti" ]]; then
      mkdir "../$1/contenuti" ;
    fi

    for link in $LINKS; do
      FILE_NAME=`echo $link | sed -e 's/.*\///'`
      if [[ ! -f  "../$1/contenuti/$FILE_NAME" ]]; then
        echo "Contenuto aggiuntivo -> $1/contenuti/$FILE_NAME" ;
        wget -q -O - "$link" > "../$1/contenuti/$FILE_NAME" ;
        if [[ "$?" -ne 0 ]]; then echo -ne "\nwget file failed!\n"; rm "../$1/contenuti/$FILE_NAME"; fi
      fi

      #riscrittura indirizzo contenuto
      LOCAL_NAME="contenuti/$FILE_NAME" ;
      sed -i 's*'$link'*'$LOCAL_NAME'*g' "../$1/$1.html" ;
    done
  fi
}

function ProcessRMA()
{
  if [[ $NO_RMA -eq 0 ]] && [[ ! "$RMA" ]]; then
    return 0 ;
  fi

  PROCESSED=`$RMA -d "../$1" | grep "This file has been processed by RealMedia Analyzer"`
  if [[ -f "../$1" ]] && [[ -z $PROCESSED ]]; then
    if $RMA -ft "../$1" >/dev/null 2>&1 ; then
      echo -n "." ;
    else
      echo -ne "\n*rma -ft warning*" ;
      touch "../$1-rma_ft_WARNING" ;
    fi
    if $RMA -i "../$1" >/dev/null 2>&1 ; then
      echo -n "." ;
    else
      echo -ne "\n*rma -i warning*" ;
      touch "../$1-rma_i_WARNING" ;
    fi
  fi
  unset PROCESSED ;
}

# trap keyboard interrupt (control-c)
trap control_c SIGINT
# trap standart sigterm
trap control_c SIGTERM
EXIT_AS_SOON_AS_POSS=0

# file that flags a folder as completely downloaded
FILE_FLAG_DONE=".done"

control_c()
{
  printf "\n\n%s\n\n" "*** Richiesta uscita script: attendere, prego... ***"
  EXIT_AS_SOON_AS_POSS=1
}

#cartella di lavoro
TEMP_FOLDER="alle8dellasera_TMP"
if [[ ! -d "$TEMP_FOLDER" ]]; then
  printf "%s\n%s\n\n%s\n%s\n\n" \
       "Benvenuto in \"Alle otto della sera\" downloader." \
       "Prima esecuzione dello script: creo la certella temporanea \"$TEMP_FOLDER\"" \
       "  ***    Potrai eliminare questa cartella al termine    ***" \
       "  *** del download di tutte le serie che ti interessano ***"
fi

mkdir -p "$TEMP_FOLDER"
cd "$TEMP_FOLDER"

#RealMedia analyzer
RMA="./rma"

if [[ $LIST -eq 0 ]] && [[ $NO_RMA -eq 0 ]] && [[ ! -f "$RMA" ]]; then
  RMA_FULL_NAME="rma-0.30.00-linux-i386"
  printf "\n%s\n%s\n" "Sto scaricando una utilità per riparare gli stream: RealMedia Analyzer ($RMA_FULL_NAME)" \
                      "Eseguire lo script con argomento --no-rma per saltare questo passaggio."
  if [[ ! -f "$RMA_FULL_NAME.gz" ]]; then
    wget -q "http://users.i.com.ua/~alexeysp/rma/$RMA_FULL_NAME.gz"
    if [[ "$?" -ne 0 ]]; then echo -ne "\nwget RMA failed!\n"; rm "$RMA_FULL_NAME.gz" ; fi
  fi
  gzip -qdc "$RMA_FULL_NAME.gz" > "$RMA"
  chmod +x "$RMA"
fi

if [[ ! -f "style.css" ]]; then
  wget -q -O - "http://www.rai.tv/dl/Radio2/css/Radio2.css" > style.css
  if [[ "$?" -ne 0 ]]; then echo -ne "\nwget css failed!\n"; rm style.css ; exit 1; fi
fi

INDEX_ALLEOTTO="alleottodellasera.html"

#recupero indice generale
if [[ ! -f "$INDEX_ALLEOTTO" ]]; then
  wget -q -O - "http://www.rai.it/dl/Radio2/alleottodellasera.html" > $INDEX_ALLEOTTO
  if [[ "$?" -ne 0 ]]; then echo -ne "\nwget global index failed!\n"; rm $INDEX_ALLEOTTO; exit 1; fi
fi

#estraggo i link alle serie di puntate
SERIES=$(GetSeries "$INDEX_ALLEOTTO") ;

SERIE_DONE=0

NR_INDEX=1
LEPORTEDEISOGNI=0
for serie in $SERIES; do
  if [[ EXIT_AS_SOON_AS_POSS -eq 1 ]]; then
    exit 0 ;
  fi

  #recupero indici serie
  if ( ! DownloadIndexSerie "$NR_INDEX" "$serie" 0 ); then
    if [[ $LIST -eq 0 ]]; then
      echo -ne "\nwget index $NR_INDEX failed!\n" ;
    fi
    if [[ $NR_INDEX -ne 74 ]]; then
      ((NR_INDEX++))
      continue
    else
      touch "serie$NR_INDEX/index.htm" ;
      LEPORTEDEISOGNI=1
    fi
  fi

  if [[ ! -f "serie$NR_INDEX/index.htm" ]] && [[ $NR_INDEX -ne 74 ]]; then
    exit 0 ;
  fi

  EPISODES=$(GetEpisodes "serie$NR_INDEX/index.htm") ;
  TITLE=$(GetHTMLtitle "serie$NR_INDEX/index.htm") ;
  LEGACY=0 ; #flag modalità legacy
  LEGACY_URL="" ;

  if [[ $LEPORTEDEISOGNI -eq 1 ]]; then
    TITLE="Le porte dei sogni" ;
    LEGACY=1 ;
  fi

  if [[ -z $EPISODES ]]; then
    #Alcune serie non sono state migrate completamente al nuovo sito RAI, gli unici link
    #alle puntate sono ancora presenti nelle vecchie pagine che potrebbero finire offline
    #in qualsiasi momento...
    CODE=$(GetCodeFromTitle "$TITLE") ;
    if [[ ! -z $CODE ]]; then
      LEGACY_URL="http://www.radio.rai.it/radio2/alleotto/$CODE/" ;
    fi

    if [[ ! -z $LEGACY_URL ]]; then
      LEGACY=1 ;
    fi
    if [[ $LEGACY -eq 0 ]]; then
      ((NR_INDEX++))
      continue ;
    fi
  fi

  #questa flag viene portata a zero se un download di mplayer fallisce
  #in questo caso non viene creato il file FILE_FLAG_DONE, che marca una cartella come terminata
  export SERIE_DONE=1
  export SERIE_NAME="" ;
  if [[ $LEGACY -eq 0 ]]; then
    ProcessStandard "$EPISODES" "$NR_INDEX" ;
  else
    ProcessLegacy "$LEGACY_URL" "$NR_INDEX" ;
  fi

  if [[ $? -eq 3 ]]; then
    exit 0 ;
  fi

  ((NR_INDEX++))

  if ( ! IsSerieSelected "$SERIE_NAME" ); then
    continue
  fi
  RemoveSelected "$SERIE_NAME"

  if [[ $LIST -eq 1 ]]; then
    continue
  fi

  if [[ SERIE_DONE -eq 1 ]] && [[ ! -z $SERIE_NAME ]] && [[ ! -z $FILE_FLAG_DONE ]] && [[ ! -f "../$SERIE_NAME/$FILE_FLAG_DONE" ]]; then
    echo -ne "\n\"$SERIE_NAME\" terminata!\n"
    touch "../$SERIE_NAME/$FILE_FLAG_DONE"
  elif [[ -f "../$SERIE_NAME/$FILE_FLAG_DONE" ]]; then
    echo -ne "\n\"$SERIE_NAME\" marcata come terminata (file \"$SERIE_NAME/$FILE_FLAG_DONE\")."
  fi

  if ( ! CheckRemainingSelected ); then
    exit 0
  fi
done
#gimli
__________________
~Breve riferimento ai comandi GNU/Linux (ormai non molto breve...)

Ultima modifica di Gimli[2BV!2B] : 20-11-2011 alle 15:45. Motivo: noparse bbcode e piccoli dettagli stilistici
Gimli[2BV!2B] è offline   Rispondi citando il messaggio o parte di esso