[an error occurred while processing this directive]

Скрипт для перекодирования коллекции музыкальных файлов
Понадобилось мне однажды перекодировать некоторое количество музыкальных
композиций из формата FLAC/APE/WAV в MP3.

encode_list.txt - содержит полные пути до директорий с исходными файлами (путь
не должен оканчиватся на "\")

В системе должны быть установлены утилиты flac, mac, lame. 

Приветствуется улучшенная версия скрипта. Хотя лично мне он понадобился всего один раз... 
но после небольших изменений он может стать еще полезнее, в некоторых случаях.


#!/bin/bash

# шаманское заклинание
IFS="
";
# конец шаманского заклинания

# чего и куда класть 
ENCODE_PATH=`pwd`;
ENCODE_LIST="encode_list.txt"

for i in `cat $ENCODE_LIST`; do
    FLAC_count=`find "$i" -name "*.flac" | wc -l`
    APE_count=`find "$i" -name "*.ape" | wc -l`
    WAV_count=`find "$i" -name "*.wav" | wc -l`
    echo "dir = '$i'";
    if [ $WAV_count -lt $FLAC_count ] && [ $APE_count -lt $FLAC_count ]
    then
	echo "FLAC detected";
	for j in "$i"/*.flac; do
	    out_name=`basename ${j/.flac/.mp3}`;
	    out_dir=`basename $i`
	    out_full="$ENCODE_PATH/$out_dir/$out_name";
	    mkdir "$ENCODE_PATH/$out_dir";
	    echo `date +"%T %y/%m/%d"` encoding "'"$out_name"'" >> $ENCODE_PATH/$out_dir/encode.log;
     flac -d "$j" -o - | lame -ms -v -V0 -h - "$out_full"; #>>
$ENCODE_PATH/$out_dir/encode.log 2>> $ENCODE_PATH/$out_dir/encode.log;
	done;
    elif [ $FLAC_count -lt $APE_count ] && [ $WAV_count -lt $APE_count ]
    then
	echo "APE detected";
	for j in "$i"/*.ape; do
	    out_name=`basename ${j/.ape/.mp3}`;
	    out_dir=`basename $i`
	    out_full="$ENCODE_PATH/$out_dir/$out_name";
	    mkdir "$ENCODE_PATH/$out_dir";
	    echo `date +"%T %y/%m/%d"` encoding "'"$out_name"'" >> $ENCODE_PATH/$out_dir/encode.log;
     mac "$j" - -d | lame -ms -v -V0 -h - "$out_full"; #>>
$ENCODE_PATH/$out_dir/encode.log 2>> $ENCODE_PATH/$out_dir/encode.log;
	done;
    else [ $FLAC_count -le $WAV_count ] && [ $APE_count -le $WAV_count ]
	echo "WAV detected";
	for j in "$i"/*.wav; do
	    out_name=`basename ${j/.wav/.mp3}`;
	    out_dir=`basename $i`
	    out_full="$ENCODE_PATH/$out_dir/$out_name";
	    mkdir "$ENCODE_PATH/$out_dir";
	    echo `date +"%T %y/%m/%d"` encoding "'"$out_name"'" >> $ENCODE_PATH/$out_dir/encode.log;
     lame -ms -v -V0 -h "$j" "$out_full"; #>> $ENCODE_PATH/$out_dir/encode.log
2>> $ENCODE_PATH/$out_dir/encode.log;
	done;
    fi;
done



Другой вариант



#!/bin/bash
# Copyright (C) 2007-2008 Vladimir V. Kamarzin <vvk@altlinux.org>
#
# Split one big audiofile (cdimage) to separate tracks
#
# This file 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 St, Fifth Floor, Boston, MA 02110-1301, USA.

#. shell-error

renice 19 -p $$ > /dev/null 2>&1 ||:

while read cuefile
do
       # get cuesheet filename
       cue="${cuefile##*/}"

       # object (filename without extension)
       obj=${cue%.cue}

       # relative path to object''s directory
       objdir="${cuefile%/*}"

       pushd "$objdir"

       # First, find all files that need decoding before process and decode it
       if [ -f "$obj".mp3 ]; then
               lame --decode "$obj".mp3 "$obj".wav || fatal "cannot decode $obj.mp3, exiting"

       elif [ -f "$obj".ogg ]; then
               oggdec "$obj".ogg || fatal "cannot decode $obj.ogg, exiting"
       fi

       # Next, split one-big-file. Use flac for loseless and ogg for lossy
       if [ -f "$obj".ape ]; then
               cuebreakpoints "$cue" | shnsplit -o ''flac flac --best -o %f -'' -t %n "$obj".ape \\
               || fatal "failed to split $obj.ape"

       elif [ -f "$obj".flac ]; then
               cuebreakpoints "$cue" | shnsplit -o ''flac flac --best -o %f -'' -t %n "$obj".flac \\
               || fatal "failed to split $obj.flac"

       elif [ -f "$obj".wav ]; then
               cuebreakpoints "$cue" | shnsplit -o ''cust ext=ogg oggenc -q 7 -o %f -'' -t %n "$obj".wav \\
               || fatal "failed to split $obj.wav"

       else
               fatal "$obj file not found, exiting"
       fi

       # Recode tags. Assume that russian tags has windows-1251 encoding
       case "$LANG" in
               ru_RU.KOI8-R) recode_to=koi8-r
                       ;;
               ru_RU.CP1251) recode_not_needed=1
                       ;;
               *) recode_to=utf8
       esac

       [ "$recode_not_needed" = 1 ] && ln -s "$cue" tmp.cue || recode -f 1251.."$recode_to" < "$cue" > tmp.cue \\
       || fatal "cannot recode cue: $cue"

       # Embed tags into tracks, rename tracks
       for (( i=1 ; i <= $(cueprint -d ''%N'' tmp.cue) ; ++i ))
       do
         NN=$(printf ''%02d'' $i)

         [ -s "$NN.flac" ] && {
           # Prepare track tags, filter out empty tags, embed the rest
           cueprint -n $i -t \\
           ''ARRANGER=%A\\nCOMPOSER=%C\\nGENRE=%G\\nMESSAGE=%M\\nTRACKNUMBER=%n\\nARTIST=%p\\nTITLE=%t\\nALBUM=%T\\n'' \\
               tmp.cue | egrep -v ''=$'' | metaflac --import-tags-from=- $NN.flac
           # rename NN.flac to "NN - TrackTitle.flac"
           mv $NN.flac "$NN - $(cueprint -n $i -t %t tmp.cue | sed -e "s,/,,g").flac"
         }

         [ -s "$NN.ogg" ] && {
           cueprint -n $i -t \\
           ''ARRANGER=%A\\nCOMPOSER=%C\\nGENRE=%G\\nCOMMENT=%M\\nTRACKNUMBER=%n\\nARTIST=%p\\nTITLE=%t\\nALBUM=%T\\n'' \\
               tmp.cue | egrep -v ''=$'' > tags.tmp
           vorbiscomment -a -c tags.tmp "$NN.ogg"
           mv $NN.ogg "$NN - $(cueprint -n $i -t %t tmp.cue | sed -e "s,/,,g").ogg"
         }

       done

      rm -f tmp.cue "$cue" "$obj".{flac,ape,mp3,ogg,wav} tags.tmp
       popd

done < <(find . -type f -iname "*.cue")
 
29.12.2008 , Автор: redstorm
Ключи: mp3, music, lame, converter, shell / Лицензия: CC-BY
Раздел:    Корень / Пользователю / Запись и обработка звука

[an error occurred while processing this directive]

[an error occurred while processing this directive]