made code more readable, added auto codec changing

This commit is contained in:
silvernode 2015-10-15 04:29:35 -07:00
parent 02a77aa2e2
commit a03eb62978

View File

@ -2,6 +2,10 @@
source config/zymp3.conf source config/zymp3.conf
#Codec format of audio file
#libmp3lame (mp3), libvorbis (ogg), flac (flac)
CODEC="" #this gets set in he 'changeCodec' function
#CHECK FOR YAD OR ZENITY AND DEFAULT TO ONE #CHECK FOR YAD OR ZENITY AND DEFAULT TO ONE
if [ ! -f /usr/bin/yad ];then if [ ! -f /usr/bin/yad ];then
SET_GUI_BIN="zenity" SET_GUI_BIN="zenity"
@ -17,59 +21,99 @@ else
SET_CONV_TOOL="ffmpeg" SET_CONV_TOOL="ffmpeg"
fi fi
changeCodec(){
if [ "${EXTENSION}" = "ogg" ];then
CODEC="libvorbis"
elif [ "${EXTENSION}" = "mp3" ];then
CODEC="libmp3lame"
elif [ "${EXTENSION}" = "flac" ];then
CODEC="flac"
fi
}
#PROGRESS BAR #PROGRESS BAR
backend() backend()
{ {
youtube-dl --output=${VIDEOFILE} --format=18 "$1" | ${SET_GUI_BIN} --progress \ youtube-dl \
--output=${VIDEOFILE} --format=18 "$1" | ${SET_GUI_BIN}\
--progress \
--pulsate --title="Downloading..." \ --pulsate --title="Downloading..." \
--text="Downloading video, please wait.." --auto-close --text="Downloading video, please wait.." --auto-close
if [[ $? == 1 ]];then if [[ $? == 1 ]];then
exit 0; exit 0;
fi fi
if [ "${USE_FILE_BROWSER}" = "no" ];then if [ "${USE_FILE_BROWSER}" = "no" ];then
if [ ! -f $VIDEOFILE ];then if [ ! -f $VIDEOFILE ];then
${SET_GUI_BIN} --error \ ${SET_GUI_BIN} \
--text "Can't convert video because it does not exist, it probably failed to download." --error \
--text "Can't convert video because it does not exist,
it probably failed to download."
exit 0; exit 0;
elif [ -f $VIDEOFILE ];then elif [ -f $VIDEOFILE ];then
${SET_CONV_TOOL} -i $VIDEOFILE -acodec ${CODEC} -ac 2 -ab ${BITRATE}k -vn -y "${CONVERTED}/$2" | ${SET_GUI_BIN} \ changeCodec
--progress --pulsate --title="Converting..." \ ${SET_CONV_TOOL} -i $VIDEOFILE -acodec ${CODEC} -ac 2 -ab ${BITRATE}k \
--text="Converting video.." --auto-close -vn -y "${CONVERTED}/$2" | ${SET_GUI_BIN} \
--progress\
--pulsate\
--title="Converting..." \
--text="Converting video.."\
--auto-close
if [[ $? != 0 ]];then if [[ $? != 0 ]];then
exit 0; exit 0;
fi fi
rm ${VIDEOFILE} rm ${VIDEOFILE}
else else
echo -e "\e[1;31mERROR: It seems the video file successfully downloaded, however it was not converted \e[0m" echo -e "\e[1;31mERROR: It seems the video file successfully downloaded,
${SET_GUI_BIN} --error \ however it was not converted \e[0m"
--text "It seems the video file successfully downloaded, however it was not converted."
${SET_GUI_BIN}\
--error \
--text "It seems the video file successfully downloaded,
however it was not converted."
fi fi
else else
if [ ! -f $VIDEOFILE ];then if [ ! -f $VIDEOFILE ];then
${SET_GUI_BIN} --error \ ${SET_GUI_BIN}\
--text "Can't convert video because it does not exist, it probably failed to download." --error \
--text "Can't convert video because it does not exist,
it probably failed to download."
exit 0; exit 0;
elif [ -f $VIDEOFILE ];then elif [ -f $VIDEOFILE ];then
${SET_CONV_TOOL} -i $VIDEOFILE -acodec ${CODEC} -ac 2 -ab ${BITRATE}k -vn -y "$2" | ${SET_GUI_BIN} \ ${SET_CONV_TOOL}\
--progress --pulsate --title="Converting..." \ -i $VIDEOFILE\
--text="Converting video.." --auto-close -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 if [[ $? != 0 ]];then
exit 0; exit 0;
fi fi
rm ${VIDEOFILE} rm ${VIDEOFILE}
else else
echo -e "\e[1;31mERROR: It seems the video file successfully downloaded, however it was not converted \e[0m" echo -e\
"\e[1;31mERROR: It seems the video file successfully downloaded,
however it was not converted \e[0m"
${SET_GUI_BIN} --error \ ${SET_GUI_BIN} --error \
--text "It seems the video file successfully downloaded, however it was not converted" --text "It seems the video file successfully downloaded,
however it was not converted"
fi fi
fi fi
} }
@ -78,21 +122,22 @@ gui()
{ {
VIDURL=$(${SET_GUI_BIN} --title="Zymp3 0.1.7" \ VIDURL=$(${SET_GUI_BIN} --title="Zymp3 0.1.7" \
--height=${URL_BOX_HEIGHT} \ --height=${URL_BOX_HEIGHT} \
--width=${URL_BOX_WIDTH} --entry \ --width=${URL_BOX_WIDTH}\
--entry \
--text "Paste youtube link here: ") --text "Paste youtube link here: ")
if [[ $? == 0 ]];then if [[ $? == 0 ]];then
if [[ ${VIDURL} == *"https://www.youtube.com/watch?v="* ]];then if [[ ${VIDURL} == *"https://www.youtube.com/watch?v="* ]];then
gui2 gui2
else else
${SET_GUI_BIN} --error --text "Invalid URL" ${SET_GUI_BIN} --error --text "Invalid URL"
fi fi
else else
exit 0; exit 0;
fi fi
@ -124,8 +169,12 @@ gui2()
FILEBROWSER=$(zenity --file-selection --directory \ FILEBROWSER=$(zenity --file-selection --directory \
--title= "Where to save mp3 file? " \ --title= "Where to save mp3 file? " \
--filename=/home/$USER/Music/ \ --filename=/home/$USER/Music/ \
--file-filter='MP3 files (mp3) | *.mp3','OGG files (ogg) | *.ogg', 'FLAC (flac) | *.flac' \ --file-filter='
MP3 files (mp3) | *.mp3',
'OGG files (ogg) | *.ogg',
'FLAC (flac) | *.flac' \
--save --confirm-overwrite) --save --confirm-overwrite)
if [[ $? == 0 ]];then if [[ $? == 0 ]];then
dconvert dconvert
else else
@ -172,9 +221,9 @@ move()
elif [ ! -d "${MUSICDIR}" ];then elif [ ! -d "${MUSICDIR}" ];then
mkdir "${MUSICDIR}" mkdir "${MUSICDIR}"
mv -v "${CONVERTED}/${AUDIOFILENAME}.${EXTENSION}" "${MUSICDIR}" mv -v "${CONVERTED}/${AUDIOFILENAME}.${EXTENSION}" "${MUSICDIR}"
fi fi
fi fi
} }
@ -189,14 +238,16 @@ checkFile()
notify-send "${AUDIOFILENAME}.${EXTENSION} was saved in ${MUSICDIR}" notify-send "${AUDIOFILENAME}.${EXTENSION} was saved in ${MUSICDIR}"
${SET_GUI_BIN} --question \ ${SET_GUI_BIN} --question \
--title="Hey!" \ --title="Hey!" \
--text="I moved $AUDIOFILENAME.${EXTENSION} to $MUSICDIR, do you want to play it now?" --text="I moved $AUDIOFILENAME.${EXTENSION} to $MUSICDIR, play it now?"
if [[ $? != 0 ]];then if [[ $? != 0 ]];then
exit 0; exit 0;
fi fi
elif [ ! -f "${MUSICDIR}${AUDIOFILENAME}.${EXTENSION}" ];then elif [ ! -f "${MUSICDIR}${AUDIOFILENAME}.${EXTENSION}" ];then
${SET_GUI_BIN} --error \ ${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" --text\
"The mp3 file was does not exist. Either the download failed or
the video was not converted to mp3 properly"
fi fi
else else
@ -204,7 +255,7 @@ checkFile()
notify-send "${FILEBROWSER}.${EXTENSION} was saved" notify-send "${FILEBROWSER}.${EXTENSION} was saved"
${SET_GUI_BIN} --question \ ${SET_GUI_BIN} --question \
--title="Hey!" \ --title="Hey!" \
--text="${FILEBROWSER}.${EXTENSION} was saved, do you want to play it now?" --text="${FILEBROWSER}.${EXTENSION} was saved, play it now?"
if [[ $? == 0 ]];then if [[ $? == 0 ]];then
open open
else else
@ -213,7 +264,9 @@ checkFile()
elif [ ! -f "${FILEBROWSER}.${EXTENSION}" ];then elif [ ! -f "${FILEBROWSER}.${EXTENSION}" ];then
${SET_GUI_BIN} --error \ ${SET_GUI_BIN} --error \
--text "The converted file does not exist. Either the download failed or the video was not converted properly" --text\
"The converted file does not exist. Either the download
failed or the video was not converted properly"
fi fi
fi fi
@ -230,7 +283,7 @@ dconvert()
move move
checkFile checkFile
open open
else else
backend "${VIDURL}" "${FILEBROWSER}.${EXTENSION}" backend "${VIDURL}" "${FILEBROWSER}.${EXTENSION}"
@ -238,6 +291,6 @@ dconvert()
fi fi
} }