commented sh files
This commit is contained in:
127
src/sh/cache.sh
127
src/sh/cache.sh
@@ -1,17 +1,27 @@
|
||||
# Caching structure
|
||||
#
|
||||
# ./artist/radix(uuid)/musicbrainz.json # Artist information
|
||||
# ./artist/radix(uuid)/releasegroups.json # List of all release groups
|
||||
# ./artist/radix(uuid)/... # Any other artist information
|
||||
# ./releasegroup/radix(uuid)/musicbrainz.json # Release group information
|
||||
# ./releasegroup/radix(uuid)/releases.json # List of all releases in release group
|
||||
# ./release/radix(uuid)/musicbrainz.json # Release information with tracklist etc.
|
||||
# This implements the caching functionalities. The cache is stored under
|
||||
# `CACHEDIR` defined below, and organized as follows (all paths relative to
|
||||
# `CAHCEDIR`) ./<type>/radix(mbid)/<file>. Here, type is one of `TYPE_ARTIST`,
|
||||
# `TYPE_RELEASEGROUP`, or `TYPE_RELEASE`. The string `radix(mbid)` is the radix
|
||||
# encoded MusicBrainz ID of given type (see method below). Finally <file> is a
|
||||
# filename to hold the respective data in the json format. Currently, the data
|
||||
# is stored as follows:
|
||||
# ./artist/radix(mbid)/musicbrainz.json MusicBrainz artist data
|
||||
# ./artist/radix(mbid)/discogs.json Discogs artist data
|
||||
# ./artist/radix(mbid)/wikidata.json Wikidata artist data
|
||||
# ./artist/radix(mbid)/enwikipedia.json Wikipedia artist data
|
||||
# ./artist/radix(mbid)/releasegroups.json Release groups of artist
|
||||
# ./releasegroup/radix(mbid)/musicbrainz.json MusicBrainz release-group data
|
||||
# ./releasegroup/radix(mbid)/releases.json Releases in release group
|
||||
# ./release/radix(mbid)/musicbrainz.json MusicBrainz release data
|
||||
|
||||
if [ ! "${CACHE_LOADED:-}" ]; then
|
||||
# Base path for cache
|
||||
CACHEDIR="$HOME/.cache/$APP_NAME"
|
||||
# Directory names for cache types
|
||||
TYPE_ARTIST="artist"
|
||||
TYPE_RELEASEGROUP="releasegroup"
|
||||
TYPE_RELEASE="release"
|
||||
# Filenames for cache entries
|
||||
ARTIST_FILENAME="musicbrainz.json"
|
||||
ARTIST_RELEASEROUPS_FILENAME="releasegroups.json"
|
||||
ARTIST_DISCOGS_FILENAME="discogs.json"
|
||||
@@ -28,17 +38,22 @@ if [ ! "${CACHE_LOADED:-}" ]; then
|
||||
export CACHE_LOADED=1
|
||||
fi
|
||||
|
||||
# Radix transform directory name
|
||||
# Radix transform string
|
||||
#
|
||||
# @argument $1: some string
|
||||
__radix() {
|
||||
echo "$1" | awk -F "" '{ print $1$2$3$4"/"$5$6$7$8"/"$0 }'
|
||||
}
|
||||
|
||||
# Radix transform directory names from stdin
|
||||
# Radix transform strings (batch)
|
||||
#
|
||||
# Here, the input is read line-by-line from stdin.
|
||||
__radix_batch() {
|
||||
cat | awk -F "" '{ print $1$2$3$4"/"$5$6$7$8"/"$0 }'
|
||||
}
|
||||
|
||||
# Super wrapper
|
||||
# Super wrapper to print json data from cache
|
||||
#
|
||||
# argument $1: type
|
||||
# argument $2: MusicBrainz ID
|
||||
# argument $3: Filename of json file
|
||||
@@ -48,7 +63,8 @@ __get_json() {
|
||||
cat "$f"
|
||||
}
|
||||
|
||||
# Super wrapper
|
||||
# Super wrapper to store json data in cache
|
||||
#
|
||||
# argument $1: type
|
||||
# argument $2: MusicBrainz ID
|
||||
# argument $3: Filename of json file
|
||||
@@ -61,35 +77,64 @@ __put_json() {
|
||||
[ -s "$tmpf" ] && mv "$tmpf" "$f" || printf "{}" >"$f"
|
||||
}
|
||||
|
||||
## Artist
|
||||
# Print MusicBrainz data of given artist from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_get_artist() {
|
||||
__get_json "$TYPE_ARTIST" "$1" "$ARTIST_FILENAME"
|
||||
}
|
||||
|
||||
# Print release groups (MusicBrainz) of given artist from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_get_artist_releasegroups() {
|
||||
__get_json "$TYPE_ARTIST" "$1" "$ARTIST_RELEASEROUPS_FILENAME"
|
||||
}
|
||||
|
||||
# Print Discogs data of given artist from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_get_artist_discogs() {
|
||||
__get_json "$TYPE_ARTIST" "$1" "$ARTIST_DISCOGS_FILENAME"
|
||||
}
|
||||
|
||||
# Print Wikipedia data of given artist from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_get_artist_enwikipedia() {
|
||||
__get_json "$TYPE_ARTIST" "$1" "$ARTIST_ENWIKIPEDIA_FILENAME"
|
||||
}
|
||||
|
||||
# Print Wikidata data of given artist from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_get_artist_wikidata() {
|
||||
__get_json "$TYPE_ARTIST" "$1" "$ARTIST_WIKIDATA_FILENAME"
|
||||
}
|
||||
|
||||
# Store MusicBrainz data of given artist in cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
#
|
||||
# This methods reads the data to be stored from stdin.
|
||||
cache_put_artist() {
|
||||
cat | __put_json "$TYPE_ARTIST" "$1" "$ARTIST_FILENAME"
|
||||
}
|
||||
|
||||
# Store release groups (MusicBrainz) of given artist in cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
#
|
||||
# This methods reads the data to be stored from stdin.
|
||||
cache_put_artist_releasegroups() {
|
||||
cat | __put_json "$TYPE_ARTIST" "$1" "$ARTIST_RELEASEROUPS_FILENAME"
|
||||
}
|
||||
|
||||
# Append release groups (MusicBrainz) of given artist to existing file in cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
#
|
||||
# This methods reads the data to be stored from stdin.
|
||||
cache_append_artist_releasegroups() {
|
||||
tmpf=$(mktemp)
|
||||
cat >"$tmpf"
|
||||
@@ -99,35 +144,59 @@ cache_append_artist_releasegroups() {
|
||||
rm -f "$tmpf"
|
||||
}
|
||||
|
||||
# Store Discogs data of given artist to cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_put_artist_discogs() {
|
||||
cat | __put_json "$TYPE_ARTIST" "$1" "$ARTIST_DISCOGS_FILENAME"
|
||||
}
|
||||
|
||||
# Store Wikipedia data of given artist to cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_put_artist_enwikipedia() {
|
||||
cat | __put_json "$TYPE_ARTIST" "$1" "$ARTIST_ENWIKIPEDIA_FILENAME"
|
||||
}
|
||||
|
||||
# Store Wikidata data of given artist to cache
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
cache_put_artist_wikidata() {
|
||||
cat | __put_json "$TYPE_ARTIST" "$1" "$ARTIST_WIKIDATA_FILENAME"
|
||||
}
|
||||
|
||||
## Release group
|
||||
# Print MusicBrainz data of given release group from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
cache_get_releasegroup() {
|
||||
__get_json "$TYPE_RELEASEGROUP" "$1" "$RELEASEGROUP_FILENAME"
|
||||
}
|
||||
|
||||
# Print releases (MusicBrainz) in release group from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
cache_get_releasegroup_releases() {
|
||||
__get_json "$TYPE_RELEASEGROUP" "$1" "$RELEASEGROUP_RELEASES_FILENAME"
|
||||
}
|
||||
|
||||
# Store MusicBrainz data of given release group in cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
cache_put_releasegroup() {
|
||||
cat | __put_json "$TYPE_RELEASEGROUP" "$1" "$RELEASEGROUP_FILENAME"
|
||||
}
|
||||
|
||||
# Store releases (MusicBrainz) of given release group in cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
cache_put_releasegroup_releases() {
|
||||
cat | __put_json "$TYPE_RELEASEGROUP" "$1" "$RELEASEGROUP_RELEASES_FILENAME"
|
||||
}
|
||||
|
||||
# Append releases (MusicBrainz) of given release group to existing file in
|
||||
# cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
cache_append_releasegroup_releases() {
|
||||
tmpf=$(mktemp)
|
||||
cat >"$tmpf"
|
||||
@@ -137,40 +206,26 @@ cache_append_releasegroup_releases() {
|
||||
rm -f "$tmpf"
|
||||
}
|
||||
|
||||
## Release
|
||||
# Print MusicBrainz data of given release from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release ID
|
||||
cache_get_release() {
|
||||
__get_json "$TYPE_RELEASE" "$1" "$RELEASE_FILENAME"
|
||||
}
|
||||
|
||||
# Store MusicBrainz data of given release in cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release ID
|
||||
cache_put_release() {
|
||||
cat | __put_json "$TYPE_RELEASE" "$1" "$RELEASE_FILENAME"
|
||||
}
|
||||
|
||||
## Cache deletion
|
||||
cache_delete_artist() {
|
||||
# Get release groups
|
||||
echo "NOT IMPLEMENTED" >/dev/stderr
|
||||
}
|
||||
|
||||
# Check if main items are in cache
|
||||
# argument $1: type
|
||||
# argument $2: MusicBrainz ID
|
||||
in_cache() {
|
||||
case "$1" in
|
||||
"$TYPE_ARTIST") fn="$ARTIST_FILENAME" ;;
|
||||
"$TYPE_RELEASEGROUP") fn="$RELEASEGROUP_FILENAME" ;;
|
||||
"$TYPE_RELEASE") fn="$RELEASE_FILENAME" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
[ "$(__get_json "$1" "$2" "$fn")" ] && return 0 || return 1
|
||||
}
|
||||
|
||||
# Print all cache paths to the files specified by their IDs
|
||||
# Print all MusicBrainz cache paths to the files specified by their IDs
|
||||
#
|
||||
# @argument $1: type
|
||||
#
|
||||
# This method reads from stdin any number of MusicBrainz IDs of objects of the
|
||||
# specified type, and prints the file pahts.
|
||||
# specified type, and prints the file paths.
|
||||
cache_get_file_batch() {
|
||||
case "$1" in
|
||||
"$TYPE_ARTIST") fn="$ARTIST_FILENAME" ;;
|
||||
|
Reference in New Issue
Block a user