initial commit

This commit is contained in:
Sebastian Hugentobler 2023-06-22 09:46:43 +02:00
commit e02509cdf2
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0
3 changed files with 113 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*~
.DS_Store
*.pkg.tar.zst
*.pkg.tar.zst.sig

20
PKGBUILD Normal file
View File

@ -0,0 +1,20 @@
# Maintainer: Sebastian Hugentobler <shu@vanwa.ch>
pkgname=music-compiler
pkgver=0.1.0
pkgrel=1
pkgdesc="Transcode a directory tree to mp3."
arch=("any")
url="https://code.vanwa.ch"
license=('MIT')
depends=("ffmpeg" "bash")
source=(
"music-compiler"
)
sha256sums=("7401e88c219ffc27066fbe424a9b6ea44377bec4130b3186e626a7b5714e2f31")
package() {
cd "$srcdir/"
install -Dm 755 music-compiler "$pkgdir/usr/bin/music-compiler"
}

89
music-compiler Executable file
View File

@ -0,0 +1,89 @@
#!/usr/bin/env bash
set -o errexit
source="./"
dest=""
nproc="$(nproc)"
display_help() {
echo "Usage: $0 [option...] " >&2
echo
echo " -s, source directory [default: $source]"
echo " -d, destination directory (the structure of source will be replicated there)"
echo " -n, number of processes to use [default: $nproc]"
echo " -h, display this help and exit"
echo
}
parse_args() {
while getopts ":hs:d:n:" opt; do
case $opt in
h)
display_help
exit 0
;;
s)
source=$OPTARG/
;;
d)
dest=$OPTARG/
;;
n)
nproc=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
display_help
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
display_help
exit 1
;;
esac
done
}
transcode() {
local input="$1"
local source="$2"
local dest="$3"
local tmp_dest="${input/$source/$dest}"
for ending in %.flac %.m4a; do
tmp_dest="${tmp_dest/$ending/.mp3}"
done
local final_dest="$tmp_dest"
local parent_dir
parent_dir="$(dirname "$final_dest")"
[[ -d "$parent_dir" ]] || mkdir -p "$parent_dir"
ffmpeg -y -i "$input" -c:a libmp3lame -qscale:a 4 "$final_dest"
}
export -f transcode
cover_process() {
local input="$1"
local source="$2"
local dest="$3"
local final_dest="${input/$source/$dest}"
local parent_dir
parent_dir="$(dirname "$final_dest")"
[[ -d "$parent_dir" ]] || mkdir -p "$parent_dir"
cp "$input" "$final_dest"
}
export -f cover_process
parse_args "$@"
SHELL="$(type -p bash) -exv" \
find "$source" -type f -name "*.flac" -o -name "*.mp3" -o -name "*.m4a" |
parallel -j"$nproc" transcode {} "$source" "$dest"
SHELL=$(type -p bash) \
find "$source" -type f -name "cover.jpg" |
parallel -j"$nproc" cover_process {} "$source" "$dest"