History

restyle

Serge Zirukin committed 16 years ago

Commit 9beb96c1 parent e771c7b1 file · +41 −82Browse files

Unified · Split

split2flac.sh+41−82
@@ -78,8 +78,7 @@ every time, only a filename. · 77 unmodified lines
78 Script will try to find CUE sheet if it wasn't specified."78 Script will try to find CUE sheet if it wasn't specified."
79 79
80# parse arguments80# parse arguments
81while [ "$1" ]81while [ "$1" ]; do
82do
83 case "$1" in82 case "$1" in
84 -o) DIR=$2; shift;;83 -o) DIR=$2; shift;;
85 -cue) CUE=$2; shift;;84 -cue) CUE=$2; shift;;
@@ -99,13 +98,11 @@ do · 13 unmodified lines
99 -h) eval "echo \"${HELP}\""; exit 0;;98 -h) eval "echo \"${HELP}\""; exit 0;;
100 -H) echo "${README}"; exit 0;;99 -H) echo "${README}"; exit 0;;
101 *)100 *)
102 if [ -r "${FILE}" ]101 if [ -r "${FILE}" ]; then
103 then
104 echo "Unknown option $1"102 echo "Unknown option $1"
105 eval "echo \"${HELP}\""103 eval "echo \"${HELP}\""
106 exit 1104 exit 1
107 elif [ ! -r "$1" ]105 elif [ ! -r "$1" ]; then
108 then
109 echo "Unable to read $1"106 echo "Unable to read $1"
110 exit 1107 exit 1
111 else108 else
@@ -120,30 +117,24 @@ VORBISCOMMENT="vorbiscomment -R -a" · 8 unmodified lines
120ID3TAG="id3tag -2"117ID3TAG="id3tag -2"
121 118
122# search for a cue sheet if not specified119# search for a cue sheet if not specified
123if [ -z "${CUE}" ]120if [ -z "${CUE}" ]; then
124then
125 CUE="${FILE}.cue"121 CUE="${FILE}.cue"
126 if [ ! -r "${CUE}" ]122 if [ ! -r "${CUE}" ]; then
127 then
128 CUE=$(echo ${FILE} | sed 's/[^\.]*$//')cue123 CUE=$(echo ${FILE} | sed 's/[^\.]*$//')cue
129 if [ ! -r "${CUE}" ]124 if [ ! -r "${CUE}" ]; then
130 then
131 # try to extract internal one125 # try to extract internal one
132 # MacOSX sed doesn't have 'I' (case insensitive) flag!126 # MacOSX sed doesn't have 'I' (case insensitive) flag!
133 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/[Cc][Uu][Ee][Ss][Hh][Ee][Ee][Tt]=//')127 CUESHEET=$(${METAFLAC} --show-tag=CUESHEET "${FILE}" 2>/dev/null | sed 's/[Cc][Uu][Ee][Ss][Hh][Ee][Ee][Tt]=//')
134 128
135 if [ -z "${CUESHEET}" ]129 if [ -z "${CUESHEET}" ]; then
136 then
137 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)130 CUESHEET=$(wvunpack -q -c "${FILE}" 2>/dev/null)
138 fi131 fi
139 132
140 if [ "${CUESHEET}" ]133 if [ "${CUESHEET}" ]; then
141 then
142 CUE="${TMPCUE}"134 CUE="${TMPCUE}"
143 echo "${CUESHEET}" > "${CUE}"135 echo "${CUESHEET}" > "${CUE}"
144 136
145 if [ $? -ne 0 ]137 if [ $? -ne 0 ]; then
146 then
147 echo "Unable to save internal cue sheet"138 echo "Unable to save internal cue sheet"
148 exit 1139 exit 1
149 fi140 fi
@@ -159,29 +150,23 @@ echo "Input file :" ${FILE:?"No input filename given. Use -h for help."} · 9 unmodified lines
159echo "Cue sheet :" ${CUE:?"No cue sheet"}150echo "Cue sheet :" ${CUE:?"No cue sheet"}
160 151
161# search for a front cover image152# search for a front cover image
162if [ ${NOPIC} -eq 1 ]153if [ ${NOPIC} -eq 1 ]; then
163then
164 unset PIC154 unset PIC
165elif [ -z "${PIC}" ]155elif [ -z "${PIC}" ]; then
166then
167 # try common names 156 # try common names
168 SDIR=$(dirname "${FILE}")157 SDIR=$(dirname "${FILE}")
169 158
170 for i in cover.jpg front_cover.jpg folder.jpg159 for i in cover.jpg front_cover.jpg folder.jpg; do
171 do160 if [ -r "${SDIR}/$i" ]; then
172 if [ -r "${SDIR}/$i" ]
173 then
174 PIC="${SDIR}/$i"161 PIC="${SDIR}/$i"
175 break162 break
176 fi163 fi
177 done164 done
178 165
179 # try to extract internal one166 # try to extract internal one
180 if [ -z "${PIC}" ]167 if [ -z "${PIC}" ]; then
181 then
182 ${METAFLAC} --export-picture-to="${TMPPIC}" "${FILE}" 2>/dev/null168 ${METAFLAC} --export-picture-to="${TMPPIC}" "${FILE}" 2>/dev/null
183 if [ $? -ne 0 ]169 if [ $? -ne 0 ]; then
184 then
185 echo "Unable to export internal front cover image"170 echo "Unable to export internal front cover image"
186 unset PIC171 unset PIC
187 else172 else
@@ -194,11 +179,9 @@ echo "Cover image :" ${PIC:-"not set"} · 6 unmodified lines
194echo "Output dir :" ${DIR:?"Output directory wasn't set"}179echo "Output dir :" ${DIR:?"Output directory wasn't set"}
195 180
196# file removal warning181# file removal warning
197if [ ${REMOVE} -eq 1 ]182if [ ${REMOVE} -eq 1 ]; then
198then
199 echo -n "Also remove original"183 echo -n "Also remove original"
200 if [ ${FORCE} -eq 1 ]184 if [ ${FORCE} -eq 1 ]; then
201 then
202 echo185 echo
203 else186 else
204 echo " if user says 'y'"187 echo " if user says 'y'"
@@ -206,8 +189,7 @@ then · 1 unmodified line
206fi189fi
207 190
208# save configuration if needed191# save configuration if needed
209if [ ${SAVE} -eq 1 ]192if [ ${SAVE} -eq 1 ]; then
210then
211 echo "DIR=\"${DIR}\"" > "${CONFIG}"193 echo "DIR=\"${DIR}\"" > "${CONFIG}"
212 echo "NOSUBDIRS=${NOSUBDIRS}" >> "${CONFIG}"194 echo "NOSUBDIRS=${NOSUBDIRS}" >> "${CONFIG}"
213 echo "NORENAME=${NORENAME}" >> "${CONFIG}"195 echo "NORENAME=${NORENAME}" >> "${CONFIG}"
@@ -230,10 +212,8 @@ YEAR=$(echo ${YEAR} | tr -d -C '[:digit:]') · 16 unmodified lines
230 212
231unset TAG_DATE213unset TAG_DATE
232 214
233if [ -n "${YEAR}" ]215if [ -n "${YEAR}" ]; then
234then216 if [ ${YEAR} -ne 0 ]; then
235 if [ ${YEAR} -ne 0 ]
236 then
237 TAG_DATE="${YEAR}"217 TAG_DATE="${YEAR}"
238 fi218 fi
239fi219fi
@@ -241,8 +221,7 @@ fi · 1 unmodified line
241echo221echo
242echo "Artist : ${TAG_ARTIST}"222echo "Artist : ${TAG_ARTIST}"
243echo "Album : ${TAG_ALBUM}"223echo "Album : ${TAG_ALBUM}"
244if [ -n "${TAG_DATE}" ]224if [ -n "${TAG_DATE}" ]; then
245then
246 echo "Year : ${TAG_DATE}"225 echo "Year : ${TAG_DATE}"
247fi226fi
248echo "Tracks : ${TRACKS_NUM}"227echo "Tracks : ${TRACKS_NUM}"
@@ -251,13 +230,11 @@ echo · 2 unmodified lines
251# prepare output directory230# prepare output directory
252OUT="${DIR}"231OUT="${DIR}"
253 232
254if [ ${NOSUBDIRS} -ne 1 ]233if [ ${NOSUBDIRS} -ne 1 ]; then
255then
256 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})234 DIR_ARTIST=$(echo ${TAG_ARTIST} | ${VALIDATE})
257 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})235 DIR_ALBUM=$(echo ${TAG_ALBUM} | ${VALIDATE})
258 236
259 if [ "${TAG_DATE}" ]237 if [ "${TAG_DATE}" ]; then
260 then
261 DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"238 DIR_ALBUM="${TAG_DATE} - ${DIR_ALBUM}"
262 fi239 fi
263 240
@@ -266,13 +243,11 @@ fi · 2 unmodified lines
266 243
267echo "Saving tracks to \"${OUT}\""244echo "Saving tracks to \"${OUT}\""
268 245
269if [ ${DRY} -ne 1 ]246if [ ${DRY} -ne 1 ]; then
270then
271 # create output dir247 # create output dir
272 mkdir -p "${OUT}"248 mkdir -p "${OUT}"
273 249
274 if [ $? -ne 0 ]250 if [ $? -ne 0 ]; then
275 then
276 echo "Failed to create output directory"251 echo "Failed to create output directory"
277 exit 1252 exit 1
278 fi253 fi
@@ -287,18 +262,15 @@ then · 8 unmodified lines
287 # split to tracks262 # split to tracks
288 cuebreakpoints "${CUE}" | \263 cuebreakpoints "${CUE}" | \
289 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"264 shnsplit -O never -o "${ENC}" -d "${OUT}" -t "%n" "${FILE}"
290 if [ $? -ne 0 ]265 if [ $? -ne 0 ]; then
291 then
292 echo "Failed to split"266 echo "Failed to split"
293 exit 1267 exit 1
294 fi268 fi
295 269
296 # prepare cover image270 # prepare cover image
297 if [ "${PIC}" ]271 if [ "${PIC}" ]; then
298 then
299 convert "${PIC}" -resize "${PIC_SIZE}" "${TMPPIC}"272 convert "${PIC}" -resize "${PIC_SIZE}" "${TMPPIC}"
300 if [ $? -eq 0 ]273 if [ $? -eq 0 ]; then
301 then
302 PIC="${TMPPIC}"274 PIC="${TMPPIC}"
303 else275 else
304 echo "Failed to convert cover image"276 echo "Failed to convert cover image"
@@ -312,8 +284,7 @@ echo · 7 unmodified lines
312echo "Setting tags"284echo "Setting tags"
313 285
314i=1286i=1
315while [ $i -le ${TRACKS_NUM} ]287while [ $i -le ${TRACKS_NUM} ]; do
316do
317 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}")288 TAG_TITLE=$(cueprint -n $i -t %t "${CUE}")
318 f="${OUT}/$(printf %02i $i).${FORMAT}"289 f="${OUT}/$(printf %02i $i).${FORMAT}"
319 FILE_TRACK=$(basename "$f" .${FORMAT})290 FILE_TRACK=$(basename "$f" .${FORMAT})
@@ -321,14 +292,11 @@ do · 1 unmodified line
321 292
322 echo "$i: ${TAG_TITLE}"293 echo "$i: ${TAG_TITLE}"
323 294
324 if [ ${NORENAME} -ne 1 ]295 if [ ${NORENAME} -ne 1 ]; then
325 then
326 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"296 FINAL="${OUT}/${FILE_TRACK} - ${FILE_TITLE}.${FORMAT}"
327 if [ ${DRY} -ne 1 ]297 if [ ${DRY} -ne 1 ]; then
328 then
329 mv "$f" "${FINAL}"298 mv "$f" "${FINAL}"
330 if [ $? -ne 0 ]299 if [ $? -ne 0 ]; then
331 then
332 echo "Failed to rename track file"300 echo "Failed to rename track file"
333 exit 1301 exit 1
334 fi302 fi
@@ -337,8 +305,7 @@ do · 2 unmodified lines
337 FINAL="$f"305 FINAL="$f"
338 fi306 fi
339 307
340 if [ ${DRY} -ne 1 ]308 if [ ${DRY} -ne 1 ]; then
341 then
342 case ${FORMAT} in309 case ${FORMAT} in
343 flac)310 flac)
344 ${METAFLAC} --remove-all-tags \311 ${METAFLAC} --remove-all-tags \
@@ -349,14 +316,12 @@ do · 4 unmodified lines
349 "${FINAL}" >/dev/null316 "${FINAL}" >/dev/null
350 RES=$?317 RES=$?
351 318
352 if [ -n "${TAG_DATE}" ]319 if [ -n "${TAG_DATE}" ]; then
353 then
354 ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" >/dev/null320 ${METAFLAC} --set-tag="DATE=${TAG_DATE}" "${FINAL}" >/dev/null
355 RES=$((${RES} + $?))321 RES=$((${RES} + $?))
356 fi322 fi
357 323
358 if [ -n "${PIC}" ]324 if [ -n "${PIC}" ]; then
359 then
360 ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" >/dev/null325 ${METAFLAC} --import-picture-from="${PIC}" "${FINAL}" >/dev/null
361 RES=$((${RES} + $?))326 RES=$((${RES} + $?))
362 fi327 fi
@@ -371,8 +336,7 @@ do · 8 unmodified lines
371 "${FINAL}" >/dev/null336 "${FINAL}" >/dev/null
372 RES=$?337 RES=$?
373 338
374 if [ -n "${TAG_DATE}" ]339 if [ -n "${TAG_DATE}" ]; then
375 then
376 ${ID3TAG} -y"${TAG_DATE}" "${FINAL}" >/dev/null340 ${ID3TAG} -y"${TAG_DATE}" "${FINAL}" >/dev/null
377 RES=$((${RES} + $?))341 RES=$((${RES} + $?))
378 fi342 fi
@@ -386,8 +350,7 @@ do · 7 unmodified lines
386 -t "TRACKNUMBER=$i" >/dev/null350 -t "TRACKNUMBER=$i" >/dev/null
387 RES=$?351 RES=$?
388 352
389 if [ -n "${TAG_DATE}" ]353 if [ -n "${TAG_DATE}" ]; then
390 then
391 ${VORBISCOMMENT} "${FINAL}" -t "DATE=${TAG_DATE}" >/dev/null354 ${VORBISCOMMENT} "${FINAL}" -t "DATE=${TAG_DATE}" >/dev/null
392 RES=$((${RES} + $?))355 RES=$((${RES} + $?))
393 fi356 fi
@@ -395,8 +358,7 @@ do · 1 unmodified line
395 *) echo "Unknown output format ${FORMAT}"; exit 1;;358 *) echo "Unknown output format ${FORMAT}"; exit 1;;
396 esac359 esac
397 360
398 if [ ${RES} -ne 0 ]361 if [ ${RES} -ne 0 ]; then
399 then
400 echo "Failed to set tags for track"362 echo "Failed to set tags for track"
401 exit 1363 exit 1
402 fi364 fi
@@ -410,18 +372,15 @@ done · 7 unmodified lines
410rm -f "${TMPPIC}"372rm -f "${TMPPIC}"
411rm -f "${TMPCUE}"373rm -f "${TMPCUE}"
412 374
413if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]375if [ ${DRY} -ne 1 -a ${REMOVE} -eq 1 ]; then
414then
415 YEP="n"376 YEP="n"
416 377
417 if [ ${FORCE} -ne 1 ]378 if [ ${FORCE} -ne 1 ]; then
418 then
419 echo -n "Are you sure you want to delete original? [y] >"379 echo -n "Are you sure you want to delete original? [y] >"
420 read YEP380 read YEP
421 fi381 fi
422 382
423 if [ "${YEP}" = "y" -o ${FORCE} -eq 1 ]383 if [ "${YEP}" = "y" -o ${FORCE} -eq 1 ]; then
424 then
425 rm -f "${FILE}"384 rm -f "${FILE}"
426 fi385 fi
427fi386fi

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