giovedì, novembre 01, 2007

Youtube-DL: interfaccia grafica - aggiornamento

Ho rivisto il programma e utilizzando i consigli dell'amico Fradeve ho apportato delle modifiche che posso riassumere in:
  • Possibilità di scegliere un minor numero di info durante l'utilizzo del programma. Se l'avete usato già una volta e non volete che ci siano alcune finestre create da zenity potere rispondere si alla domanda che vi viene posta durante l'esecuzione del programma;
  • Possibilità di convertire il file anche in formati liberi quali ogg.
La guida di installazione è identica a quella precedente, l'unica cosa che cambia è il contenuto dello script.

Chi deve semplicemente aggiornare il programma segue la Guida 1, mentre chi deve installarlo per la prima volta segue la Guida 2.



Guida 1


Installazione

Aprite il file che avete creato la volta scorsa per la prima installazione
 sudo gedit /usr/bin/youtube 

Logicamente se non usate gedit potete usare qualsiasi altro editor di testo (nano,vim,kwrite,kate,mousepad, etc.)
Cancellate completamente tutto il contenuto e copiateci dentro quello che segue:

#!/bin/bash
# Funzione che configura il terminale da usare
function config {
cd ~/Desktop
msg=`zenity --title="XBackup" --list --text="Ridurre le notifiche e i messaggi di informazioni?" --radiolist --column="Scegli" --column="Abilita" false "Si" false "No"`
if [[ $msg = "Si" ]];
then
msg=1;
elif [[ $msg = "No" ]];
then
msg=0;
else
zenity --error --title="XBackup - Errore" --text="Nessuna scelta effettuata - Uscita inattesa"
exit 1;
fi

de=`zenity --title="Youtube-DL" --text="Quale DE utilizzate tra questi sottostanti?" --list --radiolist --column="Scegli" --column="Desktop Environment" false "Gnome" false "Kde" false "Xfce"`
if [[ $de = "Gnome" ]]
then
if [[ $msg -eq 0 ]]
then
zenity --info --title="Youtube-DL - Informazioni" --text="Ambiente Grafico Gnome"
else
sleep 1;
fi
terminal="gnome-terminal -x"
elif [[ $de = "Kde" ]];
then
if [[ $msg -eq 0 ]]
then
zenity --info --title="Youtube-DL - Informazioni" --text="Ambiente Grafico Kde"
else
sleep 1;
fi
terminal="konsole -e"
elif [[ $de = "Xfce" ]];
then
if [[ $msg -eq 0 ]]
then
zenity --info --title="Youtube-DL - Informazioni" --text="Ambiente Grafico Xfce"
else
sleep 1;
fi
terminal="xfce-terminal -x"
else
zenity --error --title="Youtube-DL - Errore" --text="Nessuna scelta effettuata - Uscita inattesa"
exit 1;
fi
}

# Funzione che permette di convertire i file flv nei formati richiesti
function trasform {
formato=`zenity --width=300 --height=300 --title="Youtube-DL" --list --radiolist --text="In quale formato deve essere trasformato il tuo video?" --column="Scegli" --column="Formati" false "3gp" false "Wmv" false "Mpeg" false "Avi" false "Ogg"`
zenity --info ---title="Youtube-DL - Informazioni" --text="Adesso verrà aperto un terminale che serve al programma per trasformare il file nel formato desiderato"
if [[ $formato = "3gp" ]]
then
$terminal ffmpeg -i tmp_file.flv -s 176x144 -r 15.0 -b 80k -vcodec h263 -ar 8000 -ac 1 -acodec amr_nb -y ${video_name}.3gp
if [[ $msg -eq 0 ]]
then
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.3gp creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Wmv" ]];
then
if [[ $msg -eq 0 ]]
then
$terminal ffmpeg -i tmp_file.flv ${video_name}.wmv
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.wmv creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Avi" ]];
then
$terminal ffmpeg -i tmp_file.flv ${video_name}.avi
if [[ $msg -eq 0 ]]
then
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.avi creato - Rilanciare il software per trasformarlo in un altro formato"
$terminal zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Mpeg" ]];
then
if [[ $msg -eq 0 ]]
then
ffmpeg -i tmp_file.flv ${video_name}.mpg
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.mpg creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Ogg" ]];
then
if [[ $msg -eq 0 ]]
then
ffmpeg -i tmp_file.flv ${video_name}.ogg
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.ogg creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
else
zenity --error --width=300 --title="Youtube-DL - Errore" --text="Nessuna scelta effettuata - Uscita inattesa"
exit 1;
fi
}


# MENU PRINCIPALE e cuore del programma
zenity --info --width=300 --title="Youtube-DL" --text "Programma per scaricare i video da YouTube e trasformarli vari formati"
config
find tmp_file.flv
if [[ $? -eq 0 ]];
then
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text "File già scaricato "
video_name=`zenity --entry --title="Youtube-DL" --text "Inserisci il nome che vuoi dargli (senza estensione)"`
else

video_url=`zenity --entry --title="Youtube-DL" --text "Inserisci l'url del video da YouTube"`
video_name=`zenity --entry --title="Youtube-DL" --text "Inserisci il nome che vuoi dargli (senza estensione)"`
zenity --info ---title="Youtube-DL - Informazioni" --text="Adesso verrà aperto un terminale che serve al programma per scaricare il file nel formato flv"
$terminal youtube-dl -o tmp_file.flv $video_url
fi
trasform
rm tmp_file.flv



Guida 2


Requisiti


I requisiti sono i seguenti pacchetti scaricabili dai repo:

  • youtube-dl

  • ffmpeg

  • zenity


i quali possono essere installati lanciando il comando
 sudo apt-get install youtube-dl ffmpeg  zenity 


Installazione


Anche in questo caso l'installazione si poggia con la creazione di un file o script di bash. In particolare creare un file dal nome youtube con il comando
 sudo gedit /usr/bin/youtube 

Logicamente se non usate gedit potete usare qualsiasi altro editor di testo (nano,vim,kwrite,kate,mousepad, etc.)
All'interno del file scriveteci dentro quello che segue:

#!/bin/bash
# Funzione che configura il terminale da usare
function config {
cd ~/Desktop
msg=`zenity --title="XBackup" --list --text="Ridurre le notifiche e i messaggi di informazioni?" --radiolist --column="Scegli" --column="Abilita" false "Si" false "No"`
if [[ $msg = "Si" ]];
then
msg=1;
elif [[ $msg = "No" ]];
then
msg=0;
else
zenity --error --title="XBackup - Errore" --text="Nessuna scelta effettuata - Uscita inattesa"
exit 1;
fi

de=`zenity --title="Youtube-DL" --text="Quale DE utilizzate tra questi sottostanti?" --list --radiolist --column="Scegli" --column="Desktop Environment" false "Gnome" false "Kde" false "Xfce"`
if [[ $de = "Gnome" ]]
then
if [[ $msg -eq 0 ]]
then
zenity --info --title="Youtube-DL - Informazioni" --text="Ambiente Grafico Gnome"
else
sleep 1;
fi
terminal="gnome-terminal -x"
elif [[ $de = "Kde" ]];
then
if [[ $msg -eq 0 ]]
then
zenity --info --title="Youtube-DL - Informazioni" --text="Ambiente Grafico Kde"
else
sleep 1;
fi
terminal="konsole -e"
elif [[ $de = "Xfce" ]];
then
if [[ $msg -eq 0 ]]
then
zenity --info --title="Youtube-DL - Informazioni" --text="Ambiente Grafico Xfce"
else
sleep 1;
fi
terminal="xfce-terminal -x"
else
zenity --error --title="Youtube-DL - Errore" --text="Nessuna scelta effettuata - Uscita inattesa"
exit 1;
fi
}

# Funzione che permette di convertire i file flv nei formati richiesti
function trasform {
formato=`zenity --width=300 --height=300 --title="Youtube-DL" --list --radiolist --text="In quale formato deve essere trasformato il tuo video?" --column="Scegli" --column="Formati" false "3gp" false "Wmv" false "Mpeg" false "Avi" false "Ogg"`
zenity --info ---title="Youtube-DL - Informazioni" --text="Adesso verrà aperto un terminale che serve al programma per trasformare il file nel formato desiderato"
if [[ $formato = "3gp" ]]
then
$terminal ffmpeg -i tmp_file.flv -s 176x144 -r 15.0 -b 80k -vcodec h263 -ar 8000 -ac 1 -acodec amr_nb -y ${video_name}.3gp
if [[ $msg -eq 0 ]]
then
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.3gp creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Wmv" ]];
then
if [[ $msg -eq 0 ]]
then
$terminal ffmpeg -i tmp_file.flv ${video_name}.wmv
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.wmv creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Avi" ]];
then
$terminal ffmpeg -i tmp_file.flv ${video_name}.avi
if [[ $msg -eq 0 ]]
then
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.avi creato - Rilanciare il software per trasformarlo in un altro formato"
$terminal zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Mpeg" ]];
then
if [[ $msg -eq 0 ]]
then
ffmpeg -i tmp_file.flv ${video_name}.mpg
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.mpg creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
elif [[ $formato = "Ogg" ]];
then
if [[ $msg -eq 0 ]]
then
ffmpeg -i tmp_file.flv ${video_name}.ogg
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="File ${video_name}.ogg creato - Rilanciare il software per trasformarlo in un altro formato"
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text="Grazie per aver usato il software"
else
sleep 1;
fi
else
zenity --error --width=300 --title="Youtube-DL - Errore" --text="Nessuna scelta effettuata - Uscita inattesa"
exit 1;
fi
}


# MENU PRINCIPALE e cuore del programma
zenity --info --width=300 --title="Youtube-DL" --text "Programma per scaricare i video da YouTube e trasformarli vari formati"
config
find tmp_file.flv
if [[ $? -eq 0 ]];
then
zenity --info --width=300 --title="Youtube-DL - Informazioni" --text "File già scaricato "
video_name=`zenity --entry --title="Youtube-DL" --text "Inserisci il nome che vuoi dargli (senza estensione)"`
else

video_url=`zenity --entry --title="Youtube-DL" --text "Inserisci l'url del video da YouTube"`
video_name=`zenity --entry --title="Youtube-DL" --text "Inserisci il nome che vuoi dargli (senza estensione)"`
zenity --info ---title="Youtube-DL - Informazioni" --text="Adesso verrà aperto un terminale che serve al programma per scaricare il file nel formato flv"
$terminal youtube-dl -o tmp_file.flv $video_url
fi
trasform
rm tmp_file.flv





Salvate il file e chiudetelo. Una volta fatto ciò dategli i diritti di esecuzione lanciando il comando:
 sudo chmod a+x /usr/bin/youtube 

Ora il programma può essere lanciato dove volete. Se volete potete anche (così ho fatto io) crea una icona con Menu Principale.


Alla prossima!!!

Aspetto altri vostri consigli

Continua a leggere!