Skip to content

Instantly share code, notes, and snippets.

@PandaFoss
Created July 18, 2019 01:29
Show Gist options
  • Save PandaFoss/ebd6ea57d580ff92d383a2ecdaa879e1 to your computer and use it in GitHub Desktop.
Save PandaFoss/ebd6ea57d580ff92d383a2ecdaa879e1 to your computer and use it in GitHub Desktop.
Script para descargar música desde YouTube
#!/bin/bash
# Dependencies: youtube-dl, zenity
# Author: Max Ferrer (https://github.com/PandaFoss)
function youtube_link()
{
YOUTUBE=$(zenity --entry --width=400 --height=100 --title="YouTube" --text="Ingrese link de youtube:")
}
function youtube_file()
{
TXT=$(zenity --file-selection --title="Seleccionar archivo de texto" --file-filter='*.txt')
}
function directory()
{
DIRECTORY=$(zenity --file-selection --directory --title="Guardar")
cd ${DIRECTORY}
}
function progress()
{
(
echo "10" ; sleep 1
echo "20" ; sleep 1
if [ ! -z "${YOUTUBE}" ]
then
youtube-dl --extract-audio --audio-quality 0 --audio-format mp3 --output '%(title)s.%(ext)s' "${YOUTUBE}"
fi
if [ ! -z "${TXT}" ]
then
youtube-dl --extract-audio --audio-quality 0 --audio-format mp3 --output '%(title)s.%(ext)s' --batch-file "${TXT}"
fi
echo "50" ; sleep 1
echo "75" ; sleep 1
echo "100" ; sleep 1
) |
zenity --progress --title="Descargando musica" --text="Descargando..." --percentage=0 --auto-close
if [ "$?" = 0 ] ; then
zenity --info --text="Descarga terminada." --ellipsize
fi
if [ "$?" = -1 ] ; then
zenity --error --text="Descarga cancelada."
fi
exit 0
}
function select_option()
{
OPTION=$(zenity --list --title="Seleccionar opcion" --text="Seleccione una opcion para comenzar" --column="Selection" --column="Description" "" "Insertar link" "" "Descargar desde archivo" --hide-header --radiolist --height=150 --width=400)
if [ "${OPTION}" == "Insertar link" ]
then
return 10
else
if [ "${OPTION}" == "Descargar desde archivo" ]
then
return 11
fi
fi
exit 1
}
function main() {
select_option
case "$?" in
10)
youtube_link
;;
11)
youtube_file
;;
*)
exit 2
;;
esac
directory
progress
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment