commented sh files

This commit is contained in:
2025-09-11 15:57:06 +02:00
parent 3702bc54a8
commit 0fe55ba06d
17 changed files with 483 additions and 190 deletions

View File

@@ -1,3 +1,10 @@
# This file provides the methods for access to several APIs
#
# APIs:
# - MusicBrainz
# - Discogs
# - Wikidata
# - Wikipedia
if [ ! "${API_LOADED:-}" ]; then
MB_MAX_RETRIES=10
MB_BROWSE_STEPS=100
@@ -8,6 +15,16 @@ if [ ! "${API_LOADED:-}" ]; then
export API_LOADED=1
fi
# Internal method for MusicBrainz API access
#
# @argument $1: entity (see `case` below)
# @argument $2: MusicBrainz ID
# @argument $3: offset (optional, but mandatory for browse requests)
#
# If the API access fails, then the error message is logged, and at most
# `MB_MAX_RETRIES` retries are made. If browse requests are made, then at most
# `MB_BROWSE_STEPS` number of entries are requested per call. The offset in
# browse request must be specified.
__api_mb() {
tmpout=$(mktemp)
for _ in $(seq "$MB_MAX_RETRIES"); do
@@ -98,35 +115,62 @@ __api_mb() {
return 1
}
# The interface to MusicBrainz API.
# Retrieve MusicBrainz artist information
#
# @argument $1: MusicBrainz artist ID
api_mb_artist() {
__api_mb "artist" "$1"
}
# Retrieve MusicBrainz release-group information
#
# @argument $1: MusicBrainz release-group ID
api_mb_releasegroup() {
__api_mb "releasegroup" "$1"
}
# Retrieve MusicBrainz release information
#
# @argument $1: MusicBrainz release ID
api_mb_release() {
__api_mb "release" "$1"
}
# Retrieve MusicBrainz release-groups for given artist
#
# @argument $1: MusicBrainz artist ID
# @argument $2: offset (defaults to 0)
api_mb_browse_artist_releasegroups() {
__api_mb "browse-artist-releasegroups" "$1" "${2:-0}"
}
# Retrieve MusicBrainz releases in given release group
#
# @argument $1: MusicBrainz release-group ID
# @argument $2: offset (defaults to 0)
api_mb_browse_releasegroup_releases() {
__api_mb "browse-releasegroup-releases" "$1" "${2:-0}"
}
# Argument: Search string
# Search MusicBrainz database for given artist
#
# @argument $1: query
api_mb_search_artist() {
__api_mb "search-artist" "$1"
}
# Search MusicBrainz database for given release group
#
# @argument $1: query
api_mb_search_releasegroup() {
__api_mb "search-releasegroup" "$1"
}
# Retrieve Discogs artist information
#
# @argument $1: Discogs artist ID
api_discogs_artist() {
$CURL \
--get \
@@ -134,6 +178,9 @@ api_discogs_artist() {
"https://api.discogs.com/artists/$1"
}
# Retrieve sitelinks from wikidata
#
# @argument $1: Wikidata ID
api_wikidata_sitelinks() {
$CURL \
--get \
@@ -141,6 +188,9 @@ api_wikidata_sitelinks() {
"https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/$1/sitelinks"
}
# Retrieve summary from Wikipedia page
#
# @argument $1: Wikipedia page name
api_wikipedia_en_summary() {
$CURL \
--get \