122 lines
1.8 KiB
Bash
Executable File
122 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
##############################################
|
|
# Title: Zymp3 v0.1
|
|
# Description: Convert youtube video to mp3
|
|
# Author: Justin Moore
|
|
# Contact: silvernode@gmail.com
|
|
# github: https://github.com/silvernode/zymp3
|
|
##############################################
|
|
|
|
|
|
#I wrote this in 2011 and realize now I could have done this alot better
|
|
|
|
|
|
|
|
#set music directory path
|
|
MUSICDIR="/home/$USER/Music"
|
|
|
|
|
|
#convert youtube videos to mp3 with zenity progess bar
|
|
backend()
|
|
{
|
|
t=~/.youtube-dl-$RANDOM-$RANDOM.flv
|
|
youtube-dl --output=$t --format=18 "$1" | zenity --progress --pulsate --title="Downloading..." --text="Downloading video, please wait.." --auto-close
|
|
ffmpeg -i $t -acodec libmp3lame -ac 2 -ab 128k -vn -y "$2" | zenity --progress --pulsate --title="Converting..." --text="Converting video to mp3.." --auto-close
|
|
rm $t
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#first zenity gui window (paste youtube link)
|
|
gui()
|
|
{
|
|
x=$(zenity --title="Zymp3 0.1-1" --entry --text "Paste youtube link here: ")
|
|
|
|
|
|
if [[ $? == 0 ]] ; then
|
|
|
|
|
|
gui2
|
|
else
|
|
exit 0;
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#second gui window to name your mp3 file
|
|
|
|
gui2()
|
|
{
|
|
y=$(zenity --title="Filename" --entry --text "Name your file: ")
|
|
|
|
if [[ $? == 0 ]] ; then
|
|
dconvert
|
|
else
|
|
exit 0;
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#notify the user that the mp3 file has been moved to their music folder
|
|
open()
|
|
{
|
|
|
|
zenity --question --title="Hey!" --text="I moved $y.mp3 to $MUSICDIR, do you want to play it now?"
|
|
|
|
|
|
|
|
|
|
if [[ $? == 0 ]] ; then
|
|
vlc "/home/$USER/Music/$y.mp3"
|
|
else
|
|
exit 0;
|
|
fi
|
|
|
|
|
|
}
|
|
|
|
|
|
#move the mp3 file to the users music directory
|
|
move()
|
|
{
|
|
|
|
mkdir /home/$USER/Music
|
|
mv "$y.mp3" /home/$USER/Music
|
|
|
|
}
|
|
|
|
#call the backend function so we can use it
|
|
dconvert()
|
|
{
|
|
backend "$x" "$y.mp3"
|
|
|
|
|
|
move
|
|
|
|
if [ -f "/home/$USER/Music/$y.mp3" ]
|
|
then notify-send "$y.mp3 was saved in $MUSICDIR}"
|
|
else
|
|
zenity --error --text "Oh no! Something fucked up! fuck.."
|
|
fi
|
|
|
|
|
|
|
|
open
|
|
}
|
|
|
|
#call the main gui
|
|
gui
|
|
|
|
|
|
|
|
|