Update scripts to make them more versatile:
- Support WAV - Directories are now name original and converted - Keep and copy mp3 and m4a files without reencoding them - Fix mp3convert failing when there is no cover art
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Enable nullglob so the script doesn't throw errors if certain file types are missing
|
||||
shopt -s nullglob
|
||||
|
||||
ORIGINAL_DIR="original"
|
||||
CONVERTED_DIR="converted"
|
||||
|
||||
# 1. Create the new directory structure
|
||||
mkdir -p $ORIGINAL_DIR $CONVERTED_DIR
|
||||
|
||||
# 2. Copy/move existing .mp3 and .m4a files to both directories without converting
|
||||
mp3_m4a=(*.mp3 *.m4a)
|
||||
if [ ${#mp3_m4a[@]} -gt 0 ]; then
|
||||
cp "${mp3_m4a[@]}" $ORIGINAL_DIR/
|
||||
mv "${mp3_m4a[@]}" $CONVERTED_DIR/
|
||||
fi
|
||||
|
||||
# 3. Move .flac and .wav files to the 'original' directory
|
||||
flac_wav=(*.flac *.wav)
|
||||
if [ ${#flac_wav[@]} -gt 0 ]; then
|
||||
mv "${flac_wav[@]}" $ORIGINAL_DIR/
|
||||
fi
|
||||
|
||||
# 4. Find and convert all .flac and .wav files inside the input directory
|
||||
# We pass "$CONVERTED_DIR" right before the {} +
|
||||
find "$ORIGINAL_DIR" -type f \( -name '*.flac' -o -name '*.wav' \) -exec bash -c '
|
||||
# Grab the first argument passed to this sub-shell and save it
|
||||
target_dir="$1"
|
||||
|
||||
# "shift" discards the first argument ($1), so the remaining arguments ($@)
|
||||
# are just the actual files provided by the find command.
|
||||
shift
|
||||
|
||||
for file; do
|
||||
mp3convert "$file" "$target_dir"
|
||||
done
|
||||
' _ "$CONVERTED_DIR" {} +
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
FLAC="$1"
|
||||
OUT_DIR="mp3"
|
||||
INPUT_FILE="$1"
|
||||
OUT_DIR="$2"
|
||||
# get filename without extension
|
||||
FILENAME="${FLAC##*/}"
|
||||
BASE_NAME="${INPUT_FILE##*/}"
|
||||
# make filename with .mp3 extension
|
||||
MP3="./${OUT_DIR}/${FILENAME%.flac}.mp3"
|
||||
MP3_FILE="./${OUT_DIR}/${BASE_NAME%.*}.mp3"
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
if [[ ! -f "$MP3" ]]; then
|
||||
ffmpeg -i "$FLAC" -c:a libmp3lame -b:a 320K -map a:0 "$MP3"
|
||||
ffmpeg -i "$INPUT_FILE" -c:a libmp3lame -b:a 320K -map a:0 -map v:0? -c:v copy "$MP3_FILE"
|
||||
fi
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p flac
|
||||
mv *.flac flac/
|
||||
# call mp3convert on every file inside the flac directory
|
||||
find flac -name '*.flac' -exec bash -c 'mp3convert "$1"' _ {} \;
|
||||
|
||||
Reference in New Issue
Block a user