--decorate
This commit is contained in:
41
src/main.sh
41
src/main.sh
@@ -8,6 +8,9 @@ set -eu
|
|||||||
# Load helper methods
|
# Load helper methods
|
||||||
. "sh/helper.sh"
|
. "sh/helper.sh"
|
||||||
|
|
||||||
|
# Load configuration
|
||||||
|
. "sh/config.sh"
|
||||||
|
|
||||||
# Load theme
|
# Load theme
|
||||||
. "sh/theme.sh"
|
. "sh/theme.sh"
|
||||||
|
|
||||||
@@ -29,6 +32,22 @@ set -eu
|
|||||||
# Load MusicBrainz wrappers
|
# Load MusicBrainz wrappers
|
||||||
. "sh/mb.sh"
|
. "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
|
if [ "${1:-}" = "--internal-preview-artist" ]; then
|
||||||
__preview_artist "$2"
|
__preview_artist "$2"
|
||||||
exit 0
|
exit 0
|
||||||
@@ -177,17 +196,17 @@ if [ "${1:-}" = "--internal-list-releases" ]; then
|
|||||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||||
mb_releasegroup_releases "$2" |
|
mb_releasegroup_releases "$2" |
|
||||||
$JQ -r '."releases"[] | [
|
$JQ -r '."releases"[] | [
|
||||||
.id,
|
.id,
|
||||||
.status,
|
.status,
|
||||||
.date,
|
.date,
|
||||||
."cover-art-archive".count,
|
."cover-art-archive".count,
|
||||||
(."label-info" | map(.label.name) | unique | join(", ")),
|
(."label-info" | map(.label.name) | unique | join(", ")),
|
||||||
(.media | map(."track-count") | add),
|
(.media | map(."track-count") | add),
|
||||||
(.media | map(.format) | unique | join(", ")),
|
(.media | map(.format) | unique | join(", ")),
|
||||||
.country,
|
.country,
|
||||||
.title,
|
.title,
|
||||||
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
|
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
|
||||||
] | join("\t")' |
|
] | join("\t")' |
|
||||||
awk \
|
awk \
|
||||||
-F "\t" \
|
-F "\t" \
|
||||||
-v release_official="$FORMAT_STATUS_OFFICIAL" \
|
-v release_official="$FORMAT_STATUS_OFFICIAL" \
|
||||||
|
7
src/sh/config.sh
Normal file
7
src/sh/config.sh
Normal 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
42
src/sh/local.sh
Normal 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
|
||||||
|
}
|
Reference in New Issue
Block a user