2015-01-16 15:11:53 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-02-25 02:06:39 -06:00
|
|
|
source config/zymp3.conf
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
#CHECK FOR YAD OR ZENITY AND DEFAULT TO ONE
|
2015-02-12 22:34:18 -06:00
|
|
|
if [ ! -f /usr/bin/yad ];then
|
|
|
|
SET_GUI_BIN="zenity"
|
2015-02-25 02:06:39 -06:00
|
|
|
elif [ ! -f /usr/bin/zenity ];then
|
2015-02-12 22:34:18 -06:00
|
|
|
SET_GUI_BIN="yad"
|
2015-02-25 02:06:39 -06:00
|
|
|
else
|
|
|
|
SET_GUI_BIN="${SET_GUI_BIN}"
|
2015-02-12 22:34:18 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /usr/bin/ffmpeg ];then
|
|
|
|
SET_CONV_TOOL="avconv"
|
|
|
|
else
|
|
|
|
SET_CONV_TOOL="ffmpeg"
|
|
|
|
fi
|
2015-08-09 18:53:58 -07:00
|
|
|
|
|
|
|
#PROGRESS BAR
|
2015-01-16 15:11:53 -06:00
|
|
|
backend()
|
|
|
|
{
|
|
|
|
|
2015-03-20 19:28:47 -05:00
|
|
|
youtube-dl --output=${VIDEOFILE} --format=18 "$1" | ${SET_GUI_BIN} --progress \
|
|
|
|
--pulsate --title="Downloading..." \
|
|
|
|
--text="Downloading video, please wait.." --auto-close
|
2015-05-05 12:24:43 -05:00
|
|
|
if [[ $? == 1 ]];then
|
2015-03-20 19:28:47 -05:00
|
|
|
exit 0;
|
2015-05-05 12:24:43 -05:00
|
|
|
fi
|
|
|
|
if [ "${USE_FILE_BROWSER}" = "no" ];then
|
|
|
|
if [ ! -f $VIDEOFILE ];then
|
|
|
|
${SET_GUI_BIN} --error \
|
|
|
|
--text "Can't convert video because it does not exist, it probably failed to download."
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
elif [ -f $VIDEOFILE ];then
|
|
|
|
${SET_CONV_TOOL} -i $VIDEOFILE -acodec ${CODEC} -ac 2 -ab ${BITRATE}k -vn -y "${CONVERTED}/$2" | ${SET_GUI_BIN} \
|
|
|
|
--progress --pulsate --title="Converting..." \
|
|
|
|
--text="Converting video.." --auto-close
|
|
|
|
if [[ $? != 0 ]];then
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
rm ${VIDEOFILE}
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
else
|
|
|
|
echo -e "\e[1;31mERROR: It seems the video file successfully downloaded, however it was not converted \e[0m"
|
|
|
|
${SET_GUI_BIN} --error \
|
|
|
|
--text "It seems the video file successfully downloaded, however it was not converted."
|
|
|
|
fi
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
else
|
|
|
|
if [ ! -f $VIDEOFILE ];then
|
|
|
|
${SET_GUI_BIN} --error \
|
|
|
|
--text "Can't convert video because it does not exist, it probably failed to download."
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
elif [ -f $VIDEOFILE ];then
|
|
|
|
${SET_CONV_TOOL} -i $VIDEOFILE -acodec ${CODEC} -ac 2 -ab ${BITRATE}k -vn -y "$2" | ${SET_GUI_BIN} \
|
|
|
|
--progress --pulsate --title="Converting..." \
|
|
|
|
--text="Converting video.." --auto-close
|
|
|
|
if [[ $? != 0 ]];then
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
rm ${VIDEOFILE}
|
|
|
|
|
|
|
|
else
|
|
|
|
echo -e "\e[1;31mERROR: It seems the video file successfully downloaded, however it was not converted \e[0m"
|
|
|
|
${SET_GUI_BIN} --error \
|
|
|
|
--text "It seems the video file successfully downloaded, however it was not converted"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
#PASTE YOUTUBE LINK - WINDOW
|
2015-01-16 15:11:53 -06:00
|
|
|
gui()
|
|
|
|
{
|
2015-03-20 19:28:47 -05:00
|
|
|
VIDURL=$(${SET_GUI_BIN} --title="Zymp3 0.1.7" \
|
|
|
|
--height=${URL_BOX_HEIGHT} \
|
|
|
|
--width=${URL_BOX_WIDTH} --entry \
|
|
|
|
--text "Paste youtube link here: ")
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-03-04 19:01:03 -06:00
|
|
|
|
2015-03-04 20:20:21 -06:00
|
|
|
if [[ $? == 0 ]];then
|
2015-03-04 20:28:03 -06:00
|
|
|
if [[ ${VIDURL} == *"https://www.youtube.com/watch?v="* ]];then
|
2015-03-04 19:01:03 -06:00
|
|
|
gui2
|
2015-03-04 20:20:21 -06:00
|
|
|
|
2015-03-04 19:01:03 -06:00
|
|
|
else
|
2015-03-04 20:20:21 -06:00
|
|
|
${SET_GUI_BIN} --error --text "Invalid URL"
|
2015-03-04 19:01:03 -06:00
|
|
|
fi
|
2015-03-04 20:20:21 -06:00
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
else
|
2015-03-04 20:20:21 -06:00
|
|
|
exit 0;
|
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
|
|
|
|
|
|
|
|
#ENTER MP3 FILE NAME OR OPEN FILEBROWSER
|
|
|
|
#CAN BE SWITCHED IN CONFIG
|
2015-01-16 15:11:53 -06:00
|
|
|
|
|
|
|
gui2()
|
|
|
|
{
|
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
if [ "${USE_FILE_BROWSER}" = "no" ];then
|
|
|
|
AUDIOFILENAME=$(${SET_GUI_BIN} --title="Filename" \
|
|
|
|
--height=${FILENAME_BOX_HEIGHT} \
|
|
|
|
--width=${FILENAME_BOX_WIDTH} \
|
|
|
|
--entry --text "Name your file: ")
|
|
|
|
|
|
|
|
if [[ $? == 0 ]];then
|
|
|
|
dconvert
|
|
|
|
else
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
else
|
2015-05-05 12:24:43 -05:00
|
|
|
FILEBROWSER=$(zenity --file-selection --directory \
|
|
|
|
--title= "Where to save mp3 file? " \
|
|
|
|
--filename=/home/$USER/Music/ \
|
|
|
|
--file-filter='MP3 files (mp3) | *.mp3','OGG files (ogg) | *.ogg', 'FLAC (flac) | *.flac' \
|
|
|
|
--save --confirm-overwrite)
|
|
|
|
if [[ $? == 0 ]];then
|
|
|
|
dconvert
|
|
|
|
else
|
|
|
|
exit 0;
|
|
|
|
fi
|
2015-01-16 15:11:53 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
#CHECK IF FILEBROWSER VAR IS SET
|
|
|
|
#IF NOT SET, DEFAULT TO MANUAL TO {MUSICDIR}
|
2015-01-16 15:11:53 -06:00
|
|
|
open()
|
|
|
|
{
|
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
if [ "${USE_FILE_BROWSER}" = "no" ];then
|
|
|
|
if [[ $? == 0 ]];then
|
|
|
|
xdg-open "${MUSICDIR}${AUDIOFILENAME}.${EXTENSION}"
|
|
|
|
else
|
|
|
|
exit 0;
|
|
|
|
fi
|
2015-01-16 15:11:53 -06:00
|
|
|
|
|
|
|
else
|
2015-05-05 12:24:43 -05:00
|
|
|
if [[ $? == 0 ]];then
|
|
|
|
xdg-open "${FILEBROWSER}"
|
|
|
|
else
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
#MOVE MP3 FILE TO MUSICDIR
|
|
|
|
#IF MUSICDIR DOES NOT EXIST, CREATE IT
|
2015-01-16 15:11:53 -06:00
|
|
|
move()
|
|
|
|
{
|
2015-05-05 12:24:43 -05:00
|
|
|
if [ "${USE_FILE_BROWSER}" = "no" ];then
|
|
|
|
if [ -d "${MUSICDIR}" ];then
|
|
|
|
mv -v "${CONVERTED}/${AUDIOFILENAME}.${EXTENSION}" "${MUSICDIR}"
|
|
|
|
elif [ ! -d "${MUSICDIR}" ];then
|
|
|
|
mkdir "${MUSICDIR}"
|
|
|
|
mv -v "${CONVERTED}/${AUDIOFILENAME}.${EXTENSION}" "${MUSICDIR}"
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
fi
|
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
fi
|
2015-01-16 15:11:53 -06:00
|
|
|
}
|
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
|
|
|
|
#CHECK IF MP3 FILE EXISTS
|
2015-01-16 15:11:53 -06:00
|
|
|
checkFile()
|
|
|
|
{
|
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
if [ "${USE_FILE_BROWSER}" = "no" ];then
|
|
|
|
if [ -f "${MUSICDIR}${AUDIOFILENAME}.${EXTENSION}" ];then
|
|
|
|
notify-send "${AUDIOFILENAME}.${EXTENSION} was saved in ${MUSICDIR}"
|
|
|
|
${SET_GUI_BIN} --question \
|
|
|
|
--title="Hey!" \
|
|
|
|
--text="I moved $AUDIOFILENAME.${EXTENSION} to $MUSICDIR, do you want to play it now?"
|
|
|
|
if [[ $? != 0 ]];then
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
elif [ ! -f "${MUSICDIR}${AUDIOFILENAME}.${EXTENSION}" ];then
|
|
|
|
${SET_GUI_BIN} --error \
|
|
|
|
--text "The mp3 file was does not exist. Either the download failed or the video was not converted to mp3 properly"
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
if [ -f "${FILEBROWSER}.${EXTENSION}" ];then
|
|
|
|
notify-send "${FILEBROWSER}.${EXTENSION} was saved"
|
|
|
|
${SET_GUI_BIN} --question \
|
|
|
|
--title="Hey!" \
|
|
|
|
--text="${FILEBROWSER}.${EXTENSION} was saved, do you want to play it now?"
|
|
|
|
if [[ $? == 0 ]];then
|
|
|
|
open
|
|
|
|
else
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
elif [ ! -f "${FILEBROWSER}.${EXTENSION}" ];then
|
|
|
|
${SET_GUI_BIN} --error \
|
|
|
|
--text "The converted file does not exist. Either the download failed or the video was not converted properly"
|
|
|
|
fi
|
2015-01-16 15:11:53 -06:00
|
|
|
fi
|
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dconvert()
|
|
|
|
{
|
|
|
|
|
2015-08-09 18:53:58 -07:00
|
|
|
#PASS VIDEO URL AND FILENAME.MP3 TO BACKEND FUNCTION
|
2015-05-05 12:24:43 -05:00
|
|
|
if [ "${USE_FILE_BROWSER}" = "no" ];then
|
|
|
|
backend "${VIDURL}" "${AUDIOFILENAME}.${EXTENSION}"
|
|
|
|
move
|
|
|
|
checkFile
|
|
|
|
open
|
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
else
|
|
|
|
backend "${VIDURL}" "${FILEBROWSER}.${EXTENSION}"
|
|
|
|
checkFile
|
|
|
|
fi
|
2015-01-16 15:11:53 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-05 12:24:43 -05:00
|
|
|
|
2015-01-16 15:11:53 -06:00
|
|
|
}
|