History

split2mp3 and split2ogg

Serge Zirukin committed 17 years ago

Commit 2d44a611 parent b60f91d1 file · +87 −30Browse files

Unified · Split

split2flac.sh+87−30
@@ -20,6 +20,12 @@ · 19 unmodified lines
20# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION20# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 22
23# Dependencies:
24# shntool, cuetools
25# SPLIT: flac, wavpack, mac
26# CONVERT: flac, id3lib, lame, vorbis-tools
27# ART: ImageMagick
28
23CONFIG="${HOME}/.split2flac"29CONFIG="${HOME}/.split2flac"
24TMPCUE="${HOME}/.split2flac_sheet.cue"30TMPCUE="${HOME}/.split2flac_sheet.cue"
25TMPPIC="${HOME}/.split2flac_cover.jpg"31TMPPIC="${HOME}/.split2flac_cover.jpg"
@@ -29,6 +35,8 @@ NORENAME=0 · 3 unmodified lines
29NOPIC=035NOPIC=0
30REMOVE=036REMOVE=0
31PIC_SIZE="192x192"37PIC_SIZE="192x192"
38FORMAT=$(echo $0 | sed 's/^.*2//;s/\..*//')
39FORMAT=${FORMAT:-"flac"}
32 40
33# load settings41# load settings
34eval $(cat "${CONFIG}" 2>/dev/null)42eval $(cat "${CONFIG}" 2>/dev/null)
@@ -42,25 +50,27 @@ FORCE=0 · 7 unmodified lines
42HELP="Usage: split2flac.sh [OPTIONS] FILE50HELP="Usage: split2flac.sh [OPTIONS] FILE
43 -o DIRECTORY * - set output directory51 -o DIRECTORY * - set output directory
44 -cue FILE - use file as a cue sheet52 -cue FILE - use file as a cue sheet
53 -f FORMAT - use specified output format (current is \${FORMAT})
45 -c FILE * - use file as a cover image54 -c FILE * - use file as a cover image
46 -nc * - do not set any cover images55 -nc * - do not set any cover images
47 -cs WxH * - set cover image size (current is ${PIC_SIZE})56 -cs WxH * - set cover image size (current is \${PIC_SIZE})
48 -d * - create artist/album subdirs57 -d * - create artist/album subdirs
49 -nd * - do not create any subdirs58 -nd * - do not create any subdirs
50 -r * - rename tracks to include title59 -r * - rename tracks to include title
51 -nr * - do not rename tracks (numbers only, e.g. '01.flac')60 -nr * - do not rename tracks (numbers only, e.g. '01.\${FORMAT}')
52 -p - dry run61 -p - dry run
53 -D * - delete original file62 -D * - delete original file
54 -nD * - do not remove the original63 -nD * - do not remove the original
55 -f - force deletion without asking64 -f - force deletion without asking
56 -s - save configuration to \"${CONFIG}\"65 -s - save configuration to \"\${CONFIG}\"
57 -h - print this message66 -h - print this message
58 -H - print README67 -H - print README
59 68
60* - option has effect on configuration if -s option passed.69* - option has effect on configuration if -s option passed.
61NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one."70NOTE: '-c some_file.jpg -s' only allows cover images, it doesn't set a default one.
71Supported FORMATs: flac, mp3, ogg."
62 72
63README="split2flac.sh splits one big APE/FLAC/WV file to FLAC tracks with tagging and renaming.73README="split2flac.sh splits one big APE/FLAC/WV file to FLAC/MP3/OGG tracks with tagging and renaming.
64 It's better to pass '-p' option to see what will happen when actually splitting tracks.74 It's better to pass '-p' option to see what will happen when actually splitting tracks.
65 You may want to pass '-s' option for the first run to save default configuration75 You may want to pass '-s' option for the first run to save default configuration
66(output dir, cover image size, etc.) so you won't need to pass a lot of options76(output dir, cover image size, etc.) so you won't need to pass a lot of options
@@ -73,6 +83,7 @@ do · 6 unmodified lines
73 case $1 in83 case $1 in
74 -o) DIR=$2; shift;;84 -o) DIR=$2; shift;;
75 -cue) CUE=$2; shift;;85 -cue) CUE=$2; shift;;
86 -f) FORMAT=$2; shift;;
76 -c) NOPIC=0; PIC=$2; shift;;87 -c) NOPIC=0; PIC=$2; shift;;
77 -nc) NOPIC=1;;88 -nc) NOPIC=1;;
78 -cs) PIC_SIZE=$2; shift;;89 -cs) PIC_SIZE=$2; shift;;
@@ -85,13 +96,13 @@ do · 6 unmodified lines
85 -nD) REMOVE=0;;96 -nD) REMOVE=0;;
86 -f) FORCE=1;;97 -f) FORCE=1;;
87 -s) SAVE=1;;98 -s) SAVE=1;;
88 -h) echo "${HELP}"; exit 0;;99 -h) eval "echo \"${HELP}\""; exit 0;;
89 -H) echo "${README}"; exit 0;;100 -H) echo "${README}"; exit 0;;
90 *)101 *)
91 if [ -r "${FILE}" ]102 if [ -r "${FILE}" ]
92 then103 then
93 echo "Unknown option $1"104 echo "Unknown option $1"
94 echo "${HELP}"105 eval "echo \"${HELP}\""
95 exit 1106 exit 1
96 elif [ ! -r "$1" ]107 elif [ ! -r "$1" ]
97 then108 then
@@ -105,6 +116,8 @@ do · 7 unmodified lines
105done116done
106 117
107METAFLAC="metaflac --no-utf8-convert"118METAFLAC="metaflac --no-utf8-convert"
119VORBISCOMMENT="vorbiscomment -R -a"
120ID3TAG="id3tag -2"
108 121
109# search for a cue sheet if not specified122# search for a cue sheet if not specified
110if [ -z "${CUE}" ]123if [ -z "${CUE}" ]
@@ -142,7 +155,7 @@ then · 31 unmodified lines
142fi155fi
143 156
144# print some info and check arguments157# print some info and check arguments
145echo "Input file :" ${FILE:?"${HELP}"}158echo "Input file :" ${FILE:?"No input filename given. Use -h for help."}
146echo "Cue sheet :" ${CUE:?"No cue sheet"}159echo "Cue sheet :" ${CUE:?"No cue sheet"}
147 160
148# search for a front cover image161# search for a front cover image
@@ -264,9 +277,16 @@ then · 115 unmodified lines
264 exit 1277 exit 1
265 fi278 fi
266 279
280 case ${FORMAT} in
281 flac) ENC="flac flac -8 - -o %f";;
282 mp3) ENC="cust ext=mp3 lame --preset extreme - %f";;
283 ogg) ENC="cust ext=ogg oggenc -q 10 - -o %f";;
284 *) echo "Unknown output format ${FORMAT}"; exit 1;;
285 esac
286
267 # split to tracks287 # split to tracks
268 cuebreakpoints "${CUE}" | \288 cuebreakpoints "${CUE}" | \
269 shnsplit -O never -o "flac flac -8 - -o %f" -d "${OUT}" -t "%n" "${FILE}"289 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
270 if [ $? -ne 0 ]290 if [ $? -ne 0 ]
271 then291 then
272 echo "Failed to split"292 echo "Failed to split"
@@ -295,15 +315,15 @@ i=1 · 22 unmodified lines
295while [ $i -le ${TRACKS_NUM} ]315while [ $i -le ${TRACKS_NUM} ]
296do316do
297 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}")317 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}")
298 f="${OUT}/$(printf %02i $i).flac"318 f="${OUT}/$(printf %02i $i).${FORMAT}"
299 FILE_TRACK=$(basename "$f" .flac)319 FILE_TRACK=$(basename "$f" .${FORMAT})
300 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})320 FILE_TITLE=$(echo ${TAG_TITLE} | ${VALIDATE})
301 321
302 echo "$i: ${TAG_TITLE}"322 echo "$i: ${TAG_TITLE}"
303 323
304 if [ ${NORENAME} -ne 1 ]324 if [ ${NORENAME} -ne 1 ]
305 then325 then
306 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.flac"326 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
307 if [ ${DRY} -ne 1 ]327 if [ ${DRY} -ne 1 ]
308 then328 then
309 mv "$f" "${FINAL}"329 mv "$f" "${FINAL}"
@@ -319,25 +339,62 @@ do · 9 unmodified lines
319 339
320 if [ ${DRY} -ne 1 ]340 if [ ${DRY} -ne 1 ]
321 then341 then
322 ${METAFLAC} --remove-all-tags \342 case ${FORMAT} in
323 --set-tag="ARTIST=${TAG_ARTIST}" \343 flac)
324 --set-tag="ALBUM=${TAG_ALBUM}" \344 ${METAFLAC} --remove-all-tags \
325 --set-tag="TITLE=${TAG_TITLE}" \345 --set-tag="ARTIST=${TAG_ARTIST}" \
326 --set-tag="TRACKNUMBER=$i" \346 --set-tag="ALBUM=${TAG_ALBUM}" \
327 "${FINAL}"347 --set-tag="TITLE=${TAG_TITLE}" \
328 RES=$?348 --set-tag="TRACKNUMBER=$i" \
329 349 "${FINAL}" >/dev/null
330 if [ -n "${TAG_DATE}" ]350 RES=$?
331 then351
332 ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}"352 if [ -n "${TAG_DATE}" ]
333 RES=$((${RES} + $?))353 then
334 fi354 ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" >/dev/null
355 RES=$((${RES} + $?))
356 fi
357
358 if [ -n "${PIC}" ]
359 then
360 ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" >/dev/null
361 RES=$((${RES} + $?))
362 fi
363 ;;
364
365 mp3)
366 ${ID3TAG} "-a${TAG_ARTIST}" \
367 "-A${TAG_ALBUM}" \
368 "-s${TAG_TITLE}" \
369 "-t$i" \
370 "-T${TRACKS_NUM}" \
371 "${FINAL}" >/dev/null
372 RES=$?
373
374 if [ -n "${TAG_DATE}" ]
375 then
376 ${ID3TAG} -y"${TAG_DATE}" "${FINAL}" >/dev/null
377 RES=$((${RES} + $?))
378 fi
379 ;;
380
381 ogg)
382 ${VORBISCOMMENT} "${FINAL}" \
383 -t "ARTIST=${TAG_ARTIST}" \
384 -t "ALBUM=${TAG_ALBUM}" \
385 -t "TITLE=${TAG_TITLE}" \
386 -t "TRACKNUMBER=$i" >/dev/null
387 RES=$?
388
389 if [ -n "${TAG_DATE}" ]
390 then
391 ${VORBISCOMMENT} "${FINAL}" -t "DATE=${TAG_DATE}" >/dev/null
392 RES=$((${RES} + $?))
393 fi
394 ;;
395 *) echo "Unknown output format ${FORMAT}"; exit 1;;
396 esac
335 397
336 if [ -n "${PIC}" ]
337 then
338 ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}"
339 RES=$((${RES} + $?))
340 fi
341 398
342 if [ ${RES} -ne 0 ]399 if [ ${RES} -ne 0 ]
343 then400 then

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t