Solved how to resample mp3 in ram /tmp

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" )"
 
nevermind---

Code:
#!/bin/bash
#set -x
working_dir="/media/data/music-test"
move_to="/media/data/music-resampled"
script_dir=/tmp
echo "$script_dir"
no_tags=/media/data/music_no_tags
orginals=/media/data/orginal_music

manyfiles="$(find "$working_dir" -type f -name "*.mp3" -o -name "*.Mp3" -o -name "*.MP3" -o -name "*.flac" | wc -l)"
if [[ $manyfiles -eq 0 ]] ; then 
echo "zero files"
exit
fi
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 directroy 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  - "$script_dir"/"$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"
        
         
            NewPath2=${FILE/"$working_dir"/"$move_to"}
            mkdir -p "$NewPath2"
            exit
            mv -vf "$script_dir"/"$newFile" "$NewPath2"
            
            echo;echo "moving orginal"
            mkdir -pv "$keep_orginals"
            mv -vf "$FILE" "$keep_orginals"
            echo;echo "orginal moved"
}
fi

if [[ "${ext,,}" == "mp3" ]] ; then
         
 # if  start bitrate  <    128     or   start bitrate > 160 then resample
    if [[ "${bitrate%.*}" -gt "${rate2h}" ]] ; then
    {
        echo "$FILE
        $newFile
         "$script_dir"/"$newFile"
         "
        lame -V2 -b 128  -F --vbr-new -m j -q 2 "$FILE" "$script_dir"/"$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"
    
        NewPath2=${FILE/"$working_dir"/"$move_to"}
        NewPath2=${NewPath2%/*}
        echo "in else NewPath $NewPath2"
        mkdir -p "$NewPath2"
        echo "NewPath $NewPath2"
        mv -v "$script_dir"/"$newFile" "$NewPath2"
        mkdir -pv "$keep_orginals"
        mv -vf "$FILE" "$keep_orginals"
        echo;echo "orginal moved"
         
         
    }
    else
    {
    NewPath2=${FILE//"$working_dir"/"$move_to"}
    NewPath2=${NewPath2%/*}
    echo "in else NewPath $NewPath2"
    mkdir -p "$NewPath2"
    cp -v "$FILE" "$NewPath2"
    
    echo;echo "moving orginal
     "$keep_orginals""
     
    mkdir -pv "$keep_orginals"
    mv -vf "$FILE" "$keep_orginals"
    echo;echo "orginal moved"
    }
    fi  
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" )"
 
Back
Top