Skip to content

Instantly share code, notes, and snippets.

@kepocnhh
Created September 24, 2024 12:41
Show Gist options
  • Save kepocnhh/f27bd9c6fbb6c31fa2faa1264b79029a to your computer and use it in GitHub Desktop.
Save kepocnhh/f27bd9c6fbb6c31fa2faa1264b79029a to your computer and use it in GitHub Desktop.
Flac to MP3
#!/usr/local/bin/bash
if test $# -ne 2; then
echo "Script needs for 2 arguments but actual $#!"; exit 12; fi
SRC="$1"
DST="$2"
if [[ ! -d "$SRC" ]]; then echo "SRC: $SRC is not a dir!"; exit 1; fi
if [[ ! -d "$DST" ]]; then echo "DST: $DST is not a dir!"; exit 1; fi
issuers=()
index=-1
while read it; do
index=$((index+1))
if [[ ! -f "$it" ]]; then continue; fi
if [[ ! -s "$it" ]]; then continue; fi
issuers+=("$it")
done <<< "$(find "$SRC" -maxdepth 1)"
sorted=()
while read it; do
sorted+=("$it")
done <<< "$(printf '%s\n' "${issuers[@]}"|sort)"
index=-1
for ((i = 0; i < ${#sorted[@]}; i++)); do
index=$((index+1))
it="${sorted[$i]}"
BN="$(basename "$it")"
if [[ "$BN" =~ ^.+\.flac$ ]]; then
echo "$it"
else continue; fi
dst="$DST/${BN%.flac}.mp3"
if [[ -e "$dst" ]]; then
echo "Dst exists!"; exit 1; fi
~/.local/bin/ffmpeg -i "$it" -ab 320k "$dst"
if test $? != 0; then
echo "$index] \"$it\" FFMPEG error!"; exit 1; fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment