add encode all, fix a bit of tags with split_tracks

This commit is contained in:
Luke Tidd 2023-05-17 13:01:10 -04:00
parent 05030e709b
commit 831034bd14
Signed by: luke
GPG Key ID: 75D6600BEF4E8E8F
2 changed files with 65 additions and 7 deletions

55
encode_all Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
# encode_all encodes the whole library into specified format
#
. env_parallel.bash
src_library="${HOME}/flac"
output_dir="${HOME}/opus"
function encode() {
file="$1"
# file is full original path + filename
src_dir="$(dirname "$file")"
file_name="$(basename "$file")"
final_dir="$(sed "s_${HOME}/flac_${HOME}/opus_" <<< "$src_dir")"
final_opus="$(sed -e 's/\.flac$/.opus/' -e "s_${HOME}/flac_${HOME}/opus_" <<< "$file")"
unset tags
unset dest_dir
declare -A tags
while read -r line; do
tag_type="$(cut -d= -f1 <<< "$line")"
tag_type="${tag_type^^}"
tag_val="$(cut -d= -f2- <<< "$line")"
tags["$tag_type"]="$tag_val"
done < <(metaflac --list --block-type=VORBIS_COMMENT "$file" | grep 'comment\[' | cut -d: -f2- | sed 's/^ //')
album="$(basename "$final_dir")"
if [[ "$file_name" =~ ^D[0-9]+ ]]; then
disk="$(cut -d\ -f1 <<< "$file_name")"
tags[DISK]="${disk#D}"
fi
declare -a tag_ensure
tag_ensure=( TRACKNUMBER TITLE DATE ALBUM ARTIST )
for tag_type in "${tag_ensure[@]}"; do
if [[ -z "${tags[$tag_type]}" ]]; then
tags[$tag_type]="missing $tag_type"
fi
done
[[ -d "$final_dir" ]] || mkdir -p "$final_dir"
if [[ -n "${tags[DISK]}" ]]; then
opusenc \
--title "${tags[TITLE]}" --artist "${tags[ARTIST]}" \
--album "${tags[ALBUM]}" --tracknumber "${tags[TRACKNUMBER]}" \
--date "${tags[DATE]}" --comment "DISK=${tags[DISK]}" "$file" "$final_opus"
else
opusenc \
--title "${tags[TITLE]}" --artist "${tags[ARTIST]}" \
--album "${tags[ALBUM]}" --tracknumber "${tags[TRACKNUMBER]}" \
--date "${tags[DATE]}" "$file" "$final_opus"
fi
}
time find "$src_library" -type f -name '*.flac' -print0 | env_parallel -P 0 -0 --bar encode {}

View File

@ -90,16 +90,19 @@ find "$src_library" -type f -name '*.flac' | while read file; do
declare -A tags declare -A tags
echo tag time echo tag time
while read -r line; do while read -r line; do
echo line: $line
tag_type="$(cut -d= -f1 <<< "$line")" tag_type="$(cut -d= -f1 <<< "$line")"
tag_type="${tag_type^^}"
tag_val="$(cut -d= -f2- <<< "$line")" tag_val="$(cut -d= -f2- <<< "$line")"
tags[$tag_type]="${tag_val^^}" tags["$tag_type"]="$tag_val"
done < <(metaflac --list --block-type=VORBIS_COMMENT "$file" | grep 'comment\[' | cut -d: -f2- | sed 's/^ //') done < <(metaflac --list --block-type=VORBIS_COMMENT "$file" | grep 'comment\[' | cut -d: -f2- | sed 's/^ //')
album="$(basename "$final_dir")"
if [[ "$file_name" =~ ^D[0-9]+ ]]; then
declare -a ensure disk="$(cut -d\ -f1 <<< "$file_name")"
ensure=( TRACKNUMBER TITLE DATE ALBUM ARTIST ) tags[DISK]="${disk#D}"
for tag_type in "${ensure[@]}"; do fi
declare -a tag_ensure
tag_ensure=( TRACKNUMBER TITLE DATE ALBUM ARTIST )
for tag_type in "${tag_ensure[@]}"; do
if [[ -z "${tags[$tag_type]}" ]]; then if [[ -z "${tags[$tag_type]}" ]]; then
tags[$tag_type]="missing $tag_type" tags[$tag_type]="missing $tag_type"
fi fi