YouTubeDownloader

De ULBwiki

Baixa vídeo do YouTube para o diretório de onde o script é executado. O vídeo é baixado a partir do link exibido no site.

###################################################################
# Nautilus' script para baixar vídeos do YouTube através da URL do vídeo
# Autor: Luiz 31/08/2007
# Referências: http://www.vivaolinux.com.br/scripts/verScript.php?codigo=2928
# http://jetervaz.wordpress.com/2007/07/26/wget-zenity-progress/
###################################################################
 
#!/bin/sh
 
function progress
{
file=$1
[ -f $file ] || { echo "Arquivo $file nao encontrado!";
  exit
}
dwnld_file=`cat $file | grep '=>' | tail -n1 | cut -d '>' -f2`
info_file=`cat $file | grep 'Tamanho'`
 
while true;
do
  step=`tail -n2 $file | grep % | rev | sed 's/.*%//' | cut -c -2 | rev`
  echo $step;
 
  cat $file | grep '100%' | sed 's/[^100]//g';
 
  sleep 0.5;
 
done |zenity --title "Download" --text "Baixando arquivo$dwnld_file...\n`echo $(cat \
$file | grep 'Tamanho')`" --progress --auto-close
 
if [ $? -eq 1 ]; then
  kill -9 $pid
  rm $movie_file.flv wget-log
  zenity --title "Informação" --text "Download cancelado." --info
  exit
fi
} 
 
url=`zenity --title "URL do vídeo" --entry --text "Cole a url do vídeo."`
 
if [ $? -eq 1 ]; then
  exit
  elif [ -z $url ]
    then
      zenity --error --text "Nome do arquivo Está vazio."
      exit
  fi
 
movie_file=`zenity --title "Selecionar nome do filme" --entry --text "Digite o nome do filme a ser criado sem extensão."`
if [ $? -eq 1 ]; then
  exit
elif [ -z $movie_file ]
  then
    zenity --error --text "Nome do arquivo Está vazio."
    exit
fi
 
rm wget-log
wget -O /tmp/tmp_yt "$url"
 
if [ $? -eq 1 ]; then
  zenity --error --text "Erro ao baixar arquivo. Verifique sua conexão e o endereço do vídeo."
  exit
fi
 
info=`cat /tmp/tmp_yt | grep -oE 'video_id=.*&t=[^\"&]*' | head -1`
rm /tmp/tmp_yt
 
pid=`wget -bO $movie_file.flv "http://www.youtube.com/get_video?$info" \
| grep -e 'background' -e 'pid'| awk '{print $5}'|rev|cut -c 2-|rev`
 
sleep 4
progress "wget-log"
zenity --info --title "Download completado!" --text "Arquivo $movie_file.flv baixado com sucesso!"
 
rm wget-log

--Luiz 02:22, 2 Maio 2008 (EDT)

Ferramentas pessoais
Criar página