--decorate

This commit is contained in:
2025-08-04 15:56:47 +02:00
parent 828a69d65e
commit 7f94ab9646
3 changed files with 79 additions and 11 deletions

View File

@@ -8,6 +8,9 @@ set -eu
# Load helper methods
. "sh/helper.sh"
# Load configuration
. "sh/config.sh"
# Load theme
. "sh/theme.sh"
@@ -29,6 +32,22 @@ set -eu
# Load MusicBrainz wrappers
. "sh/mb.sh"
# Load local file handling
. "sh/local.sh"
# Support of local music files
if [ "${MUSICDIR:-}" ]; then
if [ "${1:-}" = "--decorate" ]; then
[ ! "${2:-}" ] && err "You did not specify a directory." && exit 1
[ ! -d "$2" ] && err "Path $2 does not point to a directory." && exit 1
if ! decorate "$2"; then
err "Something went wrong. Are you're files tagged correctly?"
exit 1
fi
exit 0
fi
fi
if [ "${1:-}" = "--internal-preview-artist" ]; then
__preview_artist "$2"
exit 0
@@ -177,17 +196,17 @@ if [ "${1:-}" = "--internal-list-releases" ]; then
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
mb_releasegroup_releases "$2" |
$JQ -r '."releases"[] | [
.id,
.status,
.date,
."cover-art-archive".count,
(."label-info" | map(.label.name) | unique | join(", ")),
(.media | map(."track-count") | add),
(.media | map(.format) | unique | join(", ")),
.country,
.title,
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
] | join("\t")' |
.id,
.status,
.date,
."cover-art-archive".count,
(."label-info" | map(.label.name) | unique | join(", ")),
(.media | map(."track-count") | add),
(.media | map(.format) | unique | join(", ")),
.country,
.title,
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
] | join("\t")' |
awk \
-F "\t" \
-v release_official="$FORMAT_STATUS_OFFICIAL" \

7
src/sh/config.sh Normal file
View File

@@ -0,0 +1,7 @@
if [ "${CONFIGFILE:-}" ]; then
[ ! -f "$CONFIGFILE" ] && err "Configuration $CONFIGFILE not found." && exit 1
. "$CONFIGFLIE"
[ ! "${MUSICDIR:-}" ] && err "MUSICDIR configuration not set." && exit 1
fi
[ "${MUSICDIR:-}" ] && [ ! -d "${MUSICDIR:-}" ] && err "The specified path ${MUSICDIR:-} is not a directory." && exit 1
DECORATION_FILENAME=${DECORATION_FILENAME:-"mbid.json"}

42
src/sh/local.sh Normal file
View File

@@ -0,0 +1,42 @@
gettags() {
ffprobe -v error -show_entries format_tags -print_format json "$1" |
$JQ -r --compact-output '.format.tags | {
trackid: (."MusicBrainz Release Track Id" // ."MUSICBRAINZ_RELEASETRACKID" // ."MusicBrainz/Release Track Id" // ""),
releaseid: (."MusicBrainz Album Id" // ."MUSICBRAINZ_ALBUMID" // ."MusicBrainz/Album Id" // "")
}'
}
# Read music files in specified directory and create json file that points to
# all relevant MusicBrainz IDs.
# @input $1: Path to directory with album
decorate() {
decoration=$($JQ -n '.tracks = {}')
tmpf=$(mktemp)
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a') >"$tmpf"
while IFS= read -r f; do
mbid=$(gettags "$1/$f")
rid=$(echo "$mbid" | $JQ -r '.releaseid')
tid=$(echo "$mbid" | $JQ -r '.trackid')
if [ ! "$rid" ] || [ ! "$tid" ]; then
err "File $f: Seems not tagged"
releaseid=""
break
fi
if [ "${releaseid:-}" ]; then
if [ "$releaseid" != "$rid" ]; then
err "Directory $1 contains files of different releases"
releaseid=""
break
fi
else
releaseid="$rid"
fi
decoration=$(echo "$decoration" | $JQ ".tracks += {\"$tid\": \"$f\"}")
done <"$tmpf"
rm -f "$tmpf"
if [ "$releaseid" ]; then
echo "$decoration" | $JQ --compact-output ".releaseid = \"$releaseid\"" >"$1/$DECORATION_FILENAME"
else
return 1
fi
}