separated files, added config file, added variable for zenity and ffmpeg

This commit is contained in:
silvernode 2015-01-16 15:11:53 -06:00
parent bd6b7d2d23
commit c741f72980
6 changed files with 220 additions and 4 deletions

10
README
View File

@ -11,8 +11,10 @@ Dependencies
------------- -------------
* youtube-dl * youtube-dl
* zenity * zenity or yad
* vlc * xdg-utils
* libnotify
* ffmpeg or avconvert
Installation Installation
@ -20,8 +22,10 @@ Installation
1. Open a terminal window 1. Open a terminal window
2. Navigate to the directory zymp3 is located 2. Navigate to the directory zymp3 is located
3. you@machine:~$ chmod +x zymp3 3. you@machine:~$ cd zymp3/src
4. ./zymp3 4. ./zymp3
TODO: standalone installer

9
assets/zymp3.desktop Executable file
View File

@ -0,0 +1,9 @@
[Desktop Entry]
Name=Zymp3
Comment=Convert youtube videos to mp3
Exec=zymp3
Icon=zymp3.png
Terminal=0
Type=Application
Encoding=UTF-8
Categories=AudioVideo;Application;

BIN
assets/zymp3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

23
config/zymp3.conf Normal file
View File

@ -0,0 +1,23 @@
#!/bin/bash
#config.sh
#Zymp3 Configuration File
#FILE SETTINGS
#MUSICDIR must have trailing forward slash
MUSICDIR="/home/$USER/Music/"
#You shouldn't need to change this filename but just in case
VIDEOFILE=/tmp/youtube-dl-$RANDOM-$RANDOM.flv
#GUI SETTINGS
URL_BOX_HEIGHT="64"
URL_BOX_WIDTH="512"
FILENAME_BOX_HEIGHT="64"
FILENAME_BOX_WIDTH="326"

121
lib/logic.lib Normal file
View File

@ -0,0 +1,121 @@
#!/bin/bash
SET_GUI_BIN="zenity"
SET_CONV_TOOL="ffmpeg"
#convert youtube videos to mp3 with zenity progess bar
backend()
{
youtube-dl --output=${VIDEOFILE} --format=18 "$1" | ${SET_GUI_BIN} --progress --pulsate --title="Downloading..." --text="Downloading video, please wait.." --auto-close
if [ ! -f $VIDEOFILE ];then
${SET_GUI_BIN} --error --text "Can't convert video to mp3 because it does not exist, it probably failed to download."
exit 0;
elif [ -f $VIDEOFILE ];then
${SET_CONV_TOOL} -i $VIDEOFILE -acodec libmp3lame -ac 2 -ab 128k -vn -y "$2" | ${SET_GUI_BIN} --progress --pulsate --title="Converting..." --text="Converting video to mp3.." --auto-close
rm ${VIDEOFILE}
else
echo -e "\e[1;31mERROR: It seems the video file successfully downloaded, however it was not converted to mp3 \e[0m"
${SET_GUI_BIN} --error --text "It seems the video file successfully downloaded, however it was not converted to mp3"
fi
}
#first zenity gui window (paste youtube link)
gui()
{
VIDURL=$(${SET_GUI_BIN} --title="Zymp3 0.1-5" --height=${URL_BOX_HEIGHT} --width=${URL_BOX_WIDTH} --entry --text "Paste youtube link here: ")
if [[ $? == 0 ]] ; then
gui2
else
exit 0;
fi
}
#second gui window to name your mp3 file
gui2()
{
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
}
#notify the user that the mp3 file has been moved to their music folder
open()
{
if [[ $? == 0 ]] ; then
xdg-open "${MUSICDIR}${AUDIOFILENAME}.mp3"
else
exit 0;
fi
}
#Check if MUSICDIR exists and create the directory if not
#move the mp3 file to the users music directory
move()
{
if [ -d ${MUSICDIR} ];then
mv -v "${AUDIOFILENAME}.mp3" ${MUSICDIR}
elif [ ! -d ${MUSICDIR} ];then
mkdir ${MUSICDIR}
mv -v "${AUDIOFILENAME}.mp3" ${MUSICDIR}
fi
}
checkFile()
{
#check if mp3 file exists
if [ -f "${MUSICDIR}${AUDIOFILENAME}.mp3" ];then
notify-send "${AUDIOFILENAME}.mp3 was saved in ${MUSICDIR}"
${SET_GUI_BIN} --question --title="Hey!" --text="I moved $AUDIOFILENAME.mp3 to $MUSICDIR, do you want to play it now?"
elif [ ! -f "${MUSICDIR}${AUDIOFILENAME}.mp3" ];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
}
dconvert()
{
#call backend function and pass video URL and input of mp3 file
backend "${VIDURL}" "${AUDIOFILENAME}.mp3"
#call the move function to send mp3 files to MUSICDIR
move
#check if mp3 file is in MUSICDIR before prompting to play
checkFile
open
}

59
src/zymp3 Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
##############################################
# Title: Zymp3 v0.1-5
# Description: Convert youtube video to mp3
# Author: Justin Moore
# Created: Oct 12, 2011
# Updated: Jan 16, 2015
# Contact: mollusk@homebutter.com
# github: https://github.com/silvernode/zymp3
##############################################
#I wrote this in 2011 and realize now I could have done this alot better
#check for config file in two locations
chk_conf(){
if [ -f ~/.config/Zymp3/zymp3.conf ];then
source ~/.config/Zymp3/zymp3.conf
elif [ -f ../config/zymp3.conf ];then
source ../config/zymp3.conf
else
echo -e "\e[1;31mERROR: No config file in $HOME/.config/Zymp3/ or ../config/ \e[0m"
zenity --error --text "No config file in $HOME/.config/Zymp3/ or ../config"
exit 0;
fi
}
chk_libs(){
if [ -f ../lib/logic.lib ];then
source ../lib/logic.lib
else
echo -e "\e[1;31mERROR: No libraries file in found in ../libs \e[0m"
zenity --error --text "No libraries file in found in ../libs"
exit 0;
fi
}
#call the main gui
main(){
while true;do
chk_conf
chk_libs
gui
done
}
main