diff --git a/djconvert b/djconvert new file mode 100755 index 0000000..88caa9b --- /dev/null +++ b/djconvert @@ -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" {} + diff --git a/mp3convert b/mp3convert index 53a2662..9aaab45 100755 --- a/mp3convert +++ b/mp3convert @@ -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 diff --git a/tidalconvert b/tidalconvert deleted file mode 100755 index aa5ee7b..0000000 --- a/tidalconvert +++ /dev/null @@ -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"' _ {} \; -