Ubuntu Pastebin

Paste from minimec at Fri, 7 Jul 2017 21:53:19 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash

#cueape 0.1
#This script is intended to convert ape or flac + cue files to
#ogg vorbis or mp3 files, setting the tags to the correct value,
#obtained from the cue file.
#REQUIREMENTS:
#	-Oggenc installed (it comes with vorbis-tools) if you want to encode into Ogg Vorbis.
#	-lame installed if you want to encode into mp3
#	-mac to decode ape files (Monkey's Audio)
#	-flac to decode flac files.

#IF YOU FIND A BUG OR HAVE A SUGGESTION COMMENTO OR SIMPLY WANT TO CONTACT ME PLEASE MAIL ME TO
#rafadev_*@gmail.com  REMOVING THE "_*"
#This is done to prevent spamming

#Copyright (C) 2006  Rafael Ponieman - Buenos Aires, Argentina

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


#scripted by deX


case "$1" in
*.[aA][pP][eE] | *[fF][lL][aA][cC]	)
	if [ ! -f "$1" ] ; then
		echo "Input file $1 doesn't exist"
		exit 1
	fi
	if [ ! -f "$2" ]; then
		echo "Cue input file $2 doesn't exist"
		exit 1
	fi ;;
*	)
	echo "Error: invalid input parameters"
	exit ;;
esac

#Testing parameters
if [ "$3" != "-m" ] && [ "$3" != "-o" ] ; then
	echo -en "\033[1;31mInvalid parameters\n"
	echo -en "\033[1;37m"
	echo -en "Usage: cueape [input ape file] [input cue file] [parameters]\nParameters can be: -m for mp3 encoding or -o for ogg encoding.\n"
	exit 1
fi

#Need help with this one, coudn't solve it. I need to know how to check if a
#program actually exists and is accesible
#Checking for mac
#[ -f $(which 'maca' >> /dev/null) ] ||  {
#	echo -en "\033[1;31mYou must have mac in your PATH.\033[1;37m\nPlease install Monkey's Audio Codec\nYou can get it from http://sourceforge.net/projects/mac-port/\n"
#}


#Saving the position so as to return afterwards
olddir="$(pwd)"

#Going to target directory
cd "$(dirname "$1")"

#Checking for the output folder. If it's not there I create it
[ ! -d "Output" ] && mkdir -p "Output"
cp "$2" "Output/"

#Decompress
echo -en "\nCueape 0.1\n\n"
echo -en "\033[1;32mStarting conversion\n"

#Checking filetype by extension and decompressing
tmp="$(basename "$1")"
tmp="${tmp##*.}"

case "$tmp" in
[fF][lL][aA][cC]	)
	echo -en "\033[1;32mDecompressing FLAC file\n\n"
	echo -en "\033[1;37m"
	tm="$(basename "$1")"
	tm="${tm%.[fF][lL][aA][cC]}"
	out="$(flac "-d" "$1" -o "Output/${tm}.wav" )"
	;;
[aA][pP][eE]		)
	echo -en "\033[1;32mDecompressing APE file\n\n"
	echo -en "\033[1;37m"
	tm="$(basename "$1")"
	tm="${tm%.[aA][pP][eE]}"
	out="$(mac "$1" "Output/${tm}.wav" "-d")"
	;;
*			)
	echo "Error: line 99"
esac

cd "Output"
echo -en "\033[1;32m\nDecompression finished\n"
echo -en "\033[1;32mStarting reencoding\n\n"
echo -en "\033[1;37m"
if [ "$3" = "-o" ] ; then
	#Calling oggenc. Saving output for future checking
	out="$(oggenc -q 6 -o "$tm.ogg" "$tm.wav")"
	echo -en "\033[1;32m\nReencoding finished\n"
	echo -en "\033[1;32mSplitting\n\n"
	echo -en "\033[1;37m"
	out="$(mp3splt -c "$(basename "$2")" -o "@n+-+@t" "$tm.ogg")"
else
	#Calling lame. Saving output for future checking
	out="$(lame --preset standard "$tm.wav" "$tm.mp3")"
	echo -en "\033[1;32m\nReencoding finished\n"
	echo -en "\033[1;32mSplitting\n\n"
	echo -en "\033[1;37m"
	#Using framemode becaus this settings are for VBR
	out="$(mp3splt -f -c "$(basename "$2")" -o "@n+-+@t" "$tm.mp3")"
fi

#Delete obsolete files
if [ "$3" = "-o" ] ; then
	rm "$tm.ogg"
else
	rm "$tm.mp3"
fi
rm "$tm.wav" "$tm.flac.cue"

#add Genre/Date Tag
exiftool ../$tm.flac > tmp.txt
sed '/File/d' ./tmp.txt > tags.txt
genre="$(cat tags.txt | grep Genre | sed 's/^.*:/:/' | cut -b 3-)"
date="$(cat tags.txt | grep Date | sed 's/^.*:/:/' | cut -b 3-)"
rm tags.txt tmp.txt
if [ "$3" = "-o" ] ; then
	lltag -g "$genre" -d "$date" --yes *.ogg
else
	id3v2 -g "$genre" -y "$date" *.mp3
fi

#add picture
if [ ! -d "../cover.jpg" ] ; then
	cp ../cover.jpg cover.jpg
fi

if [ ! -d " cover.jpg" ] ; then
	if [ "$3" = "-o" ] ; then
#		jpg64="$(cat cover.jpg | base64)"
#		jpg64=$(base64 cover.jpg)
		for f in ./*.ogg; do
			oggart cover.jpg "$f";
			done
#	rm cover.jpg
else
		for f in ./*.mp3; do \
			ffmpeg -i "$f" -i cover.jpg -map_metadata 0 -map 0 -map 1 -acodec copy out-"${f#./}" \
			&& mv out-"${f#./}" "$f";
		done
	fi
fi

#change folder name
cd ..
folder="$(pwd | sed 's/^.*\//\//' | cut -b 2-)"
mv Output "$folder"

#Job done
echo -en "\033[1;32m\nProcessing finished successfully\n"
echo -en "\033[1;37m"
exit 0
Download as text