#Awesome declaration of variables
Yes="y"
No="n"
TimeBeginning=$(date +%s)
mxtubecontent=$(ls /var/mobile/Media/MxTube)
if [ -e "/var/mobile/Media/FFaac-Settings/genre" ];
then
genre="FFaac"
else
genre=""
fi
importedfromyourtube=0
nopwntunes="-----------
Music files stored in /var/mobile/Media/My Music/

Buy PwnTunes by SpiritOfLogic in Cydia to import your converted music into iPod.app or listen to it with a different app.
It also offers a free trial. It's well worth the money.


-Enjoy
-----------"
haspwntunes="-----------
Music files stored in /var/mobile/Media/My Music/


Go to Settings > PwnTunes > Needs Sync to import your new Music.

-Enjoy
-----------"
Oldfiles="Old Files"
importedfrommxtube="0"

if [ ! -d "/var/mobile/Media/My Lyrics/" ];
then
mkdir "/var/mobile/Media/My Lyrics/"
chown mobile:mobile "/var/mobile/Media/My Lyrics/"
fi

if [ -e /Applications/PwnTunes.app ];
then
pwntunes="1"
else
pwntunes="0"
fi
#Cleaning up
if [ -e "/var/mobile/Media/FFaac-Ringtones" ];
then
insidering=$(ls /var/mobile/Media/FFaac-Ringtones)
	if [ "$insidering" = "" ];
	then
	rmdir /var/mobile/Media/FFaac-Ringtones
	fi
fi
if [ ! -e "/var/mobile/Media/FFaac-Settings" ];
then
mkdir "/var/mobile/Media/FFaac-Settings"
chown mobile:mobile "/var/mobile/Media/FFaac-Settings"
fi
if [ -e "/var/mobile/Media/FFaac.onelastfile.tmp" ];
then
rm -f "/var/mobile/Media/ffaac.ringtone.tmp"
rm -f "/var/mobile/Media/FFaac.onelastfile.tmp"
rm -f "/var/mobile/Media/ffaac.Ringt.Conversion.tmp"
fi
if [ -e "/var/mobile/Media/My Music/log" ];
then
rm -f "/var/mobile/Media/My Music/log"
rm -f "/var/mobile/Media/My Music/log2"
rm -f "/var/mobile/whom"
echo "Cleaned up"
fi
#Creating Folders
if [ -e /var/mobile/Media/Convert ];
then
echo "Convert exists"
else
mkdir "/var/mobile/Media/Convert"
chown mobile:mobile "/var/mobile/Media/Convert"
echo "Created folder Convert"
fi

if [ -e "/var/mobile/Media/My Music" ];
then
echo "My Music exists"
find "/var/mobile/Media/My Music" -type f -iname "*.jpg" | while read i
do
	if [ "$(basename "${i}")" != "cover.jpg" ];
	then
	mv "$i" "/var/mobile/Media/My Music/$(echo $i | cut -d '/' -f6)/cover.jpg"
	fi
done
else
mkdir "/var/mobile/Media/My Music"
chown mobile:mobile "/var/mobile/Media/My Music"
echo "Created folder My Music"
fi

if [ -e "/var/mobile/Media/${Oldfiles}" ];
then
echo "${Oldfiles} exists"
else
mkdir "/var/mobile/Media/${Oldfiles}"
chown mobile:mobile "/var/mobile/Media/${Oldfiles}"
echo "Created folder ${Oldfiles}"
fi

#"anothertimecontent": This belongs here, don't move it!!!
echo "

Welcome to 

88888 88888                  
88    88    eeeee eeeee eeee 
8eeee 8eeee 8   8 8   8 8  8 
88    88    8eee8 8eee8 8   
88    88    88  8 88  8 8   
88    88    88  8 88  8 88e8 
"
if [ -e /var/mobile/Library/FFaac.sureno ];
then
read -p "Wait, aren't you the guy from last time, who didn't want to tweet how awesome FFaac is? (y/n) " uhm
	if [ $uhm = $Yes ];
	then
	read -p "How about you apologize then? ([s]orry) " sorry
		if [ $sorry = "s" ];
		then
		echo "Apology accepted. I was also wrong forcing you into tweeting something. Sorry for that.
		"
		rm -f "/var/mobile/Library/FFaac.sureno"
		else
		echo "Looks like you don't want anything converted. Bye."
		rm -f "/var/mobile/Library/FFaac.sureno"
		echo "Har Har" > "/var/mobile/Library/FFaac.forgiven"
		chown mobile:mobile "/var/mobile/Library/FFaac.forgiven"
		exit
		fi
	fi
	if [ $uhm = $No ];
	then	
	echo "Liar.
	"
	rm -f "/var/mobile/Library/FFaac.sureno"
	echo "Har Har" > "/var/mobile/Library/FFaac.forgiven"
	chown mobile:mobile "/var/mobile/Library/FFaac.forgiven"
	exit
	fi
fi

if [ -e "/var/mobile/Library/FFaac.forgiven" ];
then
echo -n "."
sleep 1
echo -n "."
sleep 1
echo -n "."
sleep 1
echo "

I forgive you.
"
rm -f "/var/mobile/Library/FFaac.forgiven"
fi

echo "
--------------
To access the settings panel close FFaac and type \"setffaac\" without quotes
--------------
"

if [ ! -e /var/mobile/Media/FFaac-Settings/mxtubesafety ];
then
	if [ -e /var/mobile/Media/FFaac-Settings/mxtubeimported ] || [ -e /var/mobile/Media/RingRing-Settings/mxtubeimported ];
	then
	find /var/mobile/Media/Convert -type f | while read i
	do
	mv "$i" /var/mobile/Media/MxTube
	done
	if [ -e /var/mobile/Media/importedvideosfrommxtube ];
	then
	find /var/mobile/Media/importedvideosfrommxtube -type f | while read i
	do
	mv "$i" /var/mobile/Media/MxTube
	done
	rmdir /var/mobile/Media/importedvideosfrommxtube
	fi
	rm -f /var/mobile/Media/FFaac-Settings/mxtubeimported
	echo "!!!!!!!!!!!!!!!
It seems your last conversion didn't work out that well. FFaac moved the contents of /var/mobile/Media/Convert into /var/mobile/Media/MxTube for safety reasons. To disable this feature close FFaac and open the FFaac-Settings by typing \"setffaac\".
!!!!!!!!!!!!!!!
"
	fi
fi
anothertimecontent=$(ls /var/mobile/Media/Convert)
#####################################################YourTube#####################################################
function YourTube ()
{
importedfromyourtube=1
if [ -e /var/mobile/Media/YourTMP ];
then
find /var/mobile/Media/YourTMP -type f | while read i
do
mv "$i" /var/mobile/Media/YourTube
done
rmdir /var/mobile/Media/YourTMP
fi

if [ ! -e /var/mobile/Media/YourTubeFileNames ];
then
newyourtube="$(ls /var/mobile/Media/YourTube)"
else
ls /var/mobile/Media/YourTube | while read i
do
echo "$i" >> /var/mobile/Media/FFaac-Settings/comparisonfile
done
cat /var/mobile/Media/YourTubeFileNames | while read i
do
echo "$i" | cut -d '#' -f1 >> /var/mobile/Media/FFaac-Settings/comparisonfile
done
newyourtube=$(cat /var/mobile/Media/FFaac-Settings/comparisonfile | sort | uniq -u)
fi

rm -f /var/mobile/Media/FFaac-Settings/comparisonfile
if [ "$(echo $newyourtube)" != "" ];
then
echo "

If new files have been added to your YourTube-Collection, we need to create a database together as YourTube itself names them unproperly,
this only takes a few seconds of your time and you only have to do it every once in a while (everytime you add new videos).
Sorry for the inconvenience. I'm trying very hard to keep FFaac convenient.

"
sleep 1
echo "$newyourtube" > /var/mobile/Media/newr.txt
chown mobile:mobile /var/mobile/Media/newr.txt
mkdir /var/mobile/Media/YourTMP
chown mobile:mobile /var/mobile/Media/YourTMP
while read i
do
mv "/var/mobile/Media/YourTube/$i" /var/mobile/Media/YourTMP 2>/dev/null
done < /var/mobile/Media/newr.txt
rm -f /var/mobile/Media/newr.txt
k=1
while true
do
yourcurr="$(ls /var/mobile/Media/YourTMP | head -1)"
	if [ "$(ls /var/mobile/Media/YourTMP)" != "" ];
	then
	nohup ffmpeg -i "/var/mobile/Media/YourTMP/$yourcurr" -acodec copy -ss 3 -t 8 /var/mobile/Media/FFaac-Settings/AudioPreviewYourTube.aac 0>/dev/null 1>/dev/null 2>/dev/null
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/AudioPreviewYourTube.aac
	echo "Playing audio-preview of $yourcurr"
	play /var/mobile/Media/FFaac-Settings/AudioPreviewYourTube.aac
	rm -f /var/mobile/Media/FFaac-Settings/AudioPreviewYourTube.aac
while true
do
	read -p "
Please enter the songtitle
-Type \"l\" (no quotes) to listen again,
-qqq behind your input to correct a mistake
-or type the songname here: " yoursong
echo
	if [ $(expr $(echo "$yoursong" | wc -m) ">" 4) = 1 ];
	then
	ttz=$(echo "$yoursong" | cut -c$(expr $(echo "$yoursong" | wc -m) - 3)-$(echo "$yoursong" | wc -m))
	else
	ttz=zzz
	fi
	if [ "$yoursong" != "" ];
	then
		if [ "$ttz" != "qqq" ];
		then
		break
		fi
	else
	echo "Please do not write empty ID3-Tags"
	fi
done
		if [ "$yoursong" != "l" ];
		then
		yoursong=$(echo "$yoursong" | tr ' ' '%' | awk '
		{  
		  n=split($0,array,"%")
		  for (i=1;i<=n;i++) {
		x=toupper (substr(array[i],1,1)) substr(array[i],2)
		    printf("%s",x)
		if (i<n) { printf ("%s"," ") }
  		}
  		printf("%s","\n")  
		}')
		echo "$yourcurr#$yoursong" >> /var/mobile/Media/YourTubeFileNames
		chown mobile:mobile /var/mobile/Media/YourTubeFileNames
		mv "/var/mobile/Media/YourTMP/$yourcurr" /var/mobile/Media/YourTube
		chown mobile:mobile "/var/mobile/Media/YourTube/$yourcurr"
		k=$(expr $k + 1)
		fi
	else
	rmdir /var/mobile/Media/YourTMP
	break
	fi
done
fi

if [ -e /var/mobile/Media/FFaac-Settings/thosenamez ];
then
rm -f /var/mobile/Media/FFaac-Settings/thosenamez
fi
while read i
do
ZZ="$(echo $i | cut -d '#' -f1)"
if [ -e "/var/mobile/Media/YourTube/$ZZ" ];
then
echo "$i" | cut -d '#' -f2 >> /var/mobile/Media/FFaac-Settings/thosenamez
else
echo "----FILE NOT FOUND ANYMORE----" >> /var/mobile/Media/FFaac-Settings/thosenamez
fi
done < /var/mobile/Media/YourTubeFileNames
if [ "$(grep -v "\-\-\-\-FILE NOT FOUND ANYMORE\-\-\-\-" /var/mobile/Media/FFaac-Settings/thosenamez)" = "" ];
then
echo "There are no files left in your YourTube folder, please download some files first."
rm -f /var/mobile/Media/YourTubeFileNames
exit
fi
chown mobile:mobile /var/mobile/Media/FFaac-Settings/thosenamez
while true
do
echo "
The following files have been found in your YourTube folder:"
cat -n /var/mobile/Media/FFaac-Settings/thosenamez
read -p "Use one of the following options (no quotes)
\"x\" (any number) to import
\"v\" view what's currently imported
\"s\" start conversion: " nr
if [ "$nr" = "s" ];
then
break
fi
is_integer=$(echo $nr | grep -q '^-\?[0-9]\+$' || echo NaN)
	if [ "$is_integer" != "" ] && [ $nr != v ];
	then
	echo "
Your choice has to be numeric or s/v, duh!
"
	sleep 2
	else
		if [ "$nr" = "v" ];
		then
		echo "
##################
Currently imported:
		"
		ls /var/mobile/Media/Convert
		echo "##################"
		else
		mv /var/mobile/Media/YourTube/"$(cat /var/mobile/Media/YourTubeFileNames | head -$nr | tail -1 | cut -d '#' -f1)" "/var/mobile/Media/Convert/$(cat /var/mobile/Media/FFaac-Settings/thosenamez | head -$nr | tail -1).mp4" 2>/dev/null
			if [ "$(cat /var/mobile/Media/FFaac-Settings/thosenamez | head -$nr | tail -1)" = "----FILE NOT FOUND ANYMORE----" ];
			then
			echo "

This file could not be imported, quit FFaac and type \"setffaac\" without quotes to get to the option menu and choose option 21 to reset this list completely and recreate it the next time you use FFaac with YourTube."
			else
			sed s/"$(cat /var/mobile/Media/FFaac-Settings/thosenamez | head -$nr | tail -1)"/"###File Imported###"/ /var/mobile/Media/FFaac-Settings/thosenamez > /var/mobile/Media/FFaac-Settings/thosenamez2
			chown mobile:mobile /var/mobile/Media/FFaac-Settings/thosenamez2
			mv /var/mobile/Media/FFaac-Settings/thosenamez2 /var/mobile/Media/FFaac-Settings/thosenamez
			fi
		fi
	fi
clear
echo "

"
done
rm -f /var/mobile/Media/FFaac-Settings/thosenamez
}
#####################################################/YourTube#####################################################
#Importing MxTube
if [ "$anothertimecontent" = "" ];
then
###debug 1
choicemxyour=k


if [ ! -e /var/mobile/Media/FFaac-Settings/disableanimport ];
then
if [ -e /var/mobile/Media/MxTube ] && [ -e /var/mobile/Media/YourTube ];
then
while true
do
read -p "You seem to have YourTube and MxTube installed, choose one of them to import videos from.
Note: You can disable one of these two functions completely in the settings-menu.
Import from ([m]xTube/[y]ourTube): " choicemxyour
	if [ "$choicemxyour" != "m" ] && [ "$choicemxyour" != "y" ];
	then
	echo "
Please type either \"m\" for MxTube or \"y\" for YourTube.
	"
	else
	break
	fi
done
	if [ "$choicemxyour" = "y" ];
	then
	YourTube
	fi
fi
else
echo "
$(cat /var/mobile/Media/FFaac-Settings/disableanimport) import disabled. Change this in \"setffaac\".
"
	if [ "$(cat /var/mobile/Media/FFaac-Settings/disableanimport)" = "MxTube" ];
	then
		read -p "Your Convert folder is empty, import from YourTube? (y/n): " importfromyourtubeyesno
		if [ "$importfromyourtubeyesno" = "y" ];
		then
		YourTube
		fi
		if [ "$(ls /var/mobile/Media/Convert )" = "" ];
		then
		echo "Please import something first."
		exit
		fi
	fi
fi




if [ "$anothertimecontent" = "" ];
then
	if [ -d /var/mobile/Media/MxTube ];
	then	
	while true
	do
		if [ "$choicemxyour" = "m" ];
		then
		import="y"
		else
		read -p "Your Convert folder is empty, do you want to import videos from MxTube? (y/n/[e]xit) " import
		fi
	echo
	if [ "$import" != "y" ] && [ "$import" != "n" ] && [ "$import" != "e" ];
	then
	echo "There are 3 options, yes, no or exit. I suggest you use one of them, moron. How fucking hard is this?
"
	else
	break
	fi
	done
			if [ "$import" = "e" ];
			then
			exit
			fi
			if [ "$import" = "$Yes" ];
			then
			importedfrommxtube="1"
			touch /var/mobile/Media/FFaac-Settings/mxtubeimported
			chown mobile:mobile /var/mobile/Media/FFaac-Settings/mxtubeimported
			while true
			do
			read -p "Import all videos or just specific ones? ([a]ll / [s]pecific) " importallspecific
			echo
				if [ "$importallspecific" != "a" ] && [ "$importallspecific" != "s" ];
				then
				echo "There are two fucking choices, use one of them.
				"
				else
				break
				fi
			done
				if [ "$importallspecific" = "a" ];
				then
				mkdir /var/mobile/Media/importedvideosfrommxtube
				chown mobile:mobile /var/mobile/Media/importedvideosfrommxtube
					if [ -e "/var/mobile/Media/thms" ];
					then
					echo 
					else
					mkdir /var/mobile/Media/thms
					echo 
					fi
				find /var/mobile/Media/MxTube -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/thms
				done
				#insert downloading video here
					if [ "$mxtubecontent" = "" ];
					then
					echo "Couldn't import videos from MxTube. Nothing to import.
					"
					exit
					else
					if [ -e /var/mobile/Media/DontAskMe ];
					then
					mkdir /var/mobile/Media/mxtmp
					while read line
					do
						if [ -e /var/mobile/Media/MxTube/"$line" ];
						then
						mv /var/mobile/Media/MxTube/"$line" /var/mobile/Media/mxtmp/
						fi
					done < /var/mobile/Media/DontAskMe
					fi
					find /var/mobile/Media/MxTube -type f | while read Vid
					do
					tmpage=$(echo "${Vid}" | cut -d '/' -f6)
						if [ "$tmpage" = "tmp" ];
						then
						echo "FFaac will not import downloading files. Not importing ${Vid}.
Run FFaac again when your download is finished.
"
						else
						mv "${Vid}" /var/mobile/Media/Convert/
						fi
					done
					if [ -e /var/mobile/Media/mxtmp ];
					then
					find /var/mobile/Media/mxtmp -type f | while read Vid
					do
					mv "$Vid" /var/mobile/Media/MxTube/
					done
					rmdir /var/mobile/Media/mxtmp
					if [ "$(ls /var/mobile/Media/Convert)" != "" ];
					then
					echo "All videos imported
					"
					fi
					fi
					fi 
				find /var/mobile/Media/thms -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/MxTube
				done
				fi
	
				if [ "$importallspecific" = "s" ];
				then
					if [ -e "/var/mobile/Media/thms" ];
					then
					echo
					else
					mkdir /var/mobile/Media/thms
					fi
				find /var/mobile/Media/MxTube -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/thms
				done
				mkdir /var/mobile/Media/importedvideosfrommxtube
				find /var/mobile/Media/MxTube -type f | while read Vid
				do
				tmpage=$(echo "${Vid}" | cut -d '/' -f6)
					if [ "$tmpage" = "tmp" ];
					then
					echo "FFaac will not import downloading files. Not importing ${Vid}.
Run FFaac again when your download is finished and you want to convert that new file."
					else
					mv "${Vid}" /var/mobile/Media/importedvideosfrommxtube
					fi
				done
				fi
				#From here	
				if [ -e /var/mobile/Media/DontAskMe ];
				then
				while read line
				do
					if [ -e /var/mobile/Media/importedvideosfrommxtube/"$line" ];
					then
					mv /var/mobile/Media/importedvideosfrommxtube/"$line" /var/mobile/Media/MxTube/
					fi
				done < /var/mobile/Media/DontAskMe
				fi
				Current=$(ls /var/mobile/Media/importedvideosfrommxtube)
				while true
				do
				echo "$Current" > /var/mobile/Media/ffaac.mxtubespecific.tmp
				chown mobile:mobile /var/mobile/Media/ffaac.mxtubespecific.tmp
				Currentfile=$(head -1 /var/mobile/Media/ffaac.mxtubespecific.tmp)
					if [ "$Current" != "" ];
					then
					chown mobile:mobile /var/mobile/Media/ffaac.mxtubespecific.tmp
						read -p "Import $Currentfile? ([y]es/[n]o/[s]tart ripping/no, [d]on't ask me again) " importcurrent
						if [ "$importcurrent" = $Yes ];
						then
						mv /var/mobile/Media/importedvideosfrommxtube/"$Currentfile" /var/mobile/Media/Convert
						echo "$Currentfile imported
						"
						echo "$Current" > /var/mobile/Media/ffaac.mxtubespecific.tmp
						chown mobile:mobile /var/mobile/Media/ffaac.mxtubespecific.tmp
						fi
						if [ "$importcurrent" = "d" ];
						then
						echo "$Currentfile" >> /var/mobile/Media/DontAskMe
						chown mobile:mobile /var/mobile/Media/DontAskMe
						mv /var/mobile/Media/importedvideosfrommxtube/"$Currentfile" /var/mobile/Media/MxTube
						echo "
---
$Currentfile not imported and you won't be asked again, to be asked again, delete the file DontAskMe in /var/mobile/Media/ using iFile, ssh or iPhone Browser
---
						"
						fi
						if [ "$importcurrent" = $No ];
						then
						mv /var/mobile/Media/importedvideosfrommxtube/"$Currentfile" /var/mobile/Media/MxTube
						echo "$Currentfile not imported
						"
						fi
						if [ "$importcurrent" = "s" ];
						then
						Current=""
						find /var/mobile/Media/importedvideosfrommxtube -type f | while read Vid
						do
						mv "${Vid}" /var/mobile/Media/MxTube
						done
						echo
						else
							if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
							then
							Current=$(ls /var/mobile/Media/importedvideosfrommxtube)
							echo
							fi
						fi	
					else
					if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
					then
					find /var/mobile/Media/importedvideosfrommxtube/ -type f | while read Vid
					do
					mv "$Vid" /var/mobile/Media/MxTube
					done
					fi
					contentafterimport=$(ls /var/mobile/Media/Convert/)								
						if [ "$contentafterimport" = "" ];
						then
							if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
							then
							rm -f /var/mobile/Media/ffaac.mxtubespecific.tmp
							rmdir /var/mobile/Media/importedvideosfrommxtube/
							echo "Nothing imported
Your Convert folder is still empty, maybe you should try to filling something in first."
							exit
							fi
						fi
					if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
					then	
					rm -f /var/mobile/Media/ffaac.mxtubespecific.tmp
					rmdir /var/mobile/Media/importedvideosfrommxtube/
					fi
					break
					fi
				done
				#till here
				find /var/mobile/Media/thms -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/MxTube
				done 
				rmdir /var/mobile/Media/thms
			fi
			if [ "$import" = "$No" ];
			then	
			echo "Your Convert folder is still empty, maybe you should try to filling something in first."
			exit
			fi
		else
			if [ -d /var/mobile/Media/YourTube ];
			then
				if [ "$(ls /var/mobile/Media/Convert/)" = "" ];
				then
					if [ "$importedfromyourtube" = "1" ];
					then
					echo "Your Convert folder is still empty, maybe you should try to filling something in first.
"
					exit
					fi
				read -p "Import videos from YourTube? (y/n) " yourimpot
					if [ "$yourimpot" = "y" ];
					then
					YourTube
						if [ "$(ls /var/mobile/Media/Convert/)" = "" ];
						then
						echo "Your Convert folder is still empty, maybe you should try to filling something in first."
						exit
						fi
					else
					echo "Your Convert folder is still empty, maybe you should try to filling something in first."
					exit
					fi
				fi
			else
			echo "Your Convert folder is empty, you cannot convert nothing, silly you!

Tip:Download MxTube from Cydia and get a few Videos (it's free!)"
			exit
			fi
		fi
fi
else
manuallyimported=y
fi








#Actual Conversion
if [ ! -e /var/mobile/Media/FFaac-Settings/cuttingoff ];
then
read -p "Do you want to cut some of the files? (y/n)" cutyes
else
cutyes=n
fi

echo
if [ ! -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
then
	if [ "$manuallyimported" = "y" ] || [ $importedfromyourtube = "1" ];
	then
	putondontaskme="n"
	else
	read -p "Do you want to put the file(s) of this conversion on the \"Don't Ask Me Again\"-List? (y/n): " putondontaskme
	fi
	if [ "$putondontaskme" = "y" ];
	then
	touch /var/mobile/Media/FFaac-Settings/dontaskmeputtage
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/dontaskmeputtage
	fi
fi

if [ "$cutyes" = "$Yes" ];
then

	if [ $importedfrommxtube = "0" ] && [ $importedfromyourtube = "0" ];
	then
	read -p "Do you want to delete the source files? (y/n)" delcutyes
	echo
	else
	delcutyes="n"
	fi
	if [ "$delcutyes" = "$Yes" ];
	then
	cd /var/mobile/Media/Convert/
	ls > /var/mobile/Media/ffaac.filesconverted.tmp
	chown mobile:mobile "/var/mobile/Media/ffaac.filesconverted.tmp"
	filesconverted=$(cat /var/mobile/Media/ffaac.filesconverted.tmp)
	while true
	do
	Content=$(ls /var/mobile/Media/Convert)
		if [ "$Content" != "" ];
		then
		echo "$Content" > /var/mobile/Media/ffaac.tmp
		chown mobile:mobile /var/mobile/Media/ffaac.tmp
		Current=$(head -1 "/var/mobile/Media/ffaac.tmp")
		ls > /var/mobile/Media/ffaac.filesconverted.tmp
		chown mobile:mobile "/var/mobile/Media/ffaac.filesconverted.tmp"
		filesconverted=$(cat /var/mobile/Media/ffaac.filesconverted.tmp)
		######################new
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" 0>>/var/mobile/Duration 1>>/var/mobile/Duration 2>>/var/mobile/Duration
		chown mobile:mobile /var/mobile/Duration
		Dur=$(expr $(cat /var/mobile/Duration | grep "Duration" | cut -d ':' -f4 | cut -c1-2) + $(expr $(cat /var/mobile/Duration | grep "Duration" | cut -d ':' -f3) "*" 60))
		rm -f /var/mobile/Duration
		######################/new
		#Audio Preview from here
		#
		#
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -t 5 /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Playing first 5 seconds
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		#
		#
		#Until here
		read -p "How many seconds do you want to cut off of the start of ${Current}? Enter number of seconds or simply 0.: " ssec
		######################new
		echo
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -ss $(expr $Dur - 5) /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Playing last 5 seconds
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		read -p "How many seconds do you want to cut off of the end of ${Current}? Enter number of seconds or simply 0.: " esec
		eesec=$(expr $Dur - $esec)
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -ss "$ssec" -t $(expr $ssec + 3) /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null &
		wait $!
		echo "Your song will start here:
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -ss $(expr $eesec - 3) -t "$eesec" /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null
		echo "And end like this:
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		read -p "Is that ok? (y/n) " oklikethis
		######################/new
		Basename="$(basename "${Current}")"
			if [ "$importedfrommxtube" = "1" ];
			then
			Newname="$(echo ${Basename} | cut -d '.' -f1 | cut -d '-' -f1)"
			else
			Newname="$(echo ${Basename} | cut -d '.' -f1)"
			fi
		#Ending
		Ending=$(echo "$Basename" | cut -d '.' -f2 | tr '[a-z]' '[A-Z]')
			if [ "$Ending" = "3GP" ] || [ "$Ending" = "MP4" ] || [ "$Ending" = "AAC" ];
			then
			codeccopy="-acodec copy "
			else
			codeccopy=""
			fi
		#/Ending
		######################new
		if [ "$oklikethis" = "y" ];
		then
			if [ "$ssec" != "0" ];
			then
				if [ "$esec" = "0" ];
				then
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -ss "$ssec" -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				else
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -ss "$ssec" -t "$eesec" -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				fi
			else
				if [ "$esec" = "0" ];
				then
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				else
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -t "$eesec" -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				fi
			fi
		if [ -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
		then
		echo "${Current}" >> /var/mobile/Media/DontAskMe
		fi
		echo "${Newname}.aac" >> "/var/mobile/Media/My Music/log"
		chown mobile:mobile "/var/mobile/Media/My Music/log"
		echo "${Newname}" >> "/var/mobile/Media/My Music/log2"
		chown mobile:mobile "/var/mobile/Media/My Music/log2"
		rm -f "$Current"
		fi
		######################/new
		else
		rm -f /var/mobile/Media/ffaac.tmp
			if [ $pwntunes = 1 ];
			then
			echo "$haspwntunes"
			else
			echo "$nopwntunes"
			fi
			echo "Files converted:
${filesconverted}
-----------
"
		if [ -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
		then
		echo "${Current}" >> /var/mobile/Media/DontAskMe
		fi
		#rm -f /var/mobile/Media/ffaac.filesconverted.tmp
		break
		fi
	done
	else
	cd /var/mobile/Media/Convert/
	ls > /var/mobile/Media/ffaac.filesconverted.tmp
	chown mobile:mobile "/var/mobile/Media/ffaac.filesconverted.tmp"
	filesconverted=$(cat /var/mobile/Media/ffaac.filesconverted.tmp)
	while true
	do
	Content=$(ls /var/mobile/Media/Convert)
		if [ "$Content" != "" ];
		then
		echo "$Content" > /var/mobile/Media/ffaac.tmp
		Current=$(head -1 "/var/mobile/Media/ffaac.tmp")
		chown mobile:mobile /var/mobile/Media/ffaac.tmp
		ls > /var/mobile/Media/ffaac.filesconverted.tmp
		chown mobile:mobile /var/mobile/Media/ffaac.filesconverted.tmp
		filesconverted=$(cat /var/mobile/Media/ffaac.filesconverted.tmp)
		######################new
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" 0>>/var/mobile/Duration 1>>/var/mobile/Duration 2>>/var/mobile/Duration
		chown mobile:mobile /var/mobile/Duration
		Dur=$(expr $(cat /var/mobile/Duration | grep "Duration" | cut -d ':' -f4 | cut -c1-2) + $(expr $(cat /var/mobile/Duration | grep "Duration" | cut -d ':' -f3) "*" 60))
		rm -f /var/mobile/Duration
		######################new
		#Audio Preview from here
		#
		#
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -t 5 /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Playing first 5 seconds
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		#
		#
		#Until here
		read -p "How many seconds do you want to cut off of the start of ${Current}? Enter number of seconds or simply 0.: " ssec
		######################new
		echo
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -ss $(expr $Dur - 5) /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Playing last 5 seconds
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		read -p "How many seconds do you want to cut off of the end of ${Current}? Enter number of seconds or simply 0.: " esec
		eesec=$(expr $Dur - $esec)
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -ss "$ssec" -t $(expr $ssec + 3) /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Your song will start here:
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		nohup ffmpeg -i "/var/mobile/Media/Convert/${Current}" -vn -acodec copy -ss $(expr $eesec - 3) -t "$eesec" /var/mobile/Media/PreviewFFaac.aac 0>/dev/null 1>/dev/null 2>/dev/null 
		echo "And end like this:
		"
		play /var/mobile/Media/PreviewFFaac.aac 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewFFaac.aac
		read -p "Is that ok? (y/n) " oklikethis
		######################/new
		Basename="$(basename "${Current}")"
		if [ "$importedfrommxtube" = "1" ];
		then
		Newname="$(echo ${Basename} | cut -d '.' -f1 | cut -d '-' -f1)"
		else
		Newname="$(echo ${Basename} | cut -d '.' -f1)"
		fi
		#Ending
		Ending=$(echo "$Basename" | cut -d '.' -f2 | tr '[a-z]' '[A-Z]')
		if [ "$Ending" = "3GP" ] || [ "$Ending" = "MP4" ] || [ "$Ending" = "AAC" ];
		then
		codeccopy="-acodec copy "
		else
		codeccopy=""
		fi
		#/Ending######################new
		if [ "$oklikethis" = "y" ];
		then
			if [ "$ssec" != "0" ];
			then
				if [ "$esec" = "0" ];
				then
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -ss "$ssec" -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				else
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -ss "$ssec" -t "$eesec" -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				fi
			else
				if [ "$esec" = "0" ];
				then
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				else
				ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -t "$eesec" -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
				wait $!
				fi
			fi
		if [ -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
		then
		echo "${Current}" >> /var/mobile/Media/DontAskMe
		fi
		echo "${Newname}.aac" >> "/var/mobile/Media/My Music/log"
		chown mobile:mobile "/var/mobile/Media/My Music/log"
		echo "${Newname}" >> "/var/mobile/Media/My Music/log2"
		chown mobile:mobile "/var/mobile/Media/My Music/log2"
			if [ $importedfrommxtube = "0" ];
			then
				if [ $importedfromyourtube = "0" ];
				then
				mv -f /var/mobile/Media/Convert/"${Current}" "/var/mobile/Media/${Oldfiles}/"
				else
				currnomp4="$(echo "${Current}" | cut -c1-$(expr $(echo -n ${Current} | wc -m) - 4))"
				mv -f /var/mobile/Media/Convert/"${Current}" "/var/mobile/Media/YourTube/$(grep -m 1 "$currnomp4" /var/mobile/Media/YourTubeFileNames | cut -d '#' -f1)"
				fi
			else
			mv -f /var/mobile/Media/Convert/"${Current}" "/var/mobile/Media/MxTube/"
			fi
		fi
		######################/new
		else
		rm -f /var/mobile/Media/ffaac.tmp
			if [ $pwntunes = 1 ];
			then
			echo "$haspwntunes"
			else
			echo "$nopwntunes"
			fi
			echo "Files converted:
${filesconverted}
-----------
"
		if [ -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
		then
		echo "${Current}" >> /var/mobile/Media/DontAskMe
		fi
		#rm -f /var/mobile/Media/ffaac.filesconverted.tmp
		rm -f /var/mobile/Media/ffaac.tmp
		break
		fi
	done
	fi
fi

if [ $cutyes = $No ];
then

	if [ $importedfrommxtube = "0" ] && [ $importedfromyourtube = "0" ];
	then
	read -p "Do you want to delete the source files? (y/n)" nocutdelyes
	else
	nocutdelyes="n"
	fi
	if [ $nocutdelyes = $Yes ];
	then
	cd /var/mobile/Media/Convert/
	ls > /var/mobile/Media/ffaac.filesconverted.tmp
	chown mobile:mobile /var/mobile/Media/ffaac.filesconverted.tmp
	filesconverted=$(cat /var/mobile/Media/ffaac.filesconverted.tmp)
	while true
	do
	Content=$(ls /var/mobile/Media/Convert)
		if [ "$Content" != "" ];
		then
		echo "$Content" > /var/mobile/Media/ffaac.tmp
		Current=$(head -1 "/var/mobile/Media/ffaac.tmp")
		chown mobile:mobile /var/mobile/Media/ffaac.tmp
		Basename="$(basename "${Current}")"
		if [ "$importedfrommxtube" = "1" ];
		then
		Newname="$(echo ${Basename} | cut -d '.' -f1 | cut -d '-' -f1)"
		else
		Newname="$(echo ${Basename} | cut -d '.' -f1)"
		fi
		#Ending
		Ending=$(echo "$Basename" | cut -d '.' -f2 | tr '[a-z]' '[A-Z]')
		if [ "$Ending" = "3GP" ] || [ "$Ending" = "MP4" ] || [ "$Ending" = "AAC" ];
		then
		codeccopy="-acodec copy"
		else
		codeccopy=""
		fi
		#/Ending
		ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac" &
		wait $!
		echo "${Newname}.aac" >> "/var/mobile/Media/My Music/log"
		chown mobile:mobile "/var/mobile/Media/My Music/log"
		echo "${Newname}" >> "/var/mobile/Media/My Music/log2"
		chown mobile:mobile "/var/mobile/Media/My Music/log2"
		if [ -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
		then
		echo "${Current}" >> /var/mobile/Media/DontAskMe
		fi
		#rm -f /var/mobile/Media/ffaac.filesconverted.tmp
		rm -f /var/mobile/Media/Convert/"${Current}"
		else
		rm -f /var/mobile/Media/ffaac.tmp
			if [ $pwntunes = 1 ];
			then
			echo "$haspwntunes"
			else
			echo "$nopwntunes"
			fi
			echo "Files converted:
${filesconverted}
-----------
"
		break
		fi
	done
	fi	
	if [ $nocutdelyes = $No ];
	then
	ls /var/mobile/Media/Convert/ > /var/mobile/Media/ffaac.filesconverted.tmp
	chown mobile:mobile /var/mobile/Media/ffaac.filesconverted.tmp
	filesconverted=$(cat /var/mobile/Media/ffaac.filesconverted.tmp)
	while true
	do
	Content=$(ls /var/mobile/Media/Convert)
		if [ "$Content" != "" ];
		then
		echo "$Content" > /var/mobile/Media/ffaac.tmp
		Current=$(head -1 "/var/mobile/Media/ffaac.tmp")
		chown mobile:mobile /var/mobile/Media/ffaac.tmp
		echo "-----------
$Current 
-----------"
		Basename="$(basename "${Current}")"
			if [ "$importedfrommxtube" = "1" ];
			then
			Newname="$(echo ${Basename} | cut -d '.' -f1 | cut -d '-' -f1)"
			else
			Newname="$(echo ${Basename} | cut -d '.' -f1)"
			fi
			#Ending
		Ending=$(echo "$Basename" | cut -d '.' -f2 | tr '[a-z]' '[A-Z]')
			if [ "$Ending" = "3GP" ] || [ "$Ending" = "MP4" ] || [ "$Ending" = "AAC" ];
			then
			codeccopy="-acodec copy "
			else
			codeccopy=""
			fi
			#/Ending
		ffmpeg -i /var/mobile/Media/Convert/"${Current}" -vn -acodec copy -ab 192k "/var/mobile/Media/My Music/${Newname}.aac"  &
		wait $!
		echo "${Newname}.aac" >> "/var/mobile/Media/My Music/log"
		chown mobile:mobile "/var/mobile/Media/My Music/log"
		echo "${Newname}" >> "/var/mobile/Media/My Music/log2"
		chown mobile:mobile "/var/mobile/Media/My Music/log2"
			if [ -e /var/mobile/Media/FFaac-Settings/dontaskmeputtage ];
			then
			echo "${Current}" >> /var/mobile/Media/DontAskMe
			fi
			#rm -f /var/mobile/Media/ffaac.filesconverted.tmp
			if [ $importedfrommxtube = "0" ];
			then
				if [ $importedfromyourtube = "0" ];
				then
				mv -f /var/mobile/Media/Convert/"${Current}" "/var/mobile/Media/${Oldfiles}/"
				else
				currnomp4="$(echo "${Current}" | cut -c1-$(expr $(echo -n ${Current} | wc -m) - 4))"
				mv -f /var/mobile/Media/Convert/"${Current}" "/var/mobile/Media/YourTube/$(grep -m 1 "$currnomp4" /var/mobile/Media/YourTubeFileNames | cut -d '#' -f1)"
				fi
			else
			mv -f /var/mobile/Media/Convert/"${Current}" "/var/mobile/Media/MxTube/"
			fi
		else
		rm -f /var/mobile/Media/ffaac.tmp
			if [ $pwntunes = 1 ];
			then
			echo "$haspwntunes"
			else
			echo "$nopwntunes"
			fi
			echo "Files converted:
${filesconverted}
-----------
"
			break
			fi
		done
		fi
	fi

if [ "$putondontaskme" = "y" ];
then
rm -f /var/mobile/Media/FFaac-Settings/dontaskmeputtage
fi

if [ -e /var/mobile/Media/importedvideosfrommxtube ];
then
rmdir /var/mobile/Media/importedvideosfrommxtube
fi
if [ -e "/var/mobile/Media/My Music/log" ];
then
echo "Converted filenames in aac:"
cat "/var/mobile/Media/My Music/log"
echo "-----------"
fi


#Logfile
if [ -e "/var/mobile/Media/FFaac-Conversion-Logs" ];
then
	if [ -e "/var/mobile/Media/FFaac-Conversion-Logs/newlayout" ];
	then
	echo
	else
	mkdir /var/mobile/Media/FFaac-Conversion-Logs/newlayout
	chown mobile:mobile /var/mobile/Media/FFaac-Conversion-Logs/newlayout
	fi
echo
else
mkdir /var/mobile/Media/FFaac-Conversion-Logs
mkdir /var/mobile/Media/FFaac-Conversion-Logs/newlayout
chown mobile:mobile /var/mobile/Media/FFaac-Conversion-Logs /var/mobile/Media/FFaac-Conversion-Logs/newlayout
fi
date +%Y.%m.%d-%H:%M > /var/mobile/dateatm
chown mobile:mobile /var/mobile/dateatm
date=$(cat /var/mobile/dateatm)
echo "---Files Converted---
" > "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
chown mobile:mobile "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
cat /var/mobile/Media/ffaac.filesconverted.tmp >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
rm -f /var/mobile/Media/ffaac.filesconverted.tmp
echo "
---New files---
" >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
cat "/var/mobile/Media/My Music/log" >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"

if [ ! -e /var/mobile/Media/FFaac-Settings/mxtubesafety ];
then
	if [ -e /var/mobile/Media/FFaac-Settings/mxtubeimported ] || [ -e /var/mobile/Media/RingRing-Settings/mxtubeimported ];
	then
	rm -f /var/mobile/Media/FFaac-Settings/mxtubeimported
	fi
fi
	
if [ ! -e /var/mobile/Media/FFaac-Settings/mp3off ];
then	
echo "


---------------MP3 Conversion---------------"

#MP3
read -p "Your files have been converted to AAC format. You can stop here or convert them to MP3. Do you want to convert these files to mp3 to set ID3 tags? This will take a long time but can easily run in background on iPad, iPod 3G/4, iPhone 3GS/4.
!!!!!!!!!!!!!!!!
!Important Note!
!!!!!!!!!!!!!!!!
If you're using MobileTerminal on OS4 or higher you NEED backgrounder installed, this terminal does NOT have native backgrounding.

Convert to MP3 now? (y/n) " Mp3
if [ "$Mp3" = "y" ];
then
echo "
Warning, your AAC-audio files are being processed now and can only be listened to in iFile in /var/mobile/Media/Convert/, PwnTunes will not find them while converting.
"
sleep 2
while true
do
if [ ! -e /var/mobile/Media/FFaac-Settings/dontalertme ] && [ ! -e /var/mobile/Media/FFaac-Settings/alwaysalertme ];
then
rm -f /var/mobile/Media/FFaac-Settings/alertme 2>/dev/null
read -p "
Do you want to be alerted with a popup window after every processed file and display how many files are left? ([y]es/[n]o/[a]lways/no, [d]on't ask me again): " alertme
	if [ "$alertme" = "y" ];
	then
	touch /var/mobile/Media/FFaac-Settings/alertme
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/alertme
	break
	fi
	if [ "$alertme" = "a" ];
	then
	touch /var/mobile/Media/FFaac-Settings/alwaysalertme
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/alwaysalertme
	break
	fi
	if [ "$alertme" = "n" ];
	then
	break
	fi
	if [ "$alertme" = "d" ];
	then
	touch /var/mobile/Media/FFaac-Settings/dontalertme
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/dontalertme
	echo "
This won't be asked again, go to FFaac-Settings by typing \"setffaac\" to change this."
	sleep 3
	break
	fi
	if [ "$alertme" != "y" ] && [ "$alertme" != "n" ] && [ "$alertme" != "d" ] && [ "$alertme" != "a" ];
	then
	echo "
	Please use one of the four options y, n, a or d.
	
	"
	fi
else
break
fi
done

if [ -e /var/mobile/Media/FFaac-Settings/alwaysalertme ];
then
touch /var/mobile/Media/FFaac-Settings/alertme
chown mobile:mobile /var/mobile/Media/FFaac-Settings/alertme
fi

if [ ! -e /var/mobile/Media/FFaac-Settings/nolyrics ] && [ ! -e /var/mobile/Media/FFaac-Settings/alwayslyrics ];
then
read -p "Do you want to download the lyrics and covers for these songs? This will require a valid 3G/EDGE/GPRS/WLAN connection.
If you don't have an unlimited data plan, additional charges may apply. I'm not responsible for your data usage ;)

Download lyrics and covers? ([a]lways/[y]es/[n]ot this time/[ne]ver, thanks) " downloadlyric
	if [ "$downloadlyric" = "ne" ];
	then
	touch /var/mobile/Media/FFaac-Settings/nolyrics
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/nolyrics
	fi
	if [ "$downloadlyric" = "a" ];
	then
	touch /var/mobile/Media/FFaac-Settings/alwayslyrics
	chown mobile:mobile /var/mobile/Media/FFaac-Settings/alwayslyrics
	fi
fi
if [ -e /var/mobile/Media/FFaac-Settings/alwayslyrics ];
then
downloadlyric="y"
fi
if [ -e /var/mobile/Media/mp3tmp ];
then
ls /var/mobile/Media/mp3tmp | while read line
do
mv "/var/mobile/Media/mp3tmp/$line" "/var/mobile/Media/My Music/$line"
done
rmdir /var/mobile/Media/mp3tmp
fi
mkdir /var/mobile/Media/mp3tmp
chown mobile:mobile /var/mobile/Media/mp3tmp
#import on mp3
while read line
do
mv "/var/mobile/Media/My Music/$line" /var/mobile/Media/mp3tmp
done < "/var/mobile/Media/My Music/log"

while true
do
if [ -e /var/mobile/Media/FFaac-Settings/makeallmp3 ];
then
find /var/mobile/Media/mp3tmp -type f | while read i
do
mv "$i" /var/mobile/Media/Convert
done
fi
mp3ls=$(ls /var/mobile/Media/mp3tmp)
echo "$mp3ls" > /var/mobile/Media/mp3ls.tmp
chown mobile:mobile /var/mobile/Media/mp3ls.tmp
mP3=$(head -1 /var/mobile/Media/mp3ls.tmp)
if [ "$mP3" != "" ];
then
read -p "Make $mP3 an MP3? (y/n) " makemp3yuh
if [ "$makemp3yuh" = "y" ];
then
mv "/var/mobile/Media/mp3tmp/$mP3" "/var/mobile/Media/Convert/$mP3"
else
mv "/var/mobile/Media/mp3tmp/$mP3" "/var/mobile/Media/My Music/$mP3"
fi
else
break
fi
done
rmdir /var/mobile/Media/mp3tmp
############################################
if [ "$(ls /var/mobile/Media/Convert)" = "" ];
then
echo "You imported no AACs for conversion."
else
if [ -e /var/mobile/mp3titles.tmp ];
then
rm -f /var/mobile/mp3titles.tmp
fi
if [ -e /var/mobile/mp3albums.tmp ];
then
rm -f /var/mobile/mp3albums.tmp
fi
if [ -e /var/mobile/mp3author.tmp ];
then
rm -f /var/mobile/mp3author.tmp
fi
if [ -e /var/mobile/mp3file.tmp ];
then
rm -f /var/mobile/mp3file.tmp
fi

cd /var/mobile/Media/Convert
while true
do

if [ -z "$(ls /var/mobile/Media/Convert)" ];
then
break
fi
file=$(ls /var/mobile/Media/Convert | head -1)
echo "$file" >> /var/mobile/mp3file.tmp
chown mobile:mobile /var/mobile/mp3file.tmp
Basename=$(basename "$file")
B=$(echo "$Basename" | cut -d '.' -f1)
echo "Processing file: $B
"
	if [ $importedfromyourtube = 1 ];
	then
		if [ -e /var/mobile/Media/FFaac-Settings/yourtitlenames ];
		then
		title=$(echo $B)
		else
			if [ ! -e /var/mobile/Media/FFaac-Settings/titlefromnameoff ];
			then
			read -p "Title from name for $B? (y/n) " titley
			else
			titley="n"
			fi
		fi
	else
		if [ ! -e /var/mobile/Media/FFaac-Settings/titlefromnameoff ];
		then
		read -p "Title from name for $B? (y/n) " titley
		else
		titley="n"
		fi
	fi

if [ "$titley" = "y" ];
then
title=$(echo $B)
echo "$title" >> /var/mobile/mp3titles.tmp
chown mobile:mobile /var/mobile/mp3titles.tmp
else
while true
do
	if [ $importedfromyourtube = 1 ];
	then
		if [ -e /var/mobile/Media/FFaac-Settings/yourtitlenames ];
		then
		title="$B"
		else
		read -p "Title
-qqq after your input to correct a mistake
Choice or Title: " title
		fi
	else
	read -p "Title
-qqq after your input to correct a mistake
Choice or Title: " title
	fi
echo
if [ $(expr $(echo "$title" | wc -m) ">" 4) = 1 ];
then
ttz=$(echo "$title" | cut -c$(expr $(echo "$title" | wc -m) - 3)-$(echo "$title" | wc -m))
else
ttz=zzz
fi
if [ "$ttz" != "qqq" ] && [ "$title" != "" ];
then
break
else
	if [ "$title" = "" ];
	then
	echo "Please do not write empty ID3-Tags"
	fi
fi
done
title=$(echo "$title" | tr ' ' '%' | awk '
{  
  n=split($0,array,"%")
  for (i=1;i<=n;i++) {
x=toupper (substr(array[i],1,1)) substr(array[i],2)
    printf("%s",x)
if (i<n) { printf ("%s"," ") }
  }
  printf("%s","\n")  
}')
echo "$title" >> /var/mobile/mp3titles.tmp
chown mobile:mobile /var/mobile/mp3titles.tmp
fi

while true
do
if [ ! -e /var/mobile/mp3albums.tmp ];
then
echo "Processing file: $B
"
read -p "Album
-qqq after your input to correct a mistake
Option or Album: " album
echo
if [ $(expr $(echo "$album" | wc -m) ">" 4) = 1 ];
then
ttz=$(echo "$album" | cut -c$(expr $(echo "$album" | wc -m) - 3)-$(echo "$album" | wc -m))
else
ttz=zzz
fi
	if [ "$album" != "" ];
	then
		if [ "$ttz" != "qqq" ];
		then
		break
		fi
	else
	echo "Please do not write empty ID3-Tags"
	fi
else
echo "Processing file: $B
"
read -p "Album or one of the following options 
-p to list previous
-pp to use the last
-qqq after your input to correct a mistake
Option or Album: " album
echo
if [ $(expr $(echo "$album" | wc -m) ">" 4) = 1 ];
then
ttz=$(echo "$album" | cut -c$(expr $(echo "$album" | wc -m) - 3)-$(echo "$album" | wc -m))
else
ttz=zzz
fi
	if [ $album = p ];
	then
	album=""
	cat -n /var/mobile/mp3albums.tmp
	read -p "Enter the album's number or p to enter the title yourself: " album
	echo
		if [ $album = p ];
		then
		album=""
		else
		is_integer=$(echo $album | grep -q '^-\?[0-9]\+$' || echo NaN)
			if [ "$is_integer" != "" ];
			then
			echo "The NUMBER has to be numeric, duh!"
			album=""
			else
			album=$(cat /var/mobile/mp3albums.tmp | head -$album | tail -1)
			break
			fi
		fi
	else
		if [ "$album" != "" ];
		then
			if [ "$album" = "pp" ];
			then
			album="$(cat /var/mobile/mp3albums.tmp | tail -1)"
			fi
			if [ "$ttz" != "qqq" ];
			then
			break
			fi
		else
		echo "Please do not write empty ID3-Tags"
		fi
	fi
fi
done
album=$(echo "$album" | tr ' ' '%' | awk '
{  
  n=split($0,array,"%")
  for (i=1;i<=n;i++) {
x=toupper (substr(array[i],1,1)) substr(array[i],2)
    printf("%s",x)
if (i<n) { printf ("%s"," ") }
  }
  printf("%s","\n")  
}')
echo "$album" >> /var/mobile/mp3albums.tmp
chown mobile:mobile /var/mobile/mp3albums.tmp
#################################
while true
do
if [ ! -e /var/mobile/mp3author.tmp ];
then
echo "Processing file: $B
"
read -p "Interpret
-qqq after input to correct a mistake
Option or Interpret: " interpret
echo
	if [ $(expr $(echo "$interpret" | wc -m) ">" 4) = 1 ];
	then
	ttz=$(echo "$interpret" | cut -c$(expr $(echo "$interpret" | wc -m) - 3)-$(echo "$interpret" | wc -m))
	else
	ttz=zzz
	fi
	if [ "$interpret" != "" ];
	then
		if [ "$ttz" != "qqq" ];
		then
		break
		fi
	else
	echo "Please do not write empty ID3-Tags"
	fi
else
echo "Processing file: $B
"
read -p "Interpret or one of the following options 
-p to list previous
-pp to use the last
-qqq after your input to correct a mistake
Option or Interpret: " interpret
echo
	if [ $(expr $(echo "$interpret" | wc -m) ">" 4) = 1 ];
	then
	ttz=$(echo "$interpret" | cut -c$(expr $(echo "$interpret" | wc -m) - 3)-$(echo "$interpret" | wc -m))
	else
	ttz=zzz
	fi
	if [ "$interpret" = p ];
	then
	interpret=""
	cat -n /var/mobile/mp3author.tmp
	read -p "Enter the interpret's number or p to enter the title yourself: " interpret
	echo
		if [ $interpret = p ];
		then
		interpret=""
		else
		is_integer=$(echo $interpret | grep -q '^-\?[0-9]\+$' || echo NaN)
			if [ "$is_integer" != "" ];
			then
			echo "The NUMBER has to be numeric, duh!"
			interpret=""
			else
			interpret=$(cat /var/mobile/mp3author.tmp | head -$interpret | tail -1)
			break
			fi
		fi
	else
		if [ "$interpret" != "" ];
		then
			if [ "$interpret" = "pp" ];
			then
			interpret="$(cat /var/mobile/mp3author.tmp | tail -1)"
			fi
			if [ "$ttz" != "qqq" ];
			then
			break
			fi
		else
		echo "Please do not write empty ID3-Tags"
		fi
	fi
fi
done
interpret=$(echo "$interpret" | tr ' ' '%' | awk '
{  
  n=split($0,array,"%")
  for (i=1;i<=n;i++) {
x=toupper (substr(array[i],1,1)) substr(array[i],2)
    printf("%s",x)
if (i<n) { printf ("%s"," ") }
  }
  printf("%s","\n")  
}')
echo "$interpret" >> /var/mobile/mp3author.tmp
chown mobile:mobile /var/mobile/mp3author.tmp
echo
echo
mv "$file" "/var/mobile/Media/Old Files"
done

if [ ! -e /var/mobile/Media/FFaac-Settings/createfolders ];
then
cat /var/mobile/mp3albums.tmp | sort | uniq -d | while read i
do
mkdir "/var/mobile/Media/My Music/$i"
chown mobile:mobile "/var/mobile/Media/My Music/$i"
done
fi

while read line
do
cp "/var/mobile/Media/Old Files/$line" /var/mobile/Media/Convert/
done < /var/mobile/mp3file.tmp

if [ ! -e /var/mobile/Media/FFaac-Settings/deleteaac ];
then
read -p "

Do you want to delete the AAC files? (y/n) " del
else
del="y"
fi


if [ ! -e /var/mobile/Media/FFaac-Settings/quality ];
then

read -p "

High or normal quality audio? (high will take longer) ([h]igh/[n]ormal) " hilow
else
	if [ "$(cat /var/mobile/Media/FFaac-Settings/quality)" = "high" ];
	then
	hilow=h
	fi
	if [ "$(cat /var/mobile/Media/FFaac-Settings/quality)" = "low" ];
	then
	hilow=n
	fi
fi


if [ "$hilow" = "h" ];
then
abrate="192k"
else
abrate="128k"
fi

if [ -e /var/mobile/Donation ];
then
echo
else
if [ ! -e /var/mobile/Media/FFaac-Settings/sound ];
then
read -p "

Would you like to donate while FFaac is converting your files to MP3? It will play a sound when it's done. (y/n) " donate
else
read -p "

Would you like to donate while FFaac is converting your files to MP3? (y/n) " donate
fi

if [ "$donate" = "y" ];
then
uiopen "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=679V7DHFCR8V6"
echo "Donated" > /var/mobile/Donation
chown mobile:mobile /var/mobile/Donation
else

echo "
Maybe next time ;)
This won't be asked again. If you reconsider, go to FFaac's Cydia page."
sleep 3
echo "Not donated, meh, at least he used it :)" > /var/mobile/Donation
chown mobile:mobile /var/mobile/Donation
fi
fi

nr=0
while true
do
nr=$(expr "$nr" + 1)
file=$(head -"$nr" /var/mobile/mp3file.tmp | tail -1)
lastfile=$(tail -1 /var/mobile/mp3file.tmp)
if [ "$file" != "$lastfile" ];
then
title=$(head -"$nr" /var/mobile/mp3titles.tmp | tail -1)
author=$(head -"$nr" /var/mobile/mp3author.tmp | tail -1)
album=$(head -"$nr" /var/mobile/mp3albums.tmp | tail -1)
ffmpeg -i "$file" -title "$title" -genre "$genre" -author "$author" -album "$album" -ab "$abrate" "/var/mobile/Media/My Music/$title".mp3 &
wait $!
echo "$file" >> /var/mobile/mp3filesconverted.tmp
chown mobile:mobile /var/mobile/mp3filesconverted.tmp
	if [ ! -e /var/mobile/Media/FFaac-Settings/createfolders ];
	then
		if [ -d "/var/mobile/Media/My Music/$album" ];
		then
		mv "/var/mobile/Media/My Music/$title.mp3" "/var/mobile/Media/My Music/$album/$title.mp3"
		fi
	fi
######################Lyrics######################
if [ ! -e /var/mobile/Media/FFaac-Settings/nolyrics ];
then
	if [ "$downloadlyric" = "y" ];
	then
	cd "/var/mobile/Media/My Lyrics/"
	interpretlyric=$(echo "$author")
	titlelyric=$(echo "$title")
		if [ "$(echo $interpretlyric | grep '/')" != "" ];
		then
		dnat1=0
		while true
		do
		dnat1=$(expr $dnat1 + 1)
		datpart1=$(echo $interpretlyric | cut -d '/' -f$dnat1)
			if [ "$datpart1" = "" ];
			then
			dnat1=$(expr $dnat1 - 1)
			datpart1=$(echo $interpretlyric | cut -d '/' -f$dnat1)
			break
			fi
		done
		fi
		if [ "$(echo $titlelyric | grep '/')" != "" ];
		then
		dnat2=0
		while true
		do
		dnat2=$(expr $dnat2 + 1)
		datpart2=$(echo $titlelyric | cut -d '/' -f$dnat2)
			if [ "$datpart2" = "" ];
			then
			dnat2=$(expr $dnat2 - 1)
			datpart2=$(echo $titlelyric | cut -d '/' -f$dnat2)
			break
			fi
		done
		fi
	interpretlyric2=$(echo "$interpretlyric" | tr '/' ' ')
		if [ ! -e "/var/mobile/Media/My Lyrics/$interpretlyric2/$titlelyric.txt" ];
		then
			if [ ! -d "/var/mobile/Media/My Lyrics/$interpretlyric2" ];
			then
			mkdir "/var/mobile/Media/My Lyrics/$interpretlyric2"
			chown mobile:mobile "/var/mobile/Media/My Lyrics/$interpretlyric2"
			fi
		interpretlyric=$(echo "$author" | tr ' ' '_')
		titlelyric=$(echo "$title" | tr ' ' '_')
		wget "http://lyrics.wikia.com/$interpretlyric:$titlelyric" 
			if [ "$(echo $interpretlyric | grep '/')" = "" ];
			then
				if [ "$(echo $titlelyric | grep '/')" = "" ];
				then
				tocat=$(ls | grep -i "$interpretlyric:$titlelyric")
				else
				tocat=$(ls | grep -i "$interpretlyric:$datpart2")
				titlelyric=$(echo "$titlelyric" | tr '/' ' ')
				fi
			else
				if [ "$(echo $interpretlyric | grep '/')" = "" ];
				then
				tocat=$(ls | grep -i "$datpart1:$titlelyric")
				interpretlyric=$(echo "$interpretlyric" | tr '/' ' ')
				else
				tocat=$(ls | grep -i "$datpart1:$datpart2")
				titlelyric=$(echo "$titlelyric" | tr '/' ' ')
				interpretlyric=$(echo "$interpretlyric" | tr '/' ' ')
				fi
			fi
		titlelyric=$(echo "$titlelyric" | tr '_' ' ')
		interpretlyric=$(echo "$interpretlyric" | tr '_' ' ')
		cat "$tocat" | grep "<br />&#" | sed 's/<\/div>\&\#/\n/g' | tail -1 | sed 's/<!--//g' | tr -d '&#' | sed 's/<br \/>/\n/g' | tr ';' ':' | awk '
{
  zeile = $0
  n = split(zeile,array,":")
  for (i=1;i<=n;i++) {
   printf("%c",array[i])
  }
  printf("%s","\n")
}' > "$interpretlyric2/$titlelyric.txt"
cat "$interpretlyric2/$titlelyric.txt" | awk '{printf ("%s%s", substr($0,1,length($0)-1), "\r\n")}' > "$interpretlyric2/$titlelyric2.txt"
mv "$interpretlyric2/$titlelyric2.txt" "$interpretlyric2/$titlelyric.txt"
		rm -f "$tocat"
		fi
	cd "/var/mobile/Media/Convert/"
	fi
fi
outputlyric=$(cat "/var/mobile/Media/My Lyrics/$interpretlyric2/$titlelyric.txt")
if [ "$outputlyric" = "" ];
then
echo "






Songtext could not be found."
rmdir "/var/mobile/Media/My Lyrics/$interpretlyric2" 2>/dev/null
if [ ! -e "/var/mobile/Media/My Lyrics/Lyrics Not Found.txt" ];
then
echo "The following lyrics could not be found:
" > "/var/mobile/Media/My Lyrics/Lyrics Not Found.txt"
fi
echo "$interpretlyric2  -  $titlelyric" >> "/var/mobile/Media/My Lyrics/Lyrics Not Found.txt"
rm -f "/var/mobile/Media/My Lyrics/$interpretlyric2/$titlelyric.txt" 2>/dev/null
rmdir "/var/mobile/Media/My Lyrics/$interpretlyric2/" 2>/dev/null
fi


albumcover="$album"
artistcover="$author"
echo "Downloading cover for album $album by $author"
artistcover=$(echo "$artistcover" | sed 's/\ /"%20"/g')
albumcover=$(echo "$albumcover" | sed 's/\ /"%20"/g')
wget -O albumart http://www.albumart.org/index.php?srchkey=$artistcover+$albumcover\&itempage=1\&newsearch=1\&searchindex=Music 2>/dev/null
CoverID=$(basename "$(cat albumart | grep amazon | head -1 | cut -d '"' -f4 | cut -d "%" -f1)")
wget -O albumart "http://www.amazon.com/gp/product/images/$CoverID/ref=dp_image_text_z_0?ie=UTF8&n=5174&s=music" 2>/dev/null
wget -O cover.jpg "$(grep "http://ecx.images-amazon.com/images/I/" albumart | head -1 | cut -d '"' -f4)" 2>/dev/null
rm -f albumart
if [ -d "/var/mobile/Media/My Music/$album" ];
then
mv cover.jpg "/var/mobile/Media/My Music/$album/cover.jpg"
else
mv cover.jpg "/var/mobile/Media/My Music/$album.jpg"
fi
######################/Lyrics######################
else
title=$(head -"$nr" /var/mobile/mp3titles.tmp | tail -1)
author=$(head -"$nr" /var/mobile/mp3author.tmp | tail -1)
album=$(head -"$nr" /var/mobile/mp3albums.tmp | tail -1)
ffmpeg -i "$file" -title "$title" -genre "$genre" -author "$author" -album "$album" -ab "$abrate" "/var/mobile/Media/My Music/$title".mp3 &
wait $!
echo "$file" >> /var/mobile/mp3filesconverted.tmp
chown mobile:mobile /var/mobile/mp3filesconverted.tmp
	if [ ! -e /var/mobile/Media/FFaac-Settings/createfolders ];
	then
		if [ -d "/var/mobile/Media/My Music/$album" ];
		then
		mv "/var/mobile/Media/My Music/$title.mp3" "/var/mobile/Media/My Music/$album/$title.mp3"
		fi
	fi
######################Lyrics######################
if [ ! -e /var/mobile/Media/FFaac-Settings/nolyrics ];
then
	if [ "$downloadlyric" = "y" ];
	then
	cd "/var/mobile/Media/My Lyrics/"
	interpretlyric=$(echo "$author")
	titlelyric=$(echo "$title")
		if [ "$(echo $interpretlyric | grep '/')" != "" ];
		then
		dnat1=0
		while true
		do
		dnat1=$(expr $dnat1 + 1)
		datpart1=$(echo $interpretlyric | cut -d '/' -f$dnat1)
			if [ "$datpart1" = "" ];
			then
			dnat1=$(expr $dnat1 - 1)
			datpart1=$(echo $interpretlyric | cut -d '/' -f$dnat1)
			break
			fi
		done
		fi
		if [ "$(echo $titlelyric | grep '/')" != "" ];
		then
		dnat2=0
		while true
		do
		dnat2=$(expr $dnat2 + 1)
		datpart2=$(echo $titlelyric | cut -d '/' -f$dnat2)
			if [ "$datpart2" = "" ];
			then
			dnat2=$(expr $dnat2 - 1)
			datpart2=$(echo $titlelyric | cut -d '/' -f$dnat2)
			break
			fi
		done
		fi
	interpretlyric2=$(echo "$interpretlyric" | tr '/' ' ')
		if [ ! -e "/var/mobile/Media/My Lyrics/$interpretlyric2/$titlelyric.txt" ];
		then
			if [ ! -d "/var/mobile/Media/My Lyrics/$interpretlyric2" ];
			then
			mkdir "/var/mobile/Media/My Lyrics/$interpretlyric2"
			chown mobile:mobile "/var/mobile/Media/My Lyrics/$interpretlyric2"
			fi
		interpretlyric=$(echo "$author" | tr ' ' '_')
		titlelyric=$(echo "$title" | tr ' ' '_')
		wget "http://lyrics.wikia.com/$interpretlyric:$titlelyric" 
			if [ "$(echo $interpretlyric | grep '/')" = "" ];
			then
				if [ "$(echo $titlelyric | grep '/')" = "" ];
				then
				tocat=$(ls | grep -i "$interpretlyric:$titlelyric")
				else
				tocat=$(ls | grep -i "$interpretlyric:$datpart2")
				titlelyric=$(echo "$titlelyric" | tr '/' ' ')
				fi
			else
				if [ "$(echo $interpretlyric | grep '/')" = "" ];
				then
				tocat=$(ls | grep -i "$datpart1:$titlelyric")
				interpretlyric=$(echo "$interpretlyric" | tr '/' ' ')
				else
				tocat=$(ls | grep -i "$datpart1:$datpart2")
				titlelyric=$(echo "$titlelyric" | tr '/' ' ')
				interpretlyric=$(echo "$interpretlyric" | tr '/' ' ')
				fi
			fi
		titlelyric=$(echo "$titlelyric" | tr '_' ' ')
		interpretlyric=$(echo "$interpretlyric" | tr '_' ' ')
		cat "$tocat" | grep "<br />&#" | sed 's/<\/div>\&\#/\n/g' | tail -1 | sed 's/<!--//g' | tr -d '&#' | sed 's/<br \/>/\n/g' | tr ';' ':' | awk '
{
  zeile = $0
  n = split(zeile,array,":")
  for (i=1;i<=n;i++) {
   printf("%c",array[i])
  }
  printf("%s","\n")
}' > "$interpretlyric2/$titlelyric.txt"
cat "$interpretlyric2/$titlelyric.txt" | awk '{printf ("%s%s", substr($0,1,length($0)-1), "\r\n")}' > "$interpretlyric2/$titlelyric2.txt"
mv "$interpretlyric2/$titlelyric2.txt" "$interpretlyric2/$titlelyric.txt"
		rm -f "$tocat"
		fi
	cd "/var/mobile/Media/Convert/"
	fi
fi
outputlyric=$(cat "/var/mobile/Media/My Lyrics/$interpretlyric2/$titlelyric.txt")
if [ "$outputlyric" = "" ];
then
echo "






Songtext could not be found."
rmdir "/var/mobile/Media/My Lyrics/$interpretlyric2" 2>/dev/null
if [ ! -e "/var/mobile/Media/My Lyrics/Lyrics Not Found.txt" ];
then
echo "The following lyrics could not be found:
" > "/var/mobile/Media/My Lyrics/Lyrics Not Found.txt"
fi
echo "$interpretlyric2  -  $titlelyric" >> "/var/mobile/Media/My Lyrics/Lyrics Not Found.txt"
rm -f "/var/mobile/Media/My Lyrics/$interpretlyric2/$titlelyric.txt" 2>/dev/null
rmdir "/var/mobile/Media/My Lyrics/$interpretlyric2/" 2>/dev/null
fi


albumcover="$album"
artistcover="$author"
echo "Downloading cover for album $album by $author"
artistcover=$(echo "$artistcover" | sed 's/\ /"%20"/g')
albumcover=$(echo "$albumcover" | sed 's/\ /"%20"/g')
wget -O albumart http://www.albumart.org/index.php?srchkey=$artistcover+$albumcover\&itempage=1\&newsearch=1\&searchindex=Music 2>/dev/null
CoverID=$(basename "$(cat albumart | grep amazon | head -1 | cut -d '"' -f4 | cut -d "%" -f1)")
wget -O albumart "http://www.amazon.com/gp/product/images/$CoverID/ref=dp_image_text_z_0?ie=UTF8&n=5174&s=music" 2>/dev/null
wget -O cover.jpg "$(grep "http://ecx.images-amazon.com/images/I/" albumart | head -1 | cut -d '"' -f4)" 2>/dev/null
rm -f albumart
if [ -d "/var/mobile/Media/My Music/$album" ];
then
mv cover.jpg "/var/mobile/Media/My Music/$album/"
else
mv cover.jpg "/var/mobile/Media/My Music/$album.jpg"
fi
######################/Lyrics######################
break
fi
if [ -e /var/mobile/Media/FFaac-Settings/alertme ];
then
processingtitle=$(head -$(expr $nr + 1) /var/mobile/mp3titles.tmp | tail -1)
sbalert -t FFaac -m "Now processing $processingtitle. This is file 
$(expr ${nr} + 1) of $(cat "/var/mobile/Media/My Music/log" | wc -l)"
fi
done


if [ "$del" = "y" ];
then
while read line
do
rm -f "/var/mobile/Media/Convert/$line"
rm -f "/var/mobile/Media/Old Files/$line" 2>/dev/null
done < /var/mobile/mp3file.tmp
else
while read line
do
mv "/var/mobile/Media/Convert/$line" "/var/mobile/Media/Old Files"
done < /var/mobile/mp3file.tmp
fi

if [ $importedfrommxtube = 1 ] || [ $importedfromyourtube = 1 ];
then
while read i
do
rm -f "/var/mobile/Media/Old Files/$i" 2>/dev/null
done < /var/mobile/mp3file.tmp
fi
if [ ! -e /var/mobile/Media/FFaac-Settings/sound ];
then
play /System/Library/Audio/UISounds/sms-received1.caf &
fi


#######################
#######################
#######################


if [ -e /var/mobile/mp3titles.tmp ];
then
rm -f /var/mobile/mp3titles.tmp
fi
if [ -e /var/mobile/mp3albums.tmp ];
then
rm -f /var/mobile/mp3albums.tmp
fi
if [ -e /var/mobile/mp3author.tmp ];
then
rm -f /var/mobile/mp3author.tmp
fi
if [ -e /var/mobile/mp3file.tmp ];
then
rm -f /var/mobile/mp3file.tmp
fi

find "/var/mobile/Media/My Music" -type f -iname "*.jpg" | while read i
do
	if [ "$(basename "${i}")" != "cover.jpg" ];
	then
	mv "$i" "/var/mobile/Media/My Music/$(echo $i | cut -d '/' -f6 | cut -d '.' -f1)/cover.jpg" 2>/dev/null
	fi
done

echo "


If it says \"Audio encoding failed\" that's normal, your music files are in /var/mobile/Media/My Music. Thanks for using, it's fun programming FFaac."

if [ "$downloadlyrics" = "y" ];
then
echo "
Your lyrics have been saved in /var/mobile/Media/My Lyrics/."
fi
fi
fi

TimeEnding=$(date +%s)
TimeNeededRaw=$(expr $TimeEnding - $TimeBeginning)
TimeNeededMinutes=$(expr $TimeNeededRaw / 60)
TimeNeededSeconds=$(expr $TimeNeededRaw % 60)
if [ "$(echo "$TimeNeededSeconds" | cut -c1)" = "-" ];
then
TimeNeededSeconds=$(echo "$TimeNeededSeconds" | cut -d '-' -f2)
fi

echo "
---Time Needed---
"  >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
echo -n "$TimeNeededMinutes:"  >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
echo -n "$TimeNeededSeconds"  >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
if [ -e "/var/mobile/mp3filesconverted.tmp" ];
then
echo "
---MP3 Conversion---
" >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
cat "/var/mobile/mp3filesconverted.tmp" >> "/var/mobile/Media/FFaac-Conversion-Logs/newlayout/$date.log"
rm -f /var/mobile/mp3filesconverted.tmp

echo -n "
Time Needed:"
echo -n " $TimeNeededMinutes:"
echo -n "$TimeNeededSeconds"

if [ -e /var/mobile/Media/FFaac-Settings/alertme ];
then
sbalert -t FFaac -m "FFaac has now converted all of your files. You'll 
find them in /var/mobile/Media/My Music/. Enjoy your music!"
fi
rm -f /var/mobile/Media/FFaac-Settings/alertme 2>/dev/null

fi

if [ -e /var/mobile/dateatm ];
then
rm -f /var/mobile/dateatm
fi
fi


#Mail
if [ ! -e /var/mobile/Media/FFaac-Settings/mailoff ];
then
read -p "
Would you like to send me a mail? Crash reports, other bugs, questions or just saying hi? (y/n) " sendmail
if [ "$sendmail" = "y" ];
then
uiopen "mailto:Schweinsfuss.Nasenbeutler@googlemail.com?subject=FFaac"
else
#Linking to RingRing
	if [ ! -e /var/mobile/Media/FFaac-Settings/otheroff ];
	then
		if [ ! -e /usr/bin/ringring ];
		then
		read -p "
Would you like to take a look at my other great app: RingRing?
Create ringtones right on your iDevice from your music library or MxTube (y/n) " openringring
			if [ "$openringring" = "y" ];
			then
			uiopen "cydia:///package/com.pigfoot.ringring"
			fi
		fi
	fi
fi
fi

if [ -e "/var/mobile/Media/ffaac.filesconverted.tmp" ];
then
rm -f /var/mobile/Media/ffaac.filesconverted.tmp
fi
if [ -e "/var/mobile/Media/My Music/log" ];
then
rm -f "/var/mobile/Media/My Music/log"
rm -f "/var/mobile/Media/My Music/log2"
fi

#Twitter
if [ -e "/var/mobile/Media/FFaac.sureidontwannatweet" ];
then
echo "
Bye."
else
read -p "Tweet this conversion on Twitter! Do you want to tweet this now for the lulz? (y/n) " tweetyesno
if [ $tweetyesno = $Yes ];
then
read -p "Username: " user
read -s -p "Password: " password
echo
tweet "$user" "$password" "LOL i just converted some stuff on my iDevice using #FFaac by @iph0nege3k , it's awesome lelz, go get it in Cydia! It's FREE!"
echo "Wat" > "/var/mobile/Media/FFaac.sureidontwannatweet"
chown mobile:mobile "/var/mobile/Media/FFaac.sureidontwannatweet"
fi
if [ $tweetyesno = $No ];
then
read -p "
Are you sure you do not want to tweet this? I mean FFaac is awesome. (y/n) " sure
	if [ $sure = $No ];
	then
	read -p "Username: " user
	read -s -p "Password: " password
	echo
	tweet "$user" "$password" "LOL i just converted some stuff on my iDevice using #FFaac by @iph0nege3k , it's awesome lelz, go get it in Cydia! It's FREE!"
	echo "Wat" > "/var/mobile/Media/FFaac.sureidontwannatweet"
	chown mobile:mobile "/var/mobile/Media/FFaac.sureidontwannatweet"
	fi
	if [ $sure = $Yes ];
	then
	read -p "
Last chance. Don't not not Tweet this? (Ha Ha, I'm using negation to trick your mind!)  (y/n) " lastchance
		if [ $lastchance = $Yes ];
		then
		echo "I knew I'd convince you."
		read -p "Username: " user
		read -s -p "Password: " password
		echo
		tweet "$user" "$password" "LOL i just converted some stuff on my iDevice using #FFaac by @iph0nege3k , it's awesome lelz, go get it in Cydia! It's FREE!"
		echo "Wat" > "/var/mobile/Media/FFaac.sureidontwannatweet"
		chown mobile:mobile "/var/mobile/Media/FFaac.sureidontwannatweet"
		else
		echo "
I knew I'd convince you. 
(I know you typed no, I just don't care)"
		sleep 1
		echo -n "."
		sleep 1
		echo -n "."
		sleep 1
		echo -n "."
		sleep 2
		echo "
Nah, just kidding."
		sleep 4
		read -p "
You sure? (y/n) " absolutelysure
			if [ $absolutelysure = $Yes ];
			then		
			echo "
Have a nice day...Asshole...
I'll remember you...
"
echo "Congratulations, you found me, what now eh?" > /var/mobile/Library/FFaac.sureno
echo "Wat" > "/var/mobile/Media/FFaac.sureidontwannatweet"
chown mobile:mobile "/var/mobile/Media/FFaac.sureidontwannatweet"
chown mobile:mobile /var/mobile/Library/FFaac.sureno
			fi
			if [ $absolutelysure = $No ];
			then		
			read -p "
So you want to tweet this? :) (y/n) " oktweetman
				if [ $oktweetman = $Yes ];
				then
				read -p "Username: " user
				read -s -p "Password: " password
				tweet "$user" "$password" "LOL i just converted some stuff on my iDevice using #FFaac by @iph0nege3k , it's awesome lelz, go get it in Cydia! It's FREE! I'm also an opportunist."
				echo "Wat" > "/var/mobile/Media/FFaac.sureidontwannatweet"
				chown mobile:mobile "/var/mobile/Media/FFaac.sureidontwannatweet"
				else
				echo "
Have a nice day...Asshole...
I'll remember you...
"
				echo "Congratulations, you found me, what now eh?" > /var/mobile/Library/FFaac.sureno
				chown mobile:mobile /var/mobile/Library/FFaac.sureno
				echo "Wat" > "/var/mobile/Media/FFaac.sureidontwannatweet"
				chown mobile:mobile "/var/mobile/Media/FFaac.sureidontwannatweet"
				fi
			
			fi
		fi
	fi
fi
fi

if [ "$anothertimecontent" != "" ];
then
	if [ "$importedfrommxtube" = "1" ];
	then
	find /var/mobile/Media/Convert -type f | while read ese
	do
	mv "$ese" /var/mobile/Media/MxTube/
	done
	fi
fi
