I wrote this script years ago, and now I need to mod it so I can have it resample the files in ram to save read write on my ssd does any one have any tips on how to do that?
Code:
#!/bin/bash
working_dir="/run/media/userx/4TB_esaystore/Music"
move_to="/run/media/userx/4TB_esaystore/Resampled_Music"
script_dir=/home/userx/scripts
no_tags=/run/media/userx/4TB_esaystore/music_no_tags
orginals=/run/media/userx/4TB_esaystore/orginal_music
manyfiles="$(find "$working_dir" -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" | wc -l)"
while read FILE ; do
c=$FILE
xpath=${c%/*}
xbase=${c##*/}
xfext=${xbase##*.}
xpref=${xbase%.*}
path=${xpath}
pref=${xpref}
ext=${xfext}
newFile="$pref"."mp3"
#removes and replaces leaving the band directory and its subdirectories
#to put the resmaped music into
NoTags=${path/$working_dir/$no_tags}
keep_orginals=${path/$working_dir/$orginals}
bitrate="$(exiftool -p '$AudioBitrate' "$FILE")"
#strips kpbs
bitrate=${bitrate% *}
echo "$bitrate"
# set check bitrate values low / high
rate2l=128
rate2h=128
artist="$(exiftool -p '$Artist' "$FILE")"
album="$(exiftool -p '$Album' "$FILE")"
title="$(exiftool -p '$Title' "$FILE")"
genre="$(exiftool -p '$Genre' "$FILE")"
##############################################################
# Resampling with LAME 99.9.5
# if MP3 is out of limits then re-sample it if not then send it through
# skip resampling saves time
###
# flac -cd "$f" | lame -b 320 - "${f%.*}".mp3
if [[ "${ext}" == 'flac' ]] ; then
{
echo "got Dflack file $ext"
flac -cd "$FILE" | lame -V2 -b 128 -F --vbr-new -m j -q 2 - "$newFile"
#rm -v "$FILE"
mid3v2 -a "$artist" "$script_dir"/"$newFile"
mid3v2 -A "$album" "$script_dir"/"$newFile"
mid3v2 -t "$title" "$script_dir"/"$newFile"
mid3v2 -g "$genre" "$script_dir"/"$newFile"
if [[ -n "$artist" && -n "$album" ]] ; then
{
NewPath2="$move_to"/"$artist"/"$album"
mkdir -p "$NewPath2"
mv -vf "$script_dir"/"$newFile" "$NewPath2"
echo;echo "moving orginal"
mkdir -pv "$keep_orginals"
mv -vf "$FILE" "$keep_orginals"
echo;echo "orginal moved"
}
else
{
mkdir -p "$NoTags"
mv -vf "$script_dir"/"$newFile" "$NoTags"
echo;echo "moving orginal"
mkdir -pv "$keep_orginals"
mv -vf "$FILE" "$keep_orginals"
echo;echo "orginal moved"
}
fi
} # if start bitrate < 128 or start bitrate > 160 then resample
elif [[ "${bitrate%.*}" -gt "${rate2h}" ]] ; then
{
lame -V2 -b 128 -F --vbr-new -m j -q 2 "$FILE" "$newFile"
mid3v2 -a "$artist" "$script_dir"/"$newFile"
mid3v2 -A "$album" "$script_dir"/"$newFile"
mid3v2 -t "$title" "$script_dir"/"$newFile"
mid3v2 -g "$genre" "$script_dir"/"$newFile"
if [[ -n "$artist" && -n "$album" ]] ; then
{
NewPath2="$move_to"/"$artist"/"$album"
mkdir -p "$NewPath2"
mv -vf "$script_dir"/"$newFile" "$NewPath2"
echo;echo "moving orginal"
mkdir -pv "$keep_orginals"
mv -vf "$FILE" "$keep_orginals"
echo;echo "orginal moved"
}
else
{
mkdir -p "$NoTags"
mv -vf "$script_dir"/"$newFile" "$NoTags"
echo;echo "moving orginal"
mkdir -pv "$keep_orginals"
mv -vf "$FILE" "$keep_orginals"
echo;echo "orginal moved"
}
fi
}
elif [[ -n "$artist" && -n "$album" ]] ; then
{
NewPath2="$move_to"/"$artist"/"$album"
mkdir -p "$NewPath2"
mv -vf "$FILE" "$NewPath2"
}
else
{
mkdir -p "$NoTags"
mv -vf "$script_dir"/"$newFile" "$NoTags"
echo;echo "moving orginal"
mkdir -pv "$keep_orginals"
mv -vf "$FILE" "$keep_orginals"
echo;echo "orginal moved"
}
fi
echo;echo;echo;echo "counting down $((manyfiles--))"
#done <<<"$(find "$working_dir" "$working_dir2" -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"
done <<<"$(find "$working_dir" -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" )"