--decorate
This commit is contained in:
19
src/main.sh
19
src/main.sh
@@ -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
|
||||
|
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