Compare commits
47 Commits
1883109616
...
main
Author | SHA1 | Date | |
---|---|---|---|
ca2c7ae3c5 | |||
d39cf11ed3 | |||
8112586f87 | |||
6dc107c7c4 | |||
9c969d073f | |||
e76cb6a8e3 | |||
58b1258fe2 | |||
173c717be5 | |||
98145031d3 | |||
42e4aa02b6 | |||
d060a30c45 | |||
79df83d1b1 | |||
c1f8066688 | |||
0fe55ba06d | |||
3702bc54a8 | |||
56b8c73297 | |||
f35461cc50 | |||
88ec2f8bf5 | |||
4d63df4535 | |||
d5b3d7c597 | |||
a2fd70e096 | |||
49411a2b22 | |||
fc14a0e0d5 | |||
70da0ed282 | |||
dfcae7cf89 | |||
2cc8332560 | |||
20104a25b4 | |||
32087d8736 | |||
4cb9c8c46f | |||
e9fafe278f | |||
60f7426709 | |||
6ff6e4bbcc | |||
9b898898c8 | |||
7e01349abe | |||
655359dea3 | |||
93359f99c5 | |||
62f7e38e47 | |||
48976cbfc5 | |||
eb9ce5164f | |||
c46c64d639 | |||
dac9e5c332 | |||
45d75fe9cc | |||
e90cdda8b7 | |||
9f8d2cc189 | |||
274fa5edcc | |||
8c37cb2fea | |||
b15848887b |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,2 @@
|
||||
demo
|
||||
muf
|
||||
muf.debug.log
|
||||
fuzic
|
||||
|
@@ -3,16 +3,14 @@
|
||||
BOLD="\033[1m"
|
||||
GREEN="\033[0;32m"
|
||||
OFF="\033[m"
|
||||
NAME="muf"
|
||||
NAME="fuzic"
|
||||
SRC="./src/main.sh"
|
||||
|
||||
tmpdir=$(mktemp -d)
|
||||
echo "🐔 ${GREEN}Internalize sourced files${OFF}"
|
||||
echo "🥚 ${GREEN}Internalize sourced files${OFF}"
|
||||
sed -E 's|\. "([^$].+)"$|cat src/\1|e' "$SRC" >"$tmpdir/1.sh"
|
||||
echo "🥚 ${GREEN}Internalize awk scripts${OFF}"
|
||||
sed -E 's|@@include (.+)$|cat src/\1|e' "$tmpdir/1.sh" >"$tmpdir/2.sh"
|
||||
echo "🐔 ${GREEN}Internalize awk libraries${OFF}"
|
||||
sed -E 's|@include "(.+)"$|cat src/\1|e' "$tmpdir/2.sh" >"$NAME"
|
||||
echo "🐔 ${GREEN}Internalize awk scripts${OFF}"
|
||||
sed -E 's|@@include (.+)$|cat src/\1|e' "$tmpdir/1.sh" >"$NAME"
|
||||
echo "🥚 ${GREEN}Make executable and cleanup${OFF}"
|
||||
chmod +x "$NAME"
|
||||
rm -rf "$tmpdir"
|
||||
|
@@ -7,22 +7,22 @@ FORMAT_LOCAL="|>"
|
||||
# Pointer to the track currently playing (playlist)
|
||||
FORMAT_CURRENT="->"
|
||||
|
||||
# Input prompts
|
||||
# Input prompt
|
||||
# =============
|
||||
# General search prompt
|
||||
# Search prompt
|
||||
SEARCH_PROMPT="search> "
|
||||
# Prompt that takes an artist name as argument
|
||||
ARTIST_PROMPT="%s > "
|
||||
# Prompt that takes an artist name and a release name as arguments (in that
|
||||
# order)
|
||||
FULL_PROMPT="%s > %s > "
|
||||
|
||||
# Visual representation of current mode
|
||||
# =====================================
|
||||
# Sign to indicate `normal` mode
|
||||
PROMPT_NORMAL="n "
|
||||
# Sign to indicate `insert` mode
|
||||
PROMPT_INSERT="i "
|
||||
# Headers
|
||||
# =======
|
||||
# Header that displays artist's name
|
||||
HEADER_ARTIST="%s > "
|
||||
# Header that displays the release-group name after artist's
|
||||
HEADER_ARTIST_RELEASEGROUP="%s > %s > "
|
||||
# Header that in addition to `HEADER_ARTIST_RELEASEGROUP` also shows some
|
||||
# release information
|
||||
HEADER_RELEASE="%s > %s > %s"
|
||||
# The release information is formatted as follows (placeholders implicit):
|
||||
HEADER_RELEASE_FORMAT="<<tracks>> tx <<media>> | <<label>> <<country>> <<year>>"
|
||||
|
||||
# Artist view
|
||||
# ===========
|
||||
|
@@ -18,22 +18,22 @@ FORMAT_LOCAL="${BLUE}|>$OFF"
|
||||
# Pointer to the track currently playing (playlist)
|
||||
FORMAT_CURRENT="${WHITE}-->$OFF"
|
||||
|
||||
# Input prompts
|
||||
# Input prompt
|
||||
# =============
|
||||
# General search prompt
|
||||
# Search prompt
|
||||
SEARCH_PROMPT="search: "
|
||||
# Prompt that takes an artist name as argument
|
||||
ARTIST_PROMPT="artist: %s: "
|
||||
# Prompt that takes an artist name and a release name as arguments (in that
|
||||
# order)
|
||||
FULL_PROMPT="artist: %s / %s: "
|
||||
|
||||
# Visual representation of current mode
|
||||
# =====================================
|
||||
# Sign to indicate `normal` mode
|
||||
PROMPT_NORMAL="n)"
|
||||
# Sign to indicate `insert` mode
|
||||
PROMPT_INSERT="i)"
|
||||
# Headers
|
||||
# =======
|
||||
# Header that displays artist's name
|
||||
HEADER_ARTIST="artist: %s"
|
||||
# Header that displays the release-group name after artist's
|
||||
HEADER_ARTIST_RELEASEGROUP="artist: %s / album: %s"
|
||||
# Header that in addition to `HEADER_ARTIST_RELEASEGROUP` also shows some
|
||||
# release information
|
||||
HEADER_RELEASE="artist: %s / album: %s (%s)"
|
||||
# The release information is formatted as follows (placeholders implicit):
|
||||
HEADER_RELEASE_FORMAT="<<label>> <<year>>"
|
||||
|
||||
# Artist view
|
||||
# ===========
|
||||
|
@@ -1,3 +1,30 @@
|
||||
# List artists
|
||||
#
|
||||
# parameter file_local_artists: This is an optional parameter with the path
|
||||
# to a file with a MusicBrainz artist ID per
|
||||
# line.
|
||||
# parameter format_person: This is the format string for single person
|
||||
# artists, which includes the <<name>>
|
||||
# placeholder.
|
||||
# parameter format_disambiguation: This is the format string for the
|
||||
# disambiguation part of the artist, with a
|
||||
# placeholder <<disambiguation>>.
|
||||
# parameter format_group: This is as format_person, but for music
|
||||
# groups.
|
||||
# parameter format_local: String to indicate that there is some music
|
||||
# locally available of an artist
|
||||
#
|
||||
# This awk program takes as input a sequence of lines where the first item is
|
||||
# the MusicBrainz artist ID, the second item is the type of the artist
|
||||
# ("Person" or "Group"), the third item is the name, and the forth item is a
|
||||
# disambiguation string.
|
||||
#
|
||||
# The output of this script is a sequence of tab-delimited lines where the
|
||||
# first item is the format_local string, if some music of that artist is
|
||||
# locally accessible, and the empty string otherwise, the second item is the
|
||||
# formatted artist string (formatted according to format_person or
|
||||
# format_group), the third item is the constant string "0" indicating the
|
||||
# parent MusicBrainz ID, and the last item is the MusicBrainz artist ID.
|
||||
BEGIN {
|
||||
OFS="\t"
|
||||
local_artists[0] = 0
|
||||
|
@@ -1,3 +1,39 @@
|
||||
# List recordings
|
||||
#
|
||||
# parameter file_local_recordings: This is an optional parameter with the path
|
||||
# to a file with a MusicBrainz recording ID
|
||||
# per line.
|
||||
# parameter format: The format of a recording line including the
|
||||
# placeholders <<med>> for medium number,
|
||||
# <<nr> for for track number within a medium,
|
||||
# <<title>> for the title, <<artist>> for the
|
||||
# artist string, and <<duration>> for the
|
||||
# track duration.
|
||||
# parameter format_local: String to indicate that the track is locally
|
||||
# available
|
||||
# parameter format_current: String to indicate that the track is
|
||||
# "currently playing"
|
||||
# parameter current_id: MusicBrainz track ID of a track to be marked
|
||||
# as "currently playing"
|
||||
#
|
||||
# The input to this awk program is a sequence of lines containing the following fields:
|
||||
# Field 1: The MusicBrainz ID of the release this track belongs to
|
||||
# Field 2: MusicBrainz ID of this track
|
||||
# Field 3: Medium number of this track within the release
|
||||
# Field 4: Track number of this track within the medium
|
||||
# Field 5: Duration of this track in miliseconds
|
||||
# Field 6: Title of this track
|
||||
# Field 7: Artist of this track
|
||||
# Field 8: Path to decoratoin file of this release
|
||||
#
|
||||
# The output is a sequence of tab-delimited lines containing the following fields:
|
||||
# Field 1: Sort value (to sort the track within the release)
|
||||
# Field 2: The string `format_local` if the track is locally available
|
||||
# Field 3: The string `format_current` if the track has MusicBrainz ID `current_id`
|
||||
# Field 4: The track line to be displayed according to `format`
|
||||
# Field 5: The MusicBrainz ID of the release this track belongs to
|
||||
# Field 6: The MusicBrainz ID of this track ":" separated from the path to the
|
||||
# decoration file of this release
|
||||
BEGIN {
|
||||
OFS="\t"
|
||||
local_recordings[0] = 0
|
||||
@@ -9,7 +45,6 @@ BEGIN {
|
||||
}
|
||||
}
|
||||
{
|
||||
gsub("&", "\\\\&")
|
||||
parentid = $1
|
||||
id = $2
|
||||
med = $3
|
||||
@@ -18,6 +53,8 @@ BEGIN {
|
||||
title = $6
|
||||
artist = $7
|
||||
deco = local_recordings[id] ? $8 : ""
|
||||
gsub("&", "\\\\&", title)
|
||||
gsub("&", "\\\\&", artist)
|
||||
# Parse duration
|
||||
if (dur) {
|
||||
dur = int(dur / 1000)
|
||||
|
@@ -1,3 +1,69 @@
|
||||
# List release groups
|
||||
#
|
||||
# parameter file_local_releasegroups: This is an optional parameter with the
|
||||
# path to a file with a MusicBrainz
|
||||
# release-group ID per line.
|
||||
# parameter format_release: Format for the release title with a
|
||||
# <<title>> placeholder.
|
||||
# parameter format_release_w_artist: Same as `format_release` but with an
|
||||
# additional <<artist>> placeholder.
|
||||
# parameter format_year: Format string for the year part, with a
|
||||
# <<year>> placeholder.
|
||||
# parameter format_local: String to indicate that the track is
|
||||
# locally available.
|
||||
# parameter artist: Artist name to compare release-groups
|
||||
# artist names against. If the names
|
||||
# differ, then the format with <<artist>>
|
||||
# placeholder is used (optional)
|
||||
# parameter artistid MusicBrainz ID of the artist (optional).
|
||||
# Then, there are several format strings that indicate the type of a release
|
||||
# group. The types are implicit from the parameter names:
|
||||
# parameter format_album
|
||||
# parameter format_single
|
||||
# parameter format_ep
|
||||
# parameter format_broadcast
|
||||
# parameter format_other
|
||||
# Some release groups have also a secondary type. The presence of a secondary
|
||||
# type is formatted using
|
||||
# parameter format_secondary.
|
||||
# The list of all secondary types (implicit from their variable names) are
|
||||
# formatted using
|
||||
# parameter format_secondary.
|
||||
# Each of the secondary types is specified with (the type is implicit from the
|
||||
# variable names)
|
||||
# parameter format_compilation
|
||||
# parameter format_soundtrack
|
||||
# parameter format_spokenword
|
||||
# parameter format_interview
|
||||
# parameter format_audiobook
|
||||
# parameter format_audiodrama
|
||||
# parameter format_live
|
||||
# parameter format_remix
|
||||
# parameter format_djmix
|
||||
# parameter format_mixtape
|
||||
# parameter format_demo
|
||||
# parameter format_fieldrec
|
||||
#
|
||||
# The input to this awk program is a sequence of lines containing the following
|
||||
# fields:
|
||||
# Field 1: The MusicBrainz ID of the release group
|
||||
# Field 2: The primary type
|
||||
# Field 3: A ;-delimited string of secondary types
|
||||
# Field 4: The original release year
|
||||
# Field 5: Title of the release group
|
||||
# Field 6: The artist as credited
|
||||
#
|
||||
# The output is a sequence of tab-delimited lines with the fields:
|
||||
# Field 1: Sort value to sort release groups
|
||||
# Field 2: The flag `format_local` if the release group is accessible locally,
|
||||
# and "" else.
|
||||
# Field 3: Release-group type
|
||||
# Field 4: Release-group string
|
||||
# Field 5: Release-group year
|
||||
# Field 6: Secondary types
|
||||
# Field 7: MusicBrainz artist ID of the release group artist, if there is one,
|
||||
# else "0"
|
||||
# Field 8: MusicBrainz release-group ID
|
||||
BEGIN {
|
||||
OFS="\t"
|
||||
local_releasegroups[0] = 0
|
||||
@@ -58,5 +124,5 @@ BEGIN {
|
||||
line_year = year ? format_year : ""
|
||||
sub("<<year>>", year, line_year)
|
||||
sortk = year ? year : 0
|
||||
print sortk, l, line_type, line_release, line_year, line_sectype, "0", id
|
||||
print sortk, l, line_type, line_release, line_year, line_sectype, artistid ? artistid : "0", id
|
||||
}
|
||||
|
@@ -1,3 +1,57 @@
|
||||
# List releases
|
||||
#
|
||||
# parameter file_local_releases: This is an optional parameter with the
|
||||
# path to a file with a MusicBrainz
|
||||
# release ID per line.
|
||||
# parameter format_release: Format for the release with the
|
||||
# placeholders <<status>>, <<tracks>>,
|
||||
# <<media>>, <<year>>, <<country>>, and
|
||||
# <<label>>.
|
||||
# parameter format_release_title_artist: Format to specify title and artist,
|
||||
# with the placeholders <<title>> and
|
||||
# <<artist>>.
|
||||
# parameter format_release_title: Format to specify the release title
|
||||
# with a placeholder <<title>>.
|
||||
# parameter format_release_artist: Format to specify the release artist
|
||||
# with a placeholder <<artist>>.
|
||||
# parameter format_local: String to indicate that the track is
|
||||
# locally available.
|
||||
# parameter rg_artist: Artist name of release group
|
||||
# (optional)
|
||||
# parameter rg_title: Title of release group (optional)
|
||||
# parameter rgid: MusicBrainz release-group ID
|
||||
# (optional)
|
||||
# Then, there are several format strings that indicate the status of a release.
|
||||
# The status are implicit from the parameter names:
|
||||
# parameter release_official
|
||||
# parameter release_promotion
|
||||
# parameter release_bootleg
|
||||
# parameter release_pseudo
|
||||
# parameter release_withdrawn
|
||||
# parameter release_expunged
|
||||
# parameter release_cancelled
|
||||
#
|
||||
# The input to this awk program is a sequence of lines containing the following
|
||||
# fields:
|
||||
# Field 1: MusicBrainz ID of the release
|
||||
# Field 2: Release status
|
||||
# Field 3: Release date
|
||||
# Field 4: Number of cover-art images
|
||||
# Field 5: Label string (', '-delimited)
|
||||
# Field 6: Total number of tracks
|
||||
# Field 7: Format (', '-delimited)
|
||||
# Field 8: Release country
|
||||
# Field 9: Release title
|
||||
# Field 10: Artist as credited
|
||||
#
|
||||
# The output is a sequence of tab-delimited lines with the fields:
|
||||
# Field 1: Sort value to sort release groups
|
||||
# Field 2: The flag `format_local` if the release is accessible locally, and ""
|
||||
# else.
|
||||
# Field 3: Release line
|
||||
# Field 4: MusicBrainz release-group ID if present, else "0"
|
||||
# Field 5: MusicBrainz release ID followed by ":" and then a path to the
|
||||
# decoration file (if it exists)
|
||||
BEGIN {
|
||||
OFS="\t"
|
||||
local_releases[0] = 0
|
||||
@@ -9,18 +63,17 @@ BEGIN {
|
||||
}
|
||||
}
|
||||
{
|
||||
parentid = $1
|
||||
id = $2
|
||||
status = $3
|
||||
year = substr($4, 1, 4) + 0
|
||||
id = $1
|
||||
status = $2
|
||||
year = substr($3, 1, 4) + 0
|
||||
year = year == 0 ? "" : year
|
||||
covercount = $5
|
||||
label = $6
|
||||
trackcnt = $7
|
||||
media = $8
|
||||
country = $9
|
||||
title = $10
|
||||
artist = $11
|
||||
covercount = $4
|
||||
label = $5
|
||||
trackcnt = $6
|
||||
media = $7
|
||||
country = $8
|
||||
title = $9
|
||||
artist = $10
|
||||
switch (status) {
|
||||
case "Official": line_status = release_official; break
|
||||
case "Promotion": line_status = release_promotion; break
|
||||
@@ -31,28 +84,28 @@ BEGIN {
|
||||
case "Cancelled": line_status = release_cancelled; break
|
||||
default: line_status = ""
|
||||
}
|
||||
line = release_format
|
||||
line = format_release
|
||||
if (artist != rg_artist && title != rg_title)
|
||||
line = line "\t" release_format_title_artist
|
||||
line = line "\t" format_release_title_artist
|
||||
else if (artist != rg_artist && title == rg_title)
|
||||
line = line "\t" release_format_artist
|
||||
line = line "\t" format_release_artist
|
||||
else if (artist == rg_artist && title != rg_title)
|
||||
line = line "\t" release_format_title
|
||||
line = line "\t" format_release_title
|
||||
else
|
||||
line = line "\t"
|
||||
|
||||
sub("<<status>>", line_status, line)
|
||||
sub("<<year>>", year, line)
|
||||
sub("<<tracks>>", trackcnt, line)
|
||||
sub("<<media>>", media, line)
|
||||
gsub("<<status>>", line_status, line)
|
||||
gsub("<<year>>", year, line)
|
||||
gsub("<<tracks>>", trackcnt, line)
|
||||
gsub("<<media>>", media, line)
|
||||
gsub("&", "\\\\&", label)
|
||||
sub("<<label>>", label, line)
|
||||
gsub("&", "\\\\&", titel)
|
||||
sub("<<title>>", title, line)
|
||||
gsub("<<label>>", label, line)
|
||||
gsub("&", "\\\\&", title)
|
||||
gsub("<<title>>", title, line)
|
||||
gsub("&", "\\\\&", artist)
|
||||
sub("<<artist>>", artist, line)
|
||||
sub("<<country>>", country, line)
|
||||
gsub("<<artist>>", artist, line)
|
||||
gsub("<<country>>", country, line)
|
||||
sortk = year ? year : 0
|
||||
l = local_releases[id] ? format_local : ""
|
||||
print sortk, l, line, parentid, id ":" local_releases[id]
|
||||
print sortk, l, line, rgid ? rgid : "0", id ":" local_releases[id]
|
||||
}
|
||||
|
733
src/main.sh
733
src/main.sh
@@ -2,28 +2,61 @@
|
||||
|
||||
set -eu
|
||||
|
||||
# Load helper methods
|
||||
# The user interface of this application is composed out of the following
|
||||
# views:
|
||||
# - VIEW_ARTIST: Show all release group of an artist
|
||||
# - VIEW_RELEASEGROUP: Show all releases within a release group
|
||||
# - VIEW_RELEASE: Show track list of a release
|
||||
# - VIEW_SEARCH_ARTIST: Interface to search artists on MusicBrainz
|
||||
# - VIEW_SEARCH_ALBUM: Interface to search albums (release groups) on MusicBrainz
|
||||
# - VIEW_LIST_ARTISTS: Presentation of all artists in the local database
|
||||
# - VIEW_LIST_ALBUMS: Presentation of all albums (release groups) in the local database
|
||||
# - VIEW_SELECT_ARTIST: Interface for the user to select an artist
|
||||
# - VIEW_PLAYLIST: View on the currently loaded playlist and playlist manipulation
|
||||
# - VIEW_QUIT: Exiting view, to terminate the application
|
||||
#
|
||||
# All views but the last three are handled within a single fzf instance. The
|
||||
# views VIEW_SELECT_ARTIST and VIEW_PLAYLIST run each in a separate fzf
|
||||
# instance. The last view (VIEW_QUIT) does nothing but terminate the
|
||||
# application.
|
||||
#
|
||||
# The fzf instance comprising VIEW_ARTIST - VIEW_LIST_ALBUMS is always in one
|
||||
# of two modes: normale mode (MODE_NORMAL) or insert mode (MODE_INSERT). Both
|
||||
# modes come with different key bindings. It is only in the insert mode that
|
||||
# the query string can be written.
|
||||
#
|
||||
# All views and modes are referred to by the following constants. The values
|
||||
# are arbitrary but must be distinct.
|
||||
VIEW_ARTIST="artist"
|
||||
VIEW_RELEASEGROUP="rg"
|
||||
VIEW_RELEASE="release"
|
||||
VIEW_SEARCH_ARTIST="search-artist"
|
||||
VIEW_SEARCH_ALBUM="search-album"
|
||||
VIEW_LIST_ARTISTS="list-artists"
|
||||
VIEW_LIST_ALBUMS="list-albums"
|
||||
VIEW_SELECT_ARTIST="select-artist"
|
||||
VIEW_PLAYLIST="playlist"
|
||||
VIEW_QUIT="quit"
|
||||
MODE_NORMAL="hidden"
|
||||
MODE_INSERT="show"
|
||||
|
||||
# Methods and variables used in main instance and subprocesses
|
||||
# Load application information
|
||||
. "sh/info.sh"
|
||||
|
||||
# Load helper methods
|
||||
. "sh/helper.sh"
|
||||
# Load logging methods
|
||||
. "sh/log.sh"
|
||||
|
||||
# Load configuration
|
||||
. "sh/config.sh"
|
||||
# Load query methods
|
||||
. "sh/query.sh"
|
||||
|
||||
# Load theme
|
||||
. "sh/theme.sh"
|
||||
# Load playback helper
|
||||
. "sh/playback.sh"
|
||||
|
||||
# Load keys
|
||||
. "sh/keys.sh"
|
||||
# Load playlist tools
|
||||
. "sh/playlist.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
# Load tools
|
||||
. "sh/tools.sh"
|
||||
|
||||
# Load MusicBrainz and Discogs methods
|
||||
# Load MusicBrainz, Discogs, and wiki methods
|
||||
. "sh/api.sh"
|
||||
|
||||
# Load mpv methods
|
||||
@@ -44,38 +77,302 @@ set -eu
|
||||
# Load list-generating methods
|
||||
. "sh/lists.sh"
|
||||
|
||||
# State management
|
||||
. "sh/state.sh"
|
||||
|
||||
# FZF handlers
|
||||
. "sh/fzf.sh"
|
||||
|
||||
# Load keys
|
||||
. "sh/keys.sh"
|
||||
|
||||
# Command-line options that may only be used internally.
|
||||
# --lines
|
||||
# --playback
|
||||
# --playlist
|
||||
# --action-playlistcursor
|
||||
# --action-filter
|
||||
# --action-gotoartist
|
||||
# --action-draw
|
||||
# --mbsearch
|
||||
# --preview
|
||||
# --show-keybindings
|
||||
# --remove-from-cache
|
||||
case "${1:-}" in
|
||||
"--fzf-reload")
|
||||
fzf_handle_reload
|
||||
"--lines")
|
||||
# Print lines that are fed into fzf.
|
||||
#
|
||||
# @argument $2: view
|
||||
# @argument $3: MusicBrainz ID
|
||||
#
|
||||
# The first argument `view` may be one of VIEW_ARTIST, VIEW_RELEASEGROUP,
|
||||
# VIEW_RELEASE, VIEW_LIST_ARTISTS, VIEW_LIST_ALBUMS, and VIEW_PLAYLIST. The
|
||||
# MusicBrainz ID is required for the first three views, and denotes the
|
||||
# MusicBrainz ID of the respective object.
|
||||
view=${2:-}
|
||||
mbid=${3:-}
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") list_releasegroups "$mbid" ;;
|
||||
"$VIEW_RELEASEGROUP") list_releases "$mbid" ;;
|
||||
"$VIEW_RELEASE") list_recordings "$mbid" ;;
|
||||
"$VIEW_LIST_ARTISTS") list_local_artists ;;
|
||||
"$VIEW_LIST_ALBUMS") list_local_releasegroups ;;
|
||||
"$VIEW_PLAYLIST") list_playlist ;;
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM") mb_results_async ;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-load")
|
||||
fzf_handle_load
|
||||
"--playback")
|
||||
# Control mpv instance (see `src/sh/playback.sh`)
|
||||
#
|
||||
# @argument $2: view
|
||||
# @argument $3: MusicBrainz ID of current object
|
||||
# @argument $4: MusicBrainz ID of selected object
|
||||
# @argument $5: Path to decoration file
|
||||
shift
|
||||
playback "$@"
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-info")
|
||||
fzf_info
|
||||
"--playlist")
|
||||
# Run playback commands (see `src/sh/playlits.sh`)
|
||||
#
|
||||
# @argument $2: playlist command
|
||||
shift
|
||||
playlist "$@"
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-change-reload")
|
||||
fzf_reload_after_change
|
||||
"--action-playlistcursor")
|
||||
# Print fzf command to replace cursor in playlist
|
||||
#
|
||||
# This prints the command read by a `transform` fzf binding, with which the
|
||||
# cursor is placed on the currently played track in the playlist view.
|
||||
pos=$(mpv_playlist_position)
|
||||
printf "pos(%s)" $((pos + 1))
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-change")
|
||||
fzf_handle_change
|
||||
"--action-filter")
|
||||
# fzf instructions to invoke filters
|
||||
#
|
||||
# @argument #2: mode
|
||||
# @argument #3: view
|
||||
#
|
||||
# This option takes the key pressed (FZF_KEY), translates it to the preset
|
||||
# query of that key in that view, and prints the fzf instructions which sets
|
||||
# that query.
|
||||
mode=$2
|
||||
view=$3
|
||||
q="$(default_query "$view" "$FZF_KEY")"
|
||||
[ "$q" ] && q="$q "
|
||||
printf "show-input+change-query(%s)" "$q"
|
||||
[ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input"
|
||||
exit 0
|
||||
;;
|
||||
"--fzf-key")
|
||||
fzf_handle_key "${2:-}" "${3:-}" "${4:-}"
|
||||
"--action-gotoartist")
|
||||
# fzf instructions to go to artist
|
||||
#
|
||||
# @argument $2: mode
|
||||
# @argument $3: view
|
||||
# @argument $4: MusicBrainz ID of current object
|
||||
# @argument $5: MusicBrainz ID of selected object
|
||||
#
|
||||
# With this option, fzf instructions are printed that divert the user to the
|
||||
# view VIEW_ARTIST of the artist of the selected object (of it is a
|
||||
# single-artist object), or that divert the user to a choice
|
||||
# (VIEW_SELECT_ARTIST) of all artists of the selected object. In the view
|
||||
# VIEW_PLAYLIST, the latter path is also taken for single-artist objects. The
|
||||
# reason for this is that VIEW_PLAYLIST and VIEW_ARTIST are not implemented
|
||||
# in the same fzf instance, and VIEW_SELECT_ARTIST already provides an
|
||||
# interface to switch from VIEW_PLAYLIST to VIEW_ARTIST.
|
||||
mode=$2
|
||||
view=$3
|
||||
mbid_cur="${4:-}"
|
||||
mbid="${5:-}"
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") j="$(mb_releasegroup "$mbid" | $JQ '."artist-credit"')" ;;
|
||||
"$VIEW_RELEASEGROUP") j="$(mb_release "$mbid" | $JQ '."artist-credit"')" ;;
|
||||
"$VIEW_RELEASE" | "$VIEW_PLAYLIST") j="$(mb_release "$mbid_cur" | $JQ ".media | map(.tracks) | flatten[] | select(.id == \"$mbid\") | .\"artist-credit\"")" ;;
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") aid="$mbid" ;;
|
||||
esac
|
||||
if [ "$view" = "$VIEW_PLAYLIST" ]; then
|
||||
printf "print(%s)+print(%s)+print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" "$view" "$mbid_cur"
|
||||
exit 0
|
||||
fi
|
||||
if [ "${j:-}" ]; then
|
||||
cnt=$(echo "$j" | $JQ 'length')
|
||||
[ "$cnt" -eq 1 ] && aid="$(echo "$j" | $JQ '.[0].artist.id')"
|
||||
fi
|
||||
[ "${aid:-}" ] && $0 --action-draw "$mode" "$VIEW_ARTIST" "$aid" || printf "print(%s)+print(%s)+print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" "$view" "$mbid_cur"
|
||||
exit 0
|
||||
;;
|
||||
"--action-draw")
|
||||
# Generate fzf command to draw screen.
|
||||
#
|
||||
# @argument $2: mode (default `normal`)
|
||||
# @argument $3: view (default list artists)
|
||||
# @argument $4: MusicBrainz ID (optional)
|
||||
# @argument $5: level (optional)
|
||||
#
|
||||
# The argument `level` specifies the view relative to `view`: If `level` is
|
||||
# set to +1, then the specified MusicBrainz ID is an ID of an object one level
|
||||
# deeper than `view`. Alternatively, the argument `level` may be set to `-1`.
|
||||
# Anything else is interpreted as "on the level of `view`".
|
||||
#
|
||||
# The choice of possible arguments ($5) depends on the view.
|
||||
# These views are independent of the MusicBrainz ID ($4) and of the argument
|
||||
# ($5):
|
||||
# - VIEW_SEARCH_ARTIST: Get ready to query MusicBrainz for artists
|
||||
# - VIEW_SEARCH_ALBUM: Get ready to query MusicBrainz for albums
|
||||
# - VIEW_LIST_ARTISTS: List all locally available artists
|
||||
# - VIEW_LIST_ALBUMS: List al locally available albums
|
||||
#
|
||||
# If no argument ($5) is specified, then the remaining views act as follows:
|
||||
# - VIEW_ARTIST: Display all release groups of that artist
|
||||
# - VIEW_RELEASEGROUP: Display all releases within that release group
|
||||
# - VIEW_RELEASE: Display track list of specified release
|
||||
#
|
||||
# Here, if the argument is set to `-1`, then the parent entry is displayed:
|
||||
# - VIEW_ARTIST: Divert view to VIEW_LIST_ARTISTS
|
||||
# - VIEW_RELEASEGROUP: For single-artist release groups, divert to
|
||||
# VIEW_ARTIST of that artist, else display the artist selection.
|
||||
# - VIEW_RELEASE: Divert view to VIEW_LIST_RELEASEGROUP.
|
||||
#
|
||||
# Alternatively, if the argument is set to `+1`, then the child entry is
|
||||
# displayed:
|
||||
# - VIEW_ARTIST: Divert view to VIEW_LIST_ARTISTS
|
||||
# - VIEW_RELEASEGROUP: For single-artist release groups, divert to
|
||||
# VIEW_ARTIST of that artist, else display the artist selection.
|
||||
# - VIEW_RELEASE: Divert view to VIEW_LIST_RELEASEGROUP.
|
||||
mode="${2:-"$MODE_NORMAL"}"
|
||||
view="${3:-"$VIEW_LIST_ARTISTS"}"
|
||||
mbid="${4:-}"
|
||||
level="${5:-}"
|
||||
# Change state, if we are being diverted.
|
||||
case "$level" in
|
||||
"-1")
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
view="$VIEW_LIST_ARTISTS"
|
||||
mbid=""
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
view="$VIEW_ARTIST"
|
||||
mbid="$(mb_releasegroup "$mbid" | $JQ '."artist-credit"[0].artist.id')"
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
view="$VIEW_RELEASEGROUP"
|
||||
mbid="$(mb_release "$mbid" | $JQ '."release-group".id')"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"+1")
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") view="$VIEW_ARTIST" ;;
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") view="$VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASEGROUP") view="$VIEW_RELEASE" ;;
|
||||
esac
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
# Set initial query
|
||||
q="$(default_query "$view")"
|
||||
[ "$q" ] && q="$q "
|
||||
printf "show-input+change-query(%s)" "$q"
|
||||
# Store current state
|
||||
printf "+change-list-label(%s)" "$view"
|
||||
# Set header
|
||||
fzf_command_set_header "$view" "$mbid"
|
||||
# Set preview window
|
||||
case "$view" in
|
||||
"$VIEW_LIST_ARTISTS" | "$VIEW_SEARCH_ARTIST") printf "+show-preview" ;;
|
||||
*) printf "+hide-preview" ;;
|
||||
esac
|
||||
# Handle MusicBrainz search views
|
||||
# - `change` trigger for async. MusicBrainz search
|
||||
# - input visible but search disabled
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM") printf "+rebind(change)+disable-search" ;;
|
||||
*) printf "+unbind(change)+enable-search" ;;
|
||||
esac
|
||||
# Load lines
|
||||
printf "+reload($0 --lines %s %s)" "$view" "$mbid"
|
||||
[ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input"
|
||||
exit 0
|
||||
;;
|
||||
"--mbsearch")
|
||||
# Trigger search on MusicBrainz
|
||||
#
|
||||
# @argument $2: view
|
||||
#
|
||||
# This stops any search being executed and initiates a new query through the
|
||||
# MusicBrainz API. The results will be made available through the ``--lines
|
||||
# <view>`` command.
|
||||
mb_search_async "$2"
|
||||
exit 0
|
||||
;;
|
||||
"--preview")
|
||||
# Generate content for preview window
|
||||
#
|
||||
# @argument $2: view
|
||||
# @argument $3: MusicBrainz ID of selected item
|
||||
#
|
||||
# This prints the text to be displayed in the preview window.
|
||||
view=$2
|
||||
mbid="${3:-}"
|
||||
case "$view" in
|
||||
"$VIEW_LIST_ARTISTS" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SELECT_ARTIST") preview_artist "$mbid" ;;
|
||||
*) preview_nothing ;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
"--show-keybindings")
|
||||
# Print keybindings for current view
|
||||
#
|
||||
# @argument $2: view
|
||||
print_keybindings "$2"
|
||||
exit 0
|
||||
;;
|
||||
"--remove-from-cache")
|
||||
# Remove entry from cache to reload
|
||||
#
|
||||
# @argument $2: view
|
||||
# @argument $3: MusicBrainz ID of current object
|
||||
# @argument $4: MusicBrainz ID of selected object
|
||||
case "$2" in
|
||||
"$VIEW_ARTIST")
|
||||
cache_rm_artist "$3"
|
||||
cache_rm_releasegroup "$4"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
cache_rm_releasegroup "$3"
|
||||
cache_rm_release "$4"
|
||||
;;
|
||||
"$VIEW_RELEASE") cache_rm_release "$3" ;;
|
||||
"$VIEW_LIST_ALBUMS" | "$VIEW_SEARCH_ALBUM") cache_rm_releasegroup "$4" ;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Load configuration
|
||||
. "sh/config.sh"
|
||||
|
||||
# Load theme
|
||||
. "sh/theme.sh"
|
||||
|
||||
# Load tools
|
||||
. "sh/tools.sh"
|
||||
|
||||
# Load AWK scripts
|
||||
. "sh/awk.sh"
|
||||
|
||||
# Non-interactive user commands intended to the user. These commands do not
|
||||
# require temporary files, fzf, nor the mpv instance.
|
||||
case "${1:-}" in
|
||||
"--decorate")
|
||||
# Decorate directory with tagged audio files
|
||||
#
|
||||
# @argument $2: path
|
||||
#
|
||||
# This method reads the tags of the audio files in the specified directory.
|
||||
# If the audio files contain MusicBrainz tags, and they are consistent, then
|
||||
# a decoration file is written to that directory.
|
||||
[ ! "${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
|
||||
@@ -84,53 +381,128 @@ case "${1:-}" in
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
"--reload")
|
||||
"--decorate-as")
|
||||
# Decorate the specified directory as given MusicBrainz release
|
||||
#
|
||||
# @argument $2: path
|
||||
# @argument $3: MusicBrainz release ID
|
||||
[ ! "${2:-}" ] && err "You did not specify a directory." && exit 1
|
||||
[ ! -d "$2" ] && err "Path $2 does not point to a directory." && exit 1
|
||||
[ ! "${3:-}" ] && err "You did not specify a MusicBrainz release ID." && exit 1
|
||||
[ ! "$(mb_release "$3" | $JQ '.title // ""')" ] && err "Did you specify a correct MusicBrainz release ID?" && exit 1
|
||||
if ! decorate_as "$2" "$3"; then
|
||||
err "Something went wrong."
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
"--reload-database")
|
||||
# Reload database of local music
|
||||
#
|
||||
# @argument $2: path
|
||||
#
|
||||
# This method reconstructs the database of locally available music. This is
|
||||
# done by traversing the directories under `path` and looking for decorated
|
||||
# entries.
|
||||
[ ! "${2:-}" ] && err "Path to decorated music is missing." && exit 1
|
||||
[ ! -d "$2" ] && err "Path does not point to a directory." && exit 1
|
||||
info "Reloading information of local music directory $2"
|
||||
load_local "$2" || err "Failed to load local data"
|
||||
reloaddb "$2" || err "Failed to load local data"
|
||||
info "Done"
|
||||
exit 0
|
||||
;;
|
||||
"--internal-preview-artist")
|
||||
__preview_artist "$2"
|
||||
exit 0
|
||||
;;
|
||||
"--playlist")
|
||||
list_playlist
|
||||
exit 0
|
||||
;;
|
||||
"--help")
|
||||
# Print help string
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTION]
|
||||
|
||||
GENERAL OPTIONS:
|
||||
--help Show this help and exit.
|
||||
--help Show this help and exit
|
||||
--artists Default options, list artists of local music
|
||||
--albums List albums of local music
|
||||
--search-artist [<query>] Search artist on MusicBrainz
|
||||
--search-album [<query>] Search album on MusicBrainz
|
||||
--search-artist Search artist on MusicBrainz
|
||||
--search-album Search album on MusicBrainz
|
||||
--artist <mbid> List release groups of given artist <mbid>
|
||||
--releasegroup <mbid> List releases in given release group <mbid>
|
||||
--release <mbid> Show release given by <mbid>
|
||||
--ni-search-artist [<query>] Non-interactive search on MusicBrainz
|
||||
--ni-search-album [<query>] Non-interactive search on MusicBrainz
|
||||
|
||||
MANAGE LOCAL MUSIC:
|
||||
--decorate <path> Decorate directory containing a tagged release
|
||||
--reload <path> Populate database with decorated local music from <path>
|
||||
--decorate-as <path> <mbid> Decorate directory as the relase <mbid>
|
||||
--reload-database <path> Populate database with decorated local music from <path>
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
"--refresh-view")
|
||||
precompute_view
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Interactive user commands
|
||||
# If no unknown command is passed, then this will continue to starting the mpv
|
||||
# instance and fzf.
|
||||
case "${1:-}" in
|
||||
"--artist")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Artist ID not specified (see --help)" && exit 1
|
||||
VIEW="$VIEW_ARTIST"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID="$2"
|
||||
;;
|
||||
"--releasegroup")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Release-Group ID not specified (see --help)" && exit 1
|
||||
VIEW="$VIEW_RELEASEGROUP"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID="$2"
|
||||
;;
|
||||
"--release")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Release ID not specified (see --help)" && exit 1
|
||||
VIEW="$VIEW_RELEASE"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID="$2"
|
||||
;;
|
||||
"--search-artist")
|
||||
VIEW="$VIEW_SEARCH_ARTIST"
|
||||
MODE="$MODE_INSERT"
|
||||
MBID=""
|
||||
;;
|
||||
"--search-album")
|
||||
VIEW="$VIEW_SEARCH_ALBUM"
|
||||
MODE="$MODE_INSERT"
|
||||
MBID=""
|
||||
;;
|
||||
"--artists" | "")
|
||||
VIEW="$VIEW_LIST_ARTISTS"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID=""
|
||||
;;
|
||||
"--albums")
|
||||
VIEW="$VIEW_LIST_ALBUMS"
|
||||
MODE="$MODE_NORMAL"
|
||||
MBID=""
|
||||
;;
|
||||
*)
|
||||
err "Unknown option $1 (see --help)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Start application:
|
||||
# - load and export preset filters
|
||||
# - set title
|
||||
# - check for missing data from MusicBrainz
|
||||
# - precompute main views
|
||||
# - get temporary directory for temporary files
|
||||
# - start mpv daemon
|
||||
# - enter main loop and start fzf
|
||||
|
||||
# Load filters
|
||||
. "sh/filter.sh"
|
||||
|
||||
# Set window title
|
||||
printf '\033]0;%s\007' "$WINDOW_TITLE"
|
||||
|
||||
# Check if the required json files are present
|
||||
local_files_present || load_missing_files
|
||||
# Generate views
|
||||
precompute_views
|
||||
|
||||
# Generate filenames for temporary files
|
||||
tmpdir=$(mktemp -d)
|
||||
LOCKFILE="$tmpdir/lock"
|
||||
@@ -139,114 +511,219 @@ PIDFILE="$tmpdir/pid"
|
||||
trap 'rm -rf "$tmpdir"' EXIT INT
|
||||
export LOCKFILE RESULTS PIDFILE
|
||||
|
||||
statedir=$(mktemp -d)
|
||||
STATEFILE="$statedir/state"
|
||||
ARGSFILE="$statedir/state-args"
|
||||
STATEFILE_LAST="$statedir/state2"
|
||||
ARGSFILE_LAST="$statedir/state-args2"
|
||||
touch "$STATEFILE" "$ARGSFILE" "$STATEFILE_LAST" "$ARGSFILE_LAST"
|
||||
export STATEFILE ARGSFILE STATEFILE_LAST ARGSFILE_LAST
|
||||
|
||||
# Views and modes
|
||||
VIEW_ARTIST="artist"
|
||||
VIEW_RELEASEGROUP="rg"
|
||||
VIEW_RELEASE="release"
|
||||
VIEW_SEARCH_ARTIST="search-artist"
|
||||
VIEW_SEARCH_ALBUM="search-album"
|
||||
VIEW_LIST_ARTISTS="list-artists"
|
||||
VIEW_LIST_ALBUMS="list-albums"
|
||||
VIEW_SELECT_ARTIST="select-artist"
|
||||
VIEW_PLAYLIST="playlist"
|
||||
MODE_NORMAL="normal"
|
||||
MODE_INSERT="insert"
|
||||
export VIEW_ARTIST VIEW_RELEASEGROUP VIEW_RELEASE VIEW_SEARCH_ARTIST \
|
||||
VIEW_SEARCH_ALBUM VIEW_LIST_ARTISTS VIEW_LIST_ALBUMS VIEW_SELECT_ARTIST \
|
||||
VIEW_PLAYLIST MODE_NORMAL MODE_INSERT
|
||||
|
||||
case "${1:-}" in
|
||||
"--artist")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Artist ID not specified (see --help)" && exit 1
|
||||
state_init "$VIEW_ARTIST" "$MODE_NORMAL" "$2"
|
||||
;;
|
||||
"--releasegroup")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Release-Group ID not specified (see --help)" && exit 1
|
||||
state_init "$VIEW_RELEASEGROUP" "$MODE_NORMAL" "$2"
|
||||
;;
|
||||
"--release")
|
||||
[ ! "${2:-}" ] && err "MusicBrainz Release ID not specified (see --help)" && exit 1
|
||||
state_init "$VIEW_RELEASE" "$MODE_NORMAL" "$2"
|
||||
;;
|
||||
"--search-artist") state_init "$VIEW_SEARCH_ARTIST" "$MODE_INSERT" "${2:-}" ;;
|
||||
"--search-album") state_init "$VIEW_SEARCH_ALBUM" "$MODE_INSERT" "${2:-}" ;;
|
||||
"--artists" | "") state_init "$VIEW_LIST_ARTISTS" "$MODE_NORMAL" "" ;;
|
||||
"--albums") state_init "$VIEW_LIST_ALBUMS" "$MODE_NORMAL" "" ;;
|
||||
*)
|
||||
err "Unknown option $1 (see --help)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Start mpv
|
||||
mpv_start
|
||||
|
||||
# $KEYS_PLAY main loop
|
||||
# main loop
|
||||
# states are stored in (in)visible labels
|
||||
#
|
||||
# mode: [$MODE_NORMAL, $MODE_INSERT]
|
||||
# The mode is reflected on the input visibility. The variable $FZF_INPUT_STATE
|
||||
# is set to "hidden" if and only if the mode is `normal`. To swtich to `normal`
|
||||
# mode, we call `hide-input`. To switch to insert mode, we call `show-input`.
|
||||
#
|
||||
# view: [$VIEW_*]
|
||||
# The view is stored in $FZF_LIST_LABEL. To set the view, call
|
||||
# `change-list-label($VIEW)`.
|
||||
#
|
||||
# argument: string
|
||||
# The argument is stored in $FZF_LIST_LABEL. To set the argument, call
|
||||
# `change-list-label($arg)`.
|
||||
IN_NORMAL_MODE="[ \$FZF_INPUT_STATE = hidden ]"
|
||||
IN_VIEW_PATTERN="[ \$FZF_LIST_LABEL = %s ]"
|
||||
IN_LIST_ARTISTS_VIEW="$(printf "$IN_VIEW_PATTERN" "$VIEW_LIST_ARTISTS")"
|
||||
FZF_CURRENT_MODE="\$FZF_INPUT_STATE"
|
||||
FZF_CURRENT_VIEW="\$FZF_LIST_LABEL"
|
||||
FZF_RELOAD_PLAYLIST="reload-sync($0 --lines $VIEW_PLAYLIST)"
|
||||
FZF_POS_PLAYLIST="transform:$0 --action-playlistcursor"
|
||||
PUT_FZF_KEY_LOGIC="case \$FZF_KEY in space) echo \"put( )\";; left) echo backward-char;; right) echo forward-char;; backspace|bspace|bs) echo backward-delete-char;; delete|del) echo delete-char;; *) echo \"put(\$FZF_KEY)\";; esac"
|
||||
while true; do
|
||||
view=$(state_get_view)
|
||||
mode=$(state_get_mode)
|
||||
args=$(state_get_args)
|
||||
case "$view" in
|
||||
case "$VIEW" in
|
||||
"$VIEW_SELECT_ARTIST")
|
||||
sel=$(
|
||||
echo "$args" |
|
||||
list_artists_from_json |
|
||||
$FZF \
|
||||
--bind="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,\
|
||||
$KEYS_BROWSE,\
|
||||
$KEYS_OPEN,\
|
||||
$KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
echo "$ARGS" | list_artists_from_json | $FZF \
|
||||
--bind="$KEYS_DOWN:down" \
|
||||
--bind="$KEYS_UP:up" \
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="enter,$KEYS_IN:print($VIEW_ARTIST)+accept" \
|
||||
--bind="$KEYS_OUT,$KEYS_QUIT:print($LASTVIEW)+print($LASTARG)+accept" \
|
||||
--bind="$KEYS_LIST_ARTISTS:print($VIEW_LIST_ARTISTS)+accept" \
|
||||
--bind="$KEYS_LIST_ALBUMS:print($VIEW_LIST_ALBUMS)+accept" \
|
||||
--bind="$KEYS_SEARCH_ARTIST:print($VIEW_SEARCH_ARTIST)+accept" \
|
||||
--bind="$KEYS_SEARCH_ALBUM:print($VIEW_SEARCH_ALBUM)+accept" \
|
||||
--bind="$KEYS_BROWSE:execute-silent:open \"https://musicbrainz.org/artist/{r3}\"" \
|
||||
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+print()+accept" \
|
||||
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $VIEW_SELECT_ARTIST" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
|
||||
--bind="$KEYS_PREVIEW_OPEN:show-preview" \
|
||||
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
|
||||
--bind="$KEYS_FILTER_LOCAL:change-query($QUERY_LOCAL )" \
|
||||
-0 -1 \
|
||||
--border="bold" \
|
||||
--border-label="Select artist" \
|
||||
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
|
||||
--preview="$0 --preview $VIEW_SELECT_ARTIST {3}" \
|
||||
--delimiter="\t" \
|
||||
--prompt="$SEARCH_PROMPT" \
|
||||
--margin="5%,20%" \
|
||||
--bind="$KEYS_FILTER_LOCAL:change-query('$QUERY_LOCAL' )" \
|
||||
--accept-nth="{3}" \
|
||||
--with-nth="{1}" || true
|
||||
)
|
||||
[ "$sel" ] && state_update "$VIEW_ARTIST" "$mode" "$sel" || state_revert
|
||||
lines=$(echo "$sel" | wc -l)
|
||||
if [ "$lines" -eq 1 ]; then
|
||||
VIEW="$VIEW_ARTIST"
|
||||
MBID="$sel"
|
||||
else
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
MBID="$(echo "$sel" | head -2 | tail -1)"
|
||||
fi
|
||||
LASTVIEW="$VIEW_SELECT_ARTIST"
|
||||
LASTARG="$ARGS"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
list_playlist |
|
||||
$FZF \
|
||||
sel=$(
|
||||
list_playlist | $FZF \
|
||||
--reverse \
|
||||
--no-sort \
|
||||
--border=double \
|
||||
--border-label=" Playlist " \
|
||||
--border-label="╢ Playlist ╟" \
|
||||
--no-input \
|
||||
--margin="2%,10%" \
|
||||
--bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
--bind="r,ctrl-r:reload:$0 --playlist" \
|
||||
--bind="$KEYS_DOWN,$KEYS_N_DOWN:down" \
|
||||
--bind="$KEYS_UP,$KEYS_N_UP:up" \
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="$KEYS_N_BOT:last" \
|
||||
--bind="$KEYS_N_TOP:first" \
|
||||
--bind="$KEYS_OUT,$KEYS_N_OUT,$KEYS_QUIT,$KEYS_N_QUIT:print($LASTVIEW)+print($LASTARG)+print($VIEW_PLAYLIST)+print()+accept" \
|
||||
--bind="$KEYS_SELECT_ARTIST:transform:$0 --action-gotoartist $MODE_NORMAL $VIEW_PLAYLIST {2} {3}" \
|
||||
--bind="$KEYS_LIST_ARTISTS:print($VIEW_LIST_ARTISTS)+accept" \
|
||||
--bind="$KEYS_LIST_ALBUMS:print($VIEW_LIST_ALBUMS)+accept" \
|
||||
--bind="$KEYS_SEARCH_ARTIST:print($VIEW_SEARCH_ARTIST)+accept" \
|
||||
--bind="$KEYS_SEARCH_ALBUM:print($VIEW_SEARCH_ALBUM)+accept" \
|
||||
--bind="$KEYS_BROWSE:execute-silent:open \"https://musicbrainz.org/\track/{r3}\"" \
|
||||
--bind="$KEYS_OPEN:execute-silent:open \"\$(dirname {4})\"" \
|
||||
--bind="$KEYS_N_YANK:execute-silent:printf {3} | $CLIP)" \
|
||||
--bind="$KEYS_YANK_CURRENT:execute-silent:printf {2} | $CLIP" \
|
||||
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $VIEW_PLAYLIST" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
|
||||
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
|
||||
--bind="$KEYS_PLAYBACK,$KEYS_N_PLAYBACK:transform($0 --playback $VIEW_PLAYLIST {2} {3} {4})+$FZF_RELOAD_PLAYLIST+$FZF_POS_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_RELOAD:$FZF_RELOAD_PLAYLIST+$FZF_POS_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_REMOVE:execute-silent($0 --playlist $PLAYLIST_CMD_REMOVE)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_UP:execute-silent($0 --playlist $PLAYLIST_CMD_UP)+up+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_DOWN:execute-silent($0 --playlist $PLAYLIST_CMD_DOWN)+down+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR:execute-silent($0 --playlist $PLAYLIST_CMD_CLEAR)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR_ABOVE:execute-silent($0 --playlist $PLAYLIST_CMD_CLEAR_ABOVE)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_CLEAR_BELOW:execute-silent($0 --playlist $PLAYLIST_CMD_CLEAR_BELOW)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_SHUFFLE:execute-silent($0 --playlist $PLAYLIST_CMD_SHUFFLE)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_UNSHUFFLE:execute-silent($0 --playlist $PLAYLIST_CMD_UNSHUFFLE)+$FZF_RELOAD_PLAYLIST" \
|
||||
--bind="$KEYS_PLAYLIST_GOTO_RELEASE:print($VIEW_RELEASE)+accept" \
|
||||
--delimiter="\t" \
|
||||
--with-nth="{1}" >/dev/null
|
||||
--with-nth="{1}" \
|
||||
--accept-nth="{2}" || true
|
||||
)
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
ARGS="$(echo "$sel" | head -2 | tail -1)"
|
||||
MBID=$ARGS
|
||||
LASTVIEW="$(echo "$sel" | head -3 | tail -1)"
|
||||
LASTARG="$(echo "$sel" | head -4 | tail -1)"
|
||||
;;
|
||||
*) # Main instance
|
||||
"$VIEW_QUIT")
|
||||
break
|
||||
;;
|
||||
*)
|
||||
# Main instance
|
||||
#
|
||||
# KEY-BINDINGS:
|
||||
# Key variables contain comma-delimited sequences of keys. Every key
|
||||
# variable starts with `KEYS_`. Key variables with the prefix `KEYS_I_` are
|
||||
# exclusive to the `insert` mode. Key variables with the prefix `KEYS_N_`
|
||||
# are exclusive to the `normal` mode. All other keys are bound to both
|
||||
# modes. It is important that the keys used in `KEYS_N_` variables are
|
||||
# naturally printable or modifications of the input string. See
|
||||
# `$PUT_FZF_KEY_LOGIC` for details.
|
||||
#
|
||||
# Here is a list of all keys grouped by type (see `src/sh/keys.sh`).
|
||||
#--bind="start:change-list-label($VIEW)+change-list-label($MBID)+$MODE-input+transform:$0 --display" \
|
||||
sel=$(
|
||||
$FZF \
|
||||
printf "" | $FZF \
|
||||
--reverse \
|
||||
--bind="start:reload:$0 --fzf-reload" \
|
||||
--bind="load:transform:$0 --fzf-load" \
|
||||
--bind="change:execute-silent($0 --fzf-change &)+reload:$0 --fzf-change-reload" \
|
||||
--bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \
|
||||
--expect="ctrl-c" \
|
||||
--info="inline-right" \
|
||||
--info-command="$0 --fzf-info" \
|
||||
--header-first \
|
||||
--header-border="bottom" \
|
||||
--bind="start:transform:$0 --action-draw $MODE $VIEW $MBID" \
|
||||
--bind="$KEYS_I_NORMAL:transform:$IN_NORMAL_MODE || echo hide-input" \
|
||||
--bind="$KEYS_N_INSERT:transform:$IN_NORMAL_MODE && echo show-input || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_DOWN:down" \
|
||||
--bind="$KEYS_UP:up" \
|
||||
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
|
||||
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
|
||||
--bind="$KEYS_N_DOWN:transform:$IN_NORMAL_MODE && echo down || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_UP:transform:$IN_NORMAL_MODE && echo up || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_BOT:transform:$IN_NORMAL_MODE && echo last || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_TOP:transform:$IN_NORMAL_MODE && echo first || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_IN:transform:[ {3} ] && $0 --action-draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {3} \"+1\"" \
|
||||
--bind="$KEYS_OUT:transform:[ {2} ] && $0 --action-draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2} \"-1\"" \
|
||||
--bind="$KEYS_N_IN:transform:$IN_NORMAL_MODE && ([ {3} ] && $0 --action-draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {3} \"+1\") || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_N_OUT:transform:$IN_NORMAL_MODE && ([ {2} ] && $0 --action-draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2} \"-1\") || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_SELECT_ARTIST:transform:$0 --action-gotoartist $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2} {3}" \
|
||||
--bind="$KEYS_LIST_ARTISTS:transform:$0 --action-draw \$FZF_INPUT_STATE $VIEW_LIST_ARTISTS" \
|
||||
--bind="$KEYS_LIST_ALBUMS:transform:$0 --action-draw \$FZF_INPUT_STATE $VIEW_LIST_ALBUMS" \
|
||||
--bind="$KEYS_SEARCH_ARTIST:transform:$0 --action-draw $MODE_INSERT $VIEW_SEARCH_ARTIST" \
|
||||
--bind="$KEYS_SEARCH_ALBUM:transform:$0 --action-draw $MODE_INSERT $VIEW_SEARCH_ALBUM" \
|
||||
--bind="$KEYS_SWITCH_ARTIST_ALBUM:transform:case $FZF_CURRENT_VIEW in
|
||||
$VIEW_LIST_ARTISTS) $0 --action-draw $FZF_CURRENT_MODE $VIEW_LIST_ALBUMS ;;
|
||||
$VIEW_LIST_ALBUMS) $0 --action-draw $FZF_CURRENT_MODE $VIEW_LIST_ARTISTS ;;
|
||||
$VIEW_SEARCH_ARTIST) $0 --action-draw $MODE_INSERT $VIEW_SEARCH_ALBUM ;;
|
||||
$VIEW_SEARCH_ALBUM) $0 --action-draw $MODE_INSERT $VIEW_SEARCH_ARTIST ;;
|
||||
esac" \
|
||||
--bind="$KEYS_SWITCH_LOCAL_REMOTE:transform:case $FZF_CURRENT_VIEW in
|
||||
$VIEW_LIST_ARTISTS) $0 --action-draw $MODE_INSERT $VIEW_SEARCH_ARTIST ;;
|
||||
$VIEW_LIST_ALBUMS) $0 --action-draw $MODE_INSERT $VIEW_SEARCH_ALBUM ;;
|
||||
$VIEW_SEARCH_ARTIST) $0 --action-draw $MODE_NORMAL $VIEW_LIST_ARTISTS ;;
|
||||
$VIEW_SEARCH_ALBUM) $0 --action-draw $MODE_NORMAL $VIEW_LIST_ALBUMS ;;
|
||||
esac" \
|
||||
--bind="$KEYS_FILTER:transform:$0 --action-filter $FZF_CURRENT_MODE $FZF_CURRENT_VIEW" \
|
||||
--bind="$KEYS_BROWSE:execute-silent:
|
||||
[ {3} ] || exit 0
|
||||
case $FZF_CURRENT_VIEW in
|
||||
$VIEW_LIST_ARTISTS | $VIEW_SEARCH_ARTIST) t=artist ;;
|
||||
$VIEW_ARTIST | $VIEW_SEARCH_ALBUM | $VIEW_LIST_ALBUMS) t=release-group ;;
|
||||
$VIEW_RELEASEGROUP) t=release ;;
|
||||
$VIEW_RELEASE) t=track ;;
|
||||
esac
|
||||
open \"https://musicbrainz.org/\$t/{r3}\"" \
|
||||
--bind="$KEYS_OPEN:execute-silent:
|
||||
[ {4} ] || exit 0
|
||||
open \"\$(dirname {4})\"" \
|
||||
--bind="$KEYS_N_YANK:transform:$IN_NORMAL_MODE && echo \"execute-silent(printf {3} | $CLIP)\" || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_YANK_CURRENT:execute-silent:printf {2} | $CLIP" \
|
||||
--bind="$KEYS_SHOW_PLAYLIST:transform:echo \"print($VIEW_PLAYLIST)+print()+print($FZF_CURRENT_VIEW)+print({2})+accept\"" \
|
||||
--bind="$KEYS_KEYBINDINGS:preview:$0 --show-keybindings $FZF_CURRENT_VIEW" \
|
||||
--bind="$KEYS_REFRESH:execute-silent($0 --remove-from-cache $FZF_CURRENT_VIEW {2} {3})+transform:$0 --action-draw $FZF_CURRENT_MODE $FZF_CURRENT_VIEW {2}" \
|
||||
--bind="$KEYS_QUIT:print($VIEW_QUIT)+accept" \
|
||||
--bind="$KEYS_N_QUIT:transform:$IN_NORMAL_MODE && ($IN_LIST_ARTISTS_VIEW && echo \"print($VIEW_QUIT)+accept\" || $0 --action-draw $MODE_NORMAL $VIEW_LIST_ARTISTS) || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_DOWN:preview-down" \
|
||||
--bind="$KEYS_SCROLL_PREVIEW_UP:preview-up" \
|
||||
--bind="$KEYS_PREVIEW_OPEN:show-preview" \
|
||||
--bind="$KEYS_PREVIEW_CLOSE:hide-preview" \
|
||||
--bind="$KEYS_PLAYBACK:transform:$0 --playback $FZF_CURRENT_VIEW {2} {3} {4}" \
|
||||
--bind="$KEYS_N_PLAYBACK:transform:$IN_NORMAL_MODE && $0 --playback $FZF_CURRENT_VIEW {2} {3} {4} || $PUT_FZF_KEY_LOGIC" \
|
||||
--bind="W:execute-silent:echo 1 >> /tmp/foo; echo $FZF_CURRENT_VIEW >> /tmp/foo; echo 2 >> /tmp/foo" \
|
||||
--bind="change:execute-silent($0 --mbsearch $FZF_CURRENT_VIEW &)+reload:$0 --lines $FZF_CURRENT_VIEW" \
|
||||
--preview-window="right,25%,border-left,wrap,<30(hidden)" \
|
||||
--preview="$0 --internal-preview-artist {3}" \
|
||||
--preview="$0 --preview $FZF_CURRENT_VIEW {3}" \
|
||||
--delimiter="\t" \
|
||||
--with-nth="{1}" || true
|
||||
)
|
||||
[ "$(echo "$sel" | head -1)" = "ctrl-c" ] && break
|
||||
VIEW="$(echo "$sel" | head -1)"
|
||||
ARGS="$(echo "$sel" | head -2 | tail -1)"
|
||||
LASTVIEW="$(echo "$sel" | head -3 | tail -1)"
|
||||
LASTARG="$(echo "$sel" | head -4 | tail -1)"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
@@ -1,9 +1,30 @@
|
||||
# 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
|
||||
USER_AGENT="$APP_NAME/$APP_VERSION ($APP_WEBSITE)"
|
||||
SLEEP_ON_ERROR=1
|
||||
export MB_BROWSE_STEPS
|
||||
export MB_MAX_RETRIES MB_BROWSE_STEPS USER_AGENT SLEEP_ON_ERROR
|
||||
|
||||
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
|
||||
@@ -79,48 +100,79 @@ __api_mb() {
|
||||
"https://musicbrainz.org/ws/2/release-group"
|
||||
;;
|
||||
esac
|
||||
if ! $JQ -e '.error' "$tmpout" >/dev/null 2>/dev/stdout; then
|
||||
errormsg=$($JQ -e '.error // ""' "$tmpout")
|
||||
if [ "$errormsg" ]; then
|
||||
err "Failed to fetch MusicBrainz data for $1 $2: $errormsg"
|
||||
echo "$errormsg" | grep -q -i "not found" && break
|
||||
echo "$errormsg" | grep -q -i "invalid" && break
|
||||
sleep "$SLEEP_ON_ERROR"
|
||||
else
|
||||
cat "$tmpout"
|
||||
rm -f "$tmpout"
|
||||
return 0
|
||||
else
|
||||
sleep "$SLEEP_ON_ERROR"
|
||||
fi
|
||||
done
|
||||
rm -f "$tmpout"
|
||||
err "Failed to fetch MusicBrainz data for $1 $2"
|
||||
err "Failed to fetch MusicBrainz data for $1 $2 (not retrying anymore...)"
|
||||
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 \
|
||||
@@ -128,6 +180,9 @@ api_discogs_artist() {
|
||||
"https://api.discogs.com/artists/$1"
|
||||
}
|
||||
|
||||
# Retrieve sitelinks from wikidata
|
||||
#
|
||||
# @argument $1: Wikidata ID
|
||||
api_wikidata_sitelinks() {
|
||||
$CURL \
|
||||
--get \
|
||||
@@ -135,6 +190,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 \
|
||||
|
@@ -1,3 +1,6 @@
|
||||
# The code below is used together with `scripts/build.sh`to internalize the awk
|
||||
# scripts. See the awk sources for more information.
|
||||
if [ ! "${AWK_LOADED:-}" ]; then
|
||||
AWK_ARTISTS=$(
|
||||
cat <<'EOF'
|
||||
@@include awk/artists.awk
|
||||
@@ -25,3 +28,6 @@ AWK_RECORDINGS=$(
|
||||
EOF
|
||||
)
|
||||
export AWK_RECORDINGS
|
||||
|
||||
export AWK_LOADED=1
|
||||
fi
|
||||
|
266
src/sh/cache.sh
266
src/sh/cache.sh
@@ -1,31 +1,59 @@
|
||||
# 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"
|
||||
ARTIST_WIKIDATA_FILENAME="wikidata.json"
|
||||
ARTIST_ENWIKIPEDIA_FILENAME="enwikipedia.json"
|
||||
RELEASEGROUP_FILENAME="musicbrainz.json"
|
||||
RELEASEGROUP_RELEASES_FILENAME="releases.json"
|
||||
RELEASE_FILENAME="musicbrainz.json"
|
||||
export CACHEDIR TYPE_ARTIST TYPE_RELEASEGROUP TYPE_RELEASE ARTIST_FILENAME \
|
||||
ARTIST_RELEASEROUPS_FILENAME ARTIST_DISCOGS_FILENAME \
|
||||
ARTIST_WIKIDATA_FILENAME ARTIST_ENWIKIPEDIA_FILENAME \
|
||||
RELEASEGROUP_FILENAME RELEASEGROUP_RELEASES_FILENAME RELEASE_FILENAME
|
||||
|
||||
artist_filename="musicbrainz.json"
|
||||
artist_releasegroups_filename="releasegroups.json"
|
||||
artist_discogs_filename="discogs.json"
|
||||
artist_wikidata_filename="wikidata.json"
|
||||
artist_enwikipedia_filename="enwikipedia.json"
|
||||
releasegroup_filename="musicbrainz.json"
|
||||
releasegroup_releases_filename="releases.json"
|
||||
release_filename="musicbrainz.json"
|
||||
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 }'
|
||||
}
|
||||
|
||||
# Super wrapper
|
||||
# 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 to print json data from cache
|
||||
#
|
||||
# argument $1: type
|
||||
# argument $2: MusicBrainz ID
|
||||
# argument $3: Filename of json file
|
||||
@@ -35,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
|
||||
@@ -48,114 +77,221 @@ __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"
|
||||
__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_releasegroups_filename"
|
||||
__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"
|
||||
__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"
|
||||
__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"
|
||||
__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"
|
||||
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_releasegroups_filename"
|
||||
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"
|
||||
updated=$(mktemp)
|
||||
f="$CACHEDIR/$TYPE_ARTIST/$(__radix "$1")/$artist_releasegroups_filename"
|
||||
$JQ -r --slurpfile n "$tmpf" '."release-groups" += ($n[0]|."release-groups")' "$f" >"$updated" && mv "$updated" "$f"
|
||||
f="$CACHEDIR/$TYPE_ARTIST/$(__radix "$1")/$ARTIST_RELEASEROUPS_FILENAME"
|
||||
$JQ --slurpfile n "$tmpf" '."release-groups" += ($n[0]|."release-groups")' "$f" >"$updated" && mv "$updated" "$f"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
__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"
|
||||
__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"
|
||||
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"
|
||||
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"
|
||||
updated=$(mktemp)
|
||||
f="$CACHEDIR/$TYPE_RELEASEGROUP/$(__radix "$1")/$releasegroup_releases_filename"
|
||||
$JQ -r --slurpfile n "$tmpf" '."releases" += ($n[0]|."releases")' "$f" >"$updated" && mv "$updated" "$f"
|
||||
f="$CACHEDIR/$TYPE_RELEASEGROUP/$(__radix "$1")/$RELEASEGROUP_RELEASES_FILENAME"
|
||||
$JQ --slurpfile n "$tmpf" '."releases" += ($n[0]|."releases")' "$f" >"$updated" && mv "$updated" "$f"
|
||||
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"
|
||||
__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"
|
||||
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() {
|
||||
# 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 paths.
|
||||
cache_get_file_batch() {
|
||||
case "$1" in
|
||||
"$TYPE_ARTIST")
|
||||
fn="$artist_filename"
|
||||
;;
|
||||
"$TYPE_RELEASEGROUP")
|
||||
fn="$releasegroup_filename"
|
||||
;;
|
||||
"$TYPE_RELEASE")
|
||||
fn="$release_filename"
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
"$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
|
||||
cat |
|
||||
__radix_batch |
|
||||
awk -v dir="$CACHEDIR/$1/" -v f="/$fn" '{ print dir $0 f }'
|
||||
}
|
||||
|
||||
# Print MusicBrainz ID associated to the file paths
|
||||
#
|
||||
# This reads from stdin any number of paths (one per line)
|
||||
cache_mbid_from_path_batch() {
|
||||
cat | awk -F "/" '{ print $(NF-1) }'
|
||||
}
|
||||
|
||||
# Remove artist items from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz arist ID
|
||||
#
|
||||
# This function is "safer" than other because it removes data. These safty
|
||||
# checks are paranoid.
|
||||
cache_rm_artist() {
|
||||
[ "$CACHEDIR" ] || return 1
|
||||
[ -d "$CACHEDIR" ] || return 1
|
||||
[ -d "$CACHEDIR/$TYPE_ARTIST" ] || return 1
|
||||
d="$CACHEDIR/$TYPE_ARTIST/$(__radix "$1")/"
|
||||
[ "$d" ] || return 1
|
||||
[ -d "$d" ] || return 1
|
||||
info "removing $d"
|
||||
rm -rf "$d"
|
||||
}
|
||||
|
||||
# Remove release-group items from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
#
|
||||
# This function is "safer" than other because it removes data. These safty
|
||||
# checks are paranoid.
|
||||
cache_rm_releasegroup() {
|
||||
[ "$CACHEDIR" ] || return 1
|
||||
[ -d "$CACHEDIR" ] || return 1
|
||||
[ -d "$CACHEDIR/$TYPE_RELEASEGROUP" ] || return 1
|
||||
d="$CACHEDIR/$TYPE_RELEASEGROUP/$(__radix "$1")/"
|
||||
[ "$d" ] || return 1
|
||||
[ -d "$d" ] || return 1
|
||||
info "removing $d"
|
||||
rm -rf "$d"
|
||||
}
|
||||
|
||||
# Remove release items from cache
|
||||
#
|
||||
# @argument $1: MusicBrainz release ID
|
||||
#
|
||||
# This function is "safer" than other because it removes data. These safty
|
||||
# checks are paranoid.
|
||||
cache_rm_release() {
|
||||
[ "$CACHEDIR" ] || return 1
|
||||
[ -d "$CACHEDIR" ] || return 1
|
||||
[ -d "$CACHEDIR/$TYPE_RELEASE" ] || return 1
|
||||
d="$CACHEDIR/$TYPE_RELEASE/$(__radix "$1")/"
|
||||
[ "$d" ] || return 1
|
||||
[ -d "$d" ] || return 1
|
||||
info "removing $d"
|
||||
rm -rf "$d"
|
||||
}
|
||||
|
@@ -1,3 +1,16 @@
|
||||
# Main application configuration. This application does not require a
|
||||
# configuration file. However, a configuration file may be stored as
|
||||
# `CONFIGFILE_DEFAULT`. If that file exists, it will be sourced. The path to
|
||||
# the file may be overwritten by specifying the environment variable
|
||||
# `CONFIGFILE`. If a configuration file is specified, then it must also exist.
|
||||
# A configuration file comprises the specification of environment variables
|
||||
# that are` allowed to be set.
|
||||
#
|
||||
# Currently, the following files hold variables that are configurable:
|
||||
# - `src/sh/filter.sh`: Configuration of filters that can be triggered with
|
||||
# the respective key bindings.
|
||||
# - `src/sh/keys.sh`: Configuration of key bindings to certain actions
|
||||
# - `src/sh/theme.sh`: Configuration of theme
|
||||
CONFIGFILE_DEFAULT="$HOME/.config/$APP_NAME/config"
|
||||
CONFIGFILE="${CONFIGFILE:-"$CONFIGFILE_DEFAULT"}"
|
||||
[ "$CONFIGFILE" != "$CONFIGFILE_DEFAULT" ] && [ ! -f "$CONFIGFILE" ] && err "The configuration file manually specified with the environment variable CONFIGFILE=($CONFIGFILE) does not exist." && exit 1
|
||||
|
87
src/sh/filter.sh
Normal file
87
src/sh/filter.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
# Preset filters for different views. These filters are associated to key
|
||||
# bindings (see `src/sh/keys.sh`), and are configurable through a configuration
|
||||
# file (see `src/sh/config.sh`).
|
||||
|
||||
# The `QUERY_LOCAL` filter is associated with the keys `KEYS_FILTER_LOCAL`. It
|
||||
# is used to hide all entries that are not available locally (see
|
||||
# `src/sh/query.sh` for details and the relevant methods)
|
||||
QUERY_LOCAL="${QUERY_LOCAL:-"$(printf "'%s'" "$FORMAT_LOCAL" | __clean_filter)"}"
|
||||
|
||||
# The following variables store preset strings derived from the theme (see
|
||||
# `src/sh/theme.sh`), and used in the assignment of the default filters.
|
||||
q_has_seconary="$(printf "$FORMAT_TYPE_HAS_SECONDARY" "" | __clean_filter)"
|
||||
q_album="$(printf "%s" "$FORMAT_TYPE_ALBUM" | __clean_filter)"
|
||||
q_ep=$(printf "%s" "$FORMAT_TYPE_EP" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
q_single=$(printf "%s" "$FORMAT_TYPE_SINGLE" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
if printf "$RV_FORMAT" | grep -q "<<status>>"; then
|
||||
q_official=$(printf "'%s'" "$FORMAT_STATUS_OFFICIAL" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
fi
|
||||
export QUERY_LOCAL
|
||||
|
||||
# Here starts the list of all filters (grouped per view) that are associated to
|
||||
# the keys `KEYS_FILTER_0` - `KEYS_FILTER_9`. The filters in the `F_1_<view>`
|
||||
# variable are automatically applied whenever the given view is entered.
|
||||
F_1_VIEW_ARTIST="${F_1_VIEW_ARTIST:-"!'$q_has_seconary'"}"
|
||||
F_2_VIEW_ARTIST="${F_2_VIEW_ARTIST:-"'$q_album'"}"
|
||||
F_3_VIEW_ARTIST="${F_3_VIEW_ARTIST:-"'$q_ep'"}"
|
||||
F_4_VIEW_ARTIST="${F_4_VIEW_ARTIST:-"'$q_single'"}"
|
||||
F_5_VIEW_ARTIST="${F_5_VIEW_ARTIST:-}"
|
||||
F_6_VIEW_ARTIST="${F_6_VIEW_ARTIST:-}"
|
||||
F_7_VIEW_ARTIST="${F_7_VIEW_ARTIST:-}"
|
||||
F_8_VIEW_ARTIST="${F_8_VIEW_ARTIST:-}"
|
||||
F_9_VIEW_ARTIST="${F_9_VIEW_ARTIST:-}"
|
||||
export F_1_VIEW_ARTIST F_2_VIEW_ARTIST F_3_VIEW_ARTIST F_4_VIEW_ARTIST \
|
||||
F_5_VIEW_ARTIST F_6_VIEW_ARTIST F_7_VIEW_ARTIST F_8_VIEW_ARTIST \
|
||||
F_9_VIEW_ARTIST
|
||||
|
||||
F_1_VIEW_RELEASEGROUP="${F_1_VIEW_RELEASEGROUP:-"${q_official:-}"}"
|
||||
F_2_VIEW_RELEASEGROUP="${F_2_VIEW_RELEASEGROUP:-}"
|
||||
F_3_VIEW_RELEASEGROUP="${F_3_VIEW_RELEASEGROUP:-}"
|
||||
F_4_VIEW_RELEASEGROUP="${F_4_VIEW_RELEASEGROUP:-}"
|
||||
F_5_VIEW_RELEASEGROUP="${F_5_VIEW_RELEASEGROUP:-}"
|
||||
F_6_VIEW_RELEASEGROUP="${F_6_VIEW_RELEASEGROUP:-}"
|
||||
F_7_VIEW_RELEASEGROUP="${F_7_VIEW_RELEASEGROUP:-}"
|
||||
F_8_VIEW_RELEASEGROUP="${F_8_VIEW_RELEASEGROUP:-}"
|
||||
F_9_VIEW_RELEASEGROUP="${F_9_VIEW_RELEASEGROUP:-}"
|
||||
export F_1_VIEW_RELEASEGROUP F_2_VIEW_RELEASEGROUP F_3_VIEW_RELEASEGROUP \
|
||||
F_4_VIEW_RELEASEGROUP F_5_VIEW_RELEASEGROUP F_6_VIEW_RELEASEGROUP \
|
||||
F_7_VIEW_RELEASEGROUP F_8_VIEW_RELEASEGROUP F_9_VIEW_RELEASEGROUP
|
||||
|
||||
F_1_VIEW_RELEASE="${F_1_VIEW_RELEASE:-}"
|
||||
F_2_VIEW_RELEASE="${F_2_VIEW_RELEASE:-}"
|
||||
F_3_VIEW_RELEASE="${F_3_VIEW_RELEASE:-}"
|
||||
F_4_VIEW_RELEASE="${F_4_VIEW_RELEASE:-}"
|
||||
F_5_VIEW_RELEASE="${F_5_VIEW_RELEASE:-}"
|
||||
F_6_VIEW_RELEASE="${F_6_VIEW_RELEASE:-}"
|
||||
F_7_VIEW_RELEASE="${F_7_VIEW_RELEASE:-}"
|
||||
F_8_VIEW_RELEASE="${F_8_VIEW_RELEASE:-}"
|
||||
F_9_VIEW_RELEASE="${F_9_VIEW_RELEASE:-}"
|
||||
export F_1_VIEW_RELEASE F_2_VIEW_RELEASE F_3_VIEW_RELEASE F_4_VIEW_RELEASE \
|
||||
F_5_VIEW_RELEASE F_6_VIEW_RELEASE F_7_VIEW_RELEASE F_8_VIEW_RELEASE \
|
||||
F_9_VIEW_RELEASE
|
||||
|
||||
F_1_LIST_ARTISTS="${F_1_LIST_ARTISTS:-}"
|
||||
F_2_LIST_ARTISTS="${F_2_LIST_ARTISTS:-}"
|
||||
F_3_LIST_ARTISTS="${F_3_LIST_ARTISTS:-}"
|
||||
F_4_LIST_ARTISTS="${F_4_LIST_ARTISTS:-}"
|
||||
F_5_LIST_ARTISTS="${F_5_LIST_ARTISTS:-}"
|
||||
F_6_LIST_ARTISTS="${F_6_LIST_ARTISTS:-}"
|
||||
F_7_LIST_ARTISTS="${F_7_LIST_ARTISTS:-}"
|
||||
F_8_LIST_ARTISTS="${F_8_LIST_ARTISTS:-}"
|
||||
F_9_LIST_ARTISTS="${F_9_LIST_ARTISTS:-}"
|
||||
export F_1_LIST_ARTISTS F_2_LIST_ARTISTS F_3_LIST_ARTISTS F_4_LIST_ARTISTS \
|
||||
F_5_LIST_ARTISTS F_6_LIST_ARTISTS F_7_LIST_ARTISTS F_8_LIST_ARTISTS \
|
||||
F_9_LIST_ARTISTS
|
||||
|
||||
F_1_LIST_ALBUMS="${F_1_LIST_ALBUMS:-}"
|
||||
F_2_LIST_ALBUMS="${F_2_LIST_ALBUMS:-}"
|
||||
F_3_LIST_ALBUMS="${F_3_LIST_ALBUMS:-}"
|
||||
F_4_LIST_ALBUMS="${F_4_LIST_ALBUMS:-}"
|
||||
F_5_LIST_ALBUMS="${F_5_LIST_ALBUMS:-}"
|
||||
F_6_LIST_ALBUMS="${F_6_LIST_ALBUMS:-}"
|
||||
F_7_LIST_ALBUMS="${F_7_LIST_ALBUMS:-}"
|
||||
F_8_LIST_ALBUMS="${F_8_LIST_ALBUMS:-}"
|
||||
F_9_LIST_ALBUMS="${F_9_LIST_ALBUMS:-}"
|
||||
export F_1_LIST_ALBUMS F_2_LIST_ALBUMS F_3_LIST_ALBUMS F_4_LIST_ALBUMS \
|
||||
F_5_LIST_ALBUMS F_6_LIST_ALBUMS F_7_LIST_ALBUMS F_8_LIST_ALBUMS \
|
||||
F_9_LIST_ALBUMS
|
582
src/sh/fzf.sh
582
src/sh/fzf.sh
@@ -1,552 +1,50 @@
|
||||
# Set prompt of input field
|
||||
# Print the fzf instructions that sets the header
|
||||
#
|
||||
# @argument $1: view
|
||||
# @argument $2: mode
|
||||
__set_prompt() {
|
||||
# @argument $2: mbid
|
||||
fzf_command_set_header() {
|
||||
view=$1
|
||||
mode=$2
|
||||
mbid=$2
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST") header="Search artist on MusicBrainz" ;;
|
||||
"$VIEW_SEARCH_ALBUM") header="Search album on MusicBrainz" ;;
|
||||
"$VIEW_LIST_ARTISTS") header="Search locally available artist" ;;
|
||||
"$VIEW_LIST_ALBUMS") header="Search locally available album" ;;
|
||||
"$VIEW_ARTIST")
|
||||
name="$(mb_artist "$args" | $JQ -r '.name')"
|
||||
PROMPT=$(printf "$ARTIST_PROMPT" "$name")
|
||||
name="$(mb_artist "$mbid" | $JQ '.name')"
|
||||
header=$(printf "$HEADER_ARTIST" "$name")
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
title="$(mb_releasegroup "$args" |
|
||||
$JQ -r '.title')"
|
||||
artist="$(mb_releasegroup "$args" |
|
||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
PROMPT=$(printf "$FULL_PROMPT" "$artist" "$title")
|
||||
title="$(mb_releasegroup "$mbid" |
|
||||
$JQ '.title')"
|
||||
artist="$(mb_releasegroup "$mbid" |
|
||||
$JQ '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
header=$(printf "$HEADER_ARTIST_RELEASEGROUP" "$artist" "$title")
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
title="$(mb_release "$args" |
|
||||
$JQ -r '.title')"
|
||||
artist="$(mb_release "$args" |
|
||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
PROMPT=$(printf "$FULL_PROMPT" "$artist" "$title")
|
||||
;;
|
||||
esac
|
||||
[ "$mode" = "$MODE_INSERT" ] && PT="$PROMPT_INSERT" || PT="$PROMPT_NORMAL"
|
||||
printf "+change-prompt(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
|
||||
}
|
||||
|
||||
# Reload data for FZF
|
||||
fzf_handle_reload() {
|
||||
view=$(state_get_view)
|
||||
mode=$(state_get_mode)
|
||||
args=$(state_get_args)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
list_releasegroups "$args"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
list_releases "$args"
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
list_recordings "$args"
|
||||
;;
|
||||
"$VIEW_LIST_ARTISTS")
|
||||
list_local_artists
|
||||
;;
|
||||
"$VIEW_LIST_ALBUMS")
|
||||
list_local_releasegroups
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Handle for after loading data into FZF
|
||||
fzf_handle_load() {
|
||||
view=$(state_get_view)
|
||||
mode=$(state_get_mode)
|
||||
args=$(state_get_args)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
QUERY="!'$QUERY_HAS_SECONDARY' "
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
[ "$QUERY_RV" ] && QUERY="'$QUERY_RV' " || QUERY=""
|
||||
;;
|
||||
"$VIEW_SEARCH_ARTIST")
|
||||
ENABLE_CHANGE=1
|
||||
DISABLE_SEARCH=1
|
||||
SHOW_PREVIEW=1
|
||||
;;
|
||||
"$VIEW_SEARCH_ALBUM")
|
||||
ENABLE_CHANGE=1
|
||||
DISABLE_SEARCH=1
|
||||
;;
|
||||
"$VIEW_LIST_ARTISTS")
|
||||
SHOW_PREVIEW=1
|
||||
;;
|
||||
"$VIEW_LIST_ALBUMS") ;;
|
||||
esac
|
||||
[ "${DISABLE_SEARCH:-}" ] && printf "+disable-search+change-query(%s)" "${QUERY:-"$FZF_QUERY"}" || printf "+enable-search+change-query(%s)" "${QUERY:-}"
|
||||
[ "${SHOW_PREVIEW:-}" ] && printf "+show-preview" || printf "+hide-preview"
|
||||
[ "${ENABLE_CHANGE:-}" ] && printf "+rebind(change)" || printf "+unbind(change)"
|
||||
__set_prompt "$view" "$mode"
|
||||
}
|
||||
|
||||
# Print info string for FZF
|
||||
fzf_info() {
|
||||
view=$(state_get_view)
|
||||
mode=$(state_get_mode)
|
||||
args=$(state_get_args)
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST")
|
||||
echo "Search music artist on MusicBrainz"
|
||||
;;
|
||||
"$VIEW_SEARCH_ALBUM")
|
||||
echo "Search album on MusicBrainz"
|
||||
;;
|
||||
"$VIEW_LIST_ARTISTS")
|
||||
echo "Search artists"
|
||||
;;
|
||||
"$VIEW_LIST_ALBUMS")
|
||||
echo "Search albums"
|
||||
;;
|
||||
"$VIEW_SELECT_ARTIST")
|
||||
debug "Select artist (WE SHOULDNT SEE THIS; THIS IS A BUG!)"
|
||||
;;
|
||||
*)
|
||||
if [ "$FZF_KEY" ]; then
|
||||
printf "[last key: %s] %s/%s" "$FZF_KEY" "$FZF_MATCH_COUNT" "$FZF_TOTAL_COUNT"
|
||||
else
|
||||
printf "%s/%s" "$FZF_MATCH_COUNT" "$FZF_TOTAL_COUNT"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Reload hook that is used after change in query
|
||||
fzf_reload_after_change() {
|
||||
# Wait for async. process to terminate
|
||||
sleep 1
|
||||
while [ -f "$LOCKFILE" ]; do
|
||||
sleep 1
|
||||
done
|
||||
# Show results
|
||||
column -t -s "$(printf '\t')" -E 0 "$RESULTS" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
}
|
||||
|
||||
# Handle change in query
|
||||
fzf_handle_change() {
|
||||
# Kill any running search
|
||||
if [ -f "$PIDFILE" ]; then
|
||||
pid=$(cat "$PIDFILE")
|
||||
rm -f "$PIDFILE"
|
||||
kill -9 "$pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
# Stop, if no search string is given
|
||||
[ "$FZF_QUERY" ] || exit 0
|
||||
# Store PID of current process
|
||||
echo "$$" >"$PIDFILE"
|
||||
touch "$LOCKFILE"
|
||||
sleep 1
|
||||
view=$(state_get_view)
|
||||
if [ "$view" = "$VIEW_SEARCH_ARTIST" ]; then
|
||||
api_mb_search_artist "$FZF_QUERY" |
|
||||
$JQ -r '.artists[] | [
|
||||
.id,
|
||||
.type,
|
||||
.name,
|
||||
.disambiguation,
|
||||
.["life-span"].begin,
|
||||
.["life-span"].end
|
||||
title="$(mb_release "$mbid" |
|
||||
$JQ '.title')"
|
||||
artist="$(mb_release "$mbid" |
|
||||
$JQ '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
releaseinfo="$(mb_release "$mbid" |
|
||||
$JQ '[
|
||||
.date[:4],
|
||||
(."label-info" | map(.label.name) | unique | join(", ")),
|
||||
(.media | map(."track-count") | add),
|
||||
(.media | map(.format) | unique | join(", ")),
|
||||
.country
|
||||
] | join("\t")' |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_artists="${LOCALDATA_ARTISTS:-}" \
|
||||
-v format_person="$AV_PERSON" \
|
||||
-v format_group="$AV_GROUP" \
|
||||
-v format_disambiguation="$AV_DISAMBIGUATION" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_ARTISTS" >"$RESULTS" ||
|
||||
true
|
||||
else
|
||||
api_mb_search_releasegroup "$FZF_QUERY" |
|
||||
$JQ -r '."release-groups"[] | [
|
||||
.id,
|
||||
."primary-type",
|
||||
(."secondary-types" // []|join(";")),
|
||||
."first-release-date",
|
||||
.title,
|
||||
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
|
||||
] | join("\t")' |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_releasegroups="${LOCALDATA_RELEASEGROUPS:-}" \
|
||||
-v format_release="$RGV_RELEASE" \
|
||||
-v format_release_w_artist="$RGV_RELEASE_W_ARTIST" \
|
||||
-v format_year="$RGV_YEAR" \
|
||||
-v format_album="$FORMAT_TYPE_ALBUM" \
|
||||
-v format_single="$FORMAT_TYPE_SINGLE" \
|
||||
-v format_ep="$FORMAT_TYPE_EP" \
|
||||
-v format_broadcast="$FORMAT_TYPE_BROADCAST" \
|
||||
-v format_other="$FORMAT_TYPE_OTHER" \
|
||||
-v format_has_secondary="$FORMAT_TYPE_HAS_SECONDARY" \
|
||||
-v format_secondary="$FORMAT_TYPE_SECONDARY" \
|
||||
-v format_compilation="$FORMAT_TYPE_SECONDARY_COMPILATION" \
|
||||
-v format_soundtrack="$FORMAT_TYPE_SECONDARY_SOUNDTRACK" \
|
||||
-v format_spokenword="$FORMAT_TYPE_SECONDARY_SPOKENWORD" \
|
||||
-v format_interview="$FORMAT_TYPE_SECONDARY_INTERVIEW" \
|
||||
-v format_audiobook="$FORMAT_TYPE_SECONDARY_AUDIOBOOK" \
|
||||
-v format_audiodrama="$FORMAT_TYPE_SECONDARY_AUDIODRAMA" \
|
||||
-v format_live="$FORMAT_TYPE_SECONDARY_LIVE" \
|
||||
-v format_remix="$FORMAT_TYPE_SECONDARY_REMIX" \
|
||||
-v format_djmix="$FORMAT_TYPE_SECONDARY_DJMIX" \
|
||||
-v format_mixtape="$FORMAT_TYPE_SECONDARY_MIXTAPE" \
|
||||
-v format_demo="$FORMAT_TYPE_SECONDARY_DEMO" \
|
||||
-v format_fieldrec="$FORMAT_TYPE_SECONDARY_FIELDREC" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_RELEASEGROUPS" |
|
||||
cut -d "$(printf '\t')" -f 2- >"$RESULTS" ||
|
||||
true
|
||||
fi
|
||||
# Process ends now: Display and quit
|
||||
rm -f "$LOCKFILE" "$PIDFILE"
|
||||
}
|
||||
|
||||
# Handle FZF keypress
|
||||
# @argument $1: MusicBrainz ID of parent object
|
||||
# @argument $2: MusicBrainz ID of selected object
|
||||
# @argument $3: Path to decoration file (optional)
|
||||
fzf_handle_key() {
|
||||
parentmbid="${1:-}"
|
||||
mbid="${2:-}"
|
||||
path="${3:-}"
|
||||
view=$(state_get_view)
|
||||
mode=$(state_get_mode)
|
||||
args=$(state_get_args)
|
||||
|
||||
# If we are in the insert mode, and the key pressed is an "input" key, then
|
||||
# put it and quit.
|
||||
if [ "$mode" = "$MODE_INSERT" ]; then
|
||||
case ",$KEYS_INPUT_SINGLE," in
|
||||
*",$FZF_KEY,"*)
|
||||
printf "put(%s)" "$FZF_KEY"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_INPUT_SPECIAL," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$FZF_KEY" in
|
||||
"space") printf "put( )" ;;
|
||||
"backspace") printf "backward-delete-char" ;;
|
||||
"delete") printf "delete-char" ;;
|
||||
"left") printf "backward-char" ;;
|
||||
"right") printf "forward-char" ;;
|
||||
esac
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Keys in insert mode only
|
||||
case ",$KEYS_I_NORMAL," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_PLAYLIST") ;;
|
||||
*)
|
||||
state_update_keep_args "$view" "$MODE_NORMAL"
|
||||
__set_prompt "$view" "$MODE_NORMAL"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Keys exclusive to playlist view
|
||||
if [ "$view" = "$VIEW_PLAYLIST" ]; then
|
||||
case ",$KEYS_PLAYLIST_RELOAD," in
|
||||
*",$FZF_KEY,"*)
|
||||
debug "hit playlist reload key"
|
||||
debug "going to call $(printf "reload:%s" "$0 --fzf-reload")"
|
||||
printf "reload:%s" "$0 --fzf-reload"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Handle key press
|
||||
case ",$KEYS_HALFPAGE_DOWN," in
|
||||
*",$FZF_KEY,"*) printf "half-page-down" ;;
|
||||
esac
|
||||
case ",$KEYS_HALFPAGE_UP," in
|
||||
*",$FZF_KEY,"*) printf "half-page-up" ;;
|
||||
esac
|
||||
case ",$KEYS_OPEN," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$path" ] || return 0
|
||||
open "$(dirname "$path")"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_BROWSE," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$mbid" ] || return 0
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS" | "$VIEW_SELECT_ARTIST") urltype="artist" ;;
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") urltype="release-group" ;;
|
||||
"$VIEW_RELEASEGROUP") urltype="release" ;;
|
||||
"$VIEW_RELEASE" | "$VIEW_PLAYLIST") urltype="track" ;;
|
||||
esac
|
||||
[ "${urltype:-}" ] && printf "execute-silent(xdg-open \"https://musicbrainz.org/%s/%s\" &)" "$urltype" "$mbid"
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_OUT," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
VIEW_NEXT="$VIEW_LIST_ARTISTS"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
VIEW_NEXT="$VIEW_SELECT_ARTIST"
|
||||
VIEW_NEXT_ARGS="$(mb_releasegroup "$args" | $JQ -r --compact-output '."artist-credit"')"
|
||||
ACCEPT=1
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
VIEW_NEXT="$VIEW_RELEASEGROUP"
|
||||
VIEW_NEXT_ARGS="$(mb_release "$args" | $JQ -r --compact-output '."release-group".id')"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
VIEW_NEXT="$VIEW_RELEASE"
|
||||
VIEW_NEXT_ARGS="$parentmbid"
|
||||
ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_IN," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$mbid" ] || return 0
|
||||
VIEW_NEXT_ARGS="$mbid"
|
||||
case "$view" in
|
||||
"$VIEW_LIST_ARTISTS" | "$VIEW_SEARCH_ARTIST")
|
||||
VIEW_NEXT="$VIEW_ARTIST"
|
||||
;;
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS")
|
||||
VIEW_NEXT="$VIEW_RELEASEGROUP"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
VIEW_NEXT="$VIEW_RELEASE"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_SELECT_ARTIST," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$mbid" ] || return 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS")
|
||||
VIEW_NEXT_ARGS="$(mb_releasegroup "$mbid" | $JQ -r --compact-output '."artist-credit"')"
|
||||
ACCEPT=1
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS")
|
||||
VIEW_NEXT_ARGS="$(mb_release "$mbid" | $JQ -r --compact-output '."artist-credit"')"
|
||||
ACCEPT=1
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
VIEW_NEXT_ARGS="$(mb_release "$args" | $JQ -r --compact-output '."artist-credit"')"
|
||||
ACCEPT=1
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
debug "NOT IMPLEMENTED"
|
||||
;;
|
||||
esac
|
||||
[ "$VIEW_NEXT_ARGS" ] && VIEW_NEXT="$VIEW_SELECT_ARTIST"
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_LOCAL," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_PLAYLIST") ;;
|
||||
*) QUERY="'$QUERY_LOCAL' " ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
# VIEW_RELEASEGROUP="rg"
|
||||
# VIEW_RELEASE="release"
|
||||
# VIEW_LIST_ARTISTS="list-artists"
|
||||
# VIEW_SELECT_ARTIST="select-artist"
|
||||
# VIEW_PLAYLIST="playlist"
|
||||
case ",$KEYS_FILTER_1," in *",$FZF_KEY,"*) case "$view" in "$VIEW_ARTIST" | "$VIEW_LIST_ALBUMS") QUERY="!'$QUERY_HAS_SECONDARY' " ;; esac ;; esac
|
||||
case ",$KEYS_FILTER_2," in *",$FZF_KEY,"*) case "$view" in "$VIEW_ARTIST" | "$VIEW_LIST_ALBUMS") QUERY="!'$QUERY_HAS_SECONDARY' '$QUERY_ALBUM' " ;; esac ;; esac
|
||||
case ",$KEYS_FILTER_3," in *",$FZF_KEY,"*) case "$view" in "$VIEW_ARTIST" | "$VIEW_LIST_ALBUMS") QUERY="!'$QUERY_HAS_SECONDARY' '$QUERY_EP' " ;; esac ;; esac
|
||||
case ",$KEYS_FILTER_4," in *",$FZF_KEY,"*) case "$view" in "$VIEW_ARTIST" | "$VIEW_LIST_ALBUMS") QUERY="!'$QUERY_HAS_SECONDARY' '$QUERY_SINGLE' " ;; esac ;; esac
|
||||
case ",$KEYS_SWITCH_ARTIST_ALBUM," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST") VIEW_NEXT="$VIEW_SEARCH_ALBUM" ;;
|
||||
"$VIEW_SEARCH_ALBUM") VIEW_NEXT="$VIEW_SEARCH_ARTIST" ;;
|
||||
"$VIEW_LIST_ARTISTS") VIEW_NEXT="$VIEW_LIST_ALBUMS" ;;
|
||||
"$VIEW_LIST_ALBUMS") VIEW_NEXT="$VIEW_LIST_ARTISTS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_SWITCH_LOCAL_REMOTE," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_SEARCH_ARTIST") VIEW_NEXT="$VIEW_LIST_ARTISTS" ;;
|
||||
"$VIEW_SEARCH_ALBUM") VIEW_NEXT="$VIEW_LIST_ALBUMS" ;;
|
||||
"$VIEW_LIST_ARTISTS")
|
||||
VIEW_NEXT="$VIEW_SEARCH_ARTIST"
|
||||
MODE_NEXT="$MODE_INSERT"
|
||||
;;
|
||||
"$VIEW_LIST_ALBUMS")
|
||||
VIEW_NEXT="$VIEW_SEARCH_ALBUM"
|
||||
MODE_NEXT="$MODE_INSERT"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_SHOW_PLAYLIST," in
|
||||
*",$FZF_KEY,"*)
|
||||
VIEW_NEXT="$VIEW_PLAYLIST"
|
||||
ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_PLAY," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$path" ] || return 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS")
|
||||
debug "not implemented"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
generate_playlist "$mbid" "$path" | mpv_play_list >/dev/null
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
generate_playlist "$parentmbid" "$path" "$mbid" | mpv_play_list >/dev/null
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
generate_playlist "$parentmbid" "$path" "$mbid" | mpv_play_list >/dev/null
|
||||
VIEW_NEXT="$VIEW_PLAYLIST"
|
||||
ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_QUEUE," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$path" ] || return 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS")
|
||||
debug "not implemented"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
generate_playlist "$mbid" "$path" | mpv_queue_list >/dev/null
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
generate_playlist "$parentmbid" "$path" "$mbid" | mpv_queue_list >/dev/null
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
generate_playlist "$parentmbid" "$path" "$mbid" | mpv_queue_list >/dev/null
|
||||
VIEW_NEXT="$VIEW_PLAYLIST"
|
||||
ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
# Keys in normal mode only
|
||||
if [ "$mode" = "$MODE_NORMAL" ]; then
|
||||
case ",$KEYS_N_DOWN," in
|
||||
*",$FZF_KEY,"*) printf "down" ;;
|
||||
esac
|
||||
case ",$KEYS_N_UP," in
|
||||
*",$FZF_KEY,"*) printf "up" ;;
|
||||
esac
|
||||
case ",$KEYS_N_OUT," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST")
|
||||
VIEW_NEXT="$VIEW_LIST_ARTISTS"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
VIEW_NEXT="$VIEW_SELECT_ARTIST"
|
||||
VIEW_NEXT_ARGS="$(mb_releasegroup "$args" | $JQ -r --compact-output '."artist-credit"')"
|
||||
ACCEPT=1
|
||||
;;
|
||||
"$VIEW_RELEASE")
|
||||
VIEW_NEXT="$VIEW_RELEASEGROUP"
|
||||
VIEW_NEXT_ARGS="$(mb_release "$args" | $JQ -r --compact-output '."release-group".id')"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
VIEW_NEXT="$VIEW_RELEASE"
|
||||
VIEW_NEXT_ARGS="$parentmbid"
|
||||
ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_IN," in
|
||||
*",$FZF_KEY,"*)
|
||||
[ "$mbid" ] || return 0
|
||||
VIEW_NEXT_ARGS="$mbid"
|
||||
case "$view" in
|
||||
"$VIEW_LIST_ARTISTS" | "$VIEW_SEARCH_ARTIST")
|
||||
VIEW_NEXT="$VIEW_ARTIST"
|
||||
;;
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS")
|
||||
VIEW_NEXT="$VIEW_RELEASEGROUP"
|
||||
;;
|
||||
"$VIEW_RELEASEGROUP")
|
||||
VIEW_NEXT="$VIEW_RELEASE"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_TOP," in
|
||||
*",$FZF_KEY,"*) printf "first" ;;
|
||||
esac
|
||||
case ",$KEYS_N_BOT," in
|
||||
*",$FZF_KEY,"*) printf "last" ;;
|
||||
esac
|
||||
case ",$KEYS_N_QUIT," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_SELECT_ARTIST" | "$VIEW_PLAYLIST") printf "accept" ;;
|
||||
*) printf "print(Q)+abort" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_INSERT," in
|
||||
*",$FZF_KEY,"*)
|
||||
case "$view" in
|
||||
"$VIEW_PLAYLIST") ;;
|
||||
*)
|
||||
state_update_keep_args "$view" "$MODE_INSERT"
|
||||
__set_prompt "$view" "$MODE_INSERT"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_TOGGLE_PLAY_PAUSE," in
|
||||
*",$FZF_KEY,"*) mpv_toggle_pause >/dev/null ;;
|
||||
esac
|
||||
|
||||
case ",$KEYS_N_PLAY_NEXT," in
|
||||
*",$FZF_KEY,"*)
|
||||
mpv_next >/dev/null
|
||||
[ "$view" = "$VIEW_PLAYLIST" ] && VIEW_NEXT="$VIEW_PLAYLIST" && ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_PLAY_PREV," in
|
||||
*",$FZF_KEY,"*)
|
||||
mpv_prev >/dev/null
|
||||
[ "$view" = "$VIEW_PLAYLIST" ] && VIEW_NEXT="$VIEW_PLAYLIST" && ACCEPT=1
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_N_SEEK_FORWARD," in
|
||||
*",$FZF_KEY,"*) mpv_seek_forward >/dev/null ;;
|
||||
esac
|
||||
case ",$KEYS_N_SEEK_BACKWARD," in
|
||||
*",$FZF_KEY,"*) mpv_seek_backward >/dev/null ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Post processing
|
||||
[ "${QUERY:-}" ] && printf "+change-query(%s)" "$QUERY"
|
||||
if [ "${VIEW_NEXT:-}" ]; then
|
||||
[ "$VIEW_NEXT" = "$VIEW_PLAYLIST" ] && MODE_NEXT="$MODE_NORMAL"
|
||||
state_update "$VIEW_NEXT" "${MODE_NEXT:-"$mode"}" "${VIEW_NEXT_ARGS:-}"
|
||||
[ "${ACCEPT:-}" ] && printf "+accept" || printf "+reload:%s" "$0 --fzf-reload"
|
||||
fi
|
||||
awk -F "\t" -v format="$HEADER_RELEASE_FORMAT" '{
|
||||
gsub("&", "\\\\&")
|
||||
sub("<<year>>", $1, format)
|
||||
sub("<<label>>", $2, format)
|
||||
sub("<<tracks>>", $3, format)
|
||||
sub("<<media>>", $4, format)
|
||||
sub("<<country>>", $5, format)
|
||||
print format
|
||||
}')"
|
||||
header=$(printf "$HEADER_RELEASE" "$artist" "$title" "$releaseinfo")
|
||||
;;
|
||||
esac
|
||||
printf "+change-header(%s)" "${header:-"???"}"
|
||||
}
|
||||
|
@@ -1,19 +0,0 @@
|
||||
ERR="\033[38;5;196m"
|
||||
INFO="\033[38;5;75m"
|
||||
DBG=$ERR
|
||||
OFF="\033[m"
|
||||
LOGDIR="$HOME/.local/state/$APP_NAME"
|
||||
[ -d "$LOGDIR" ] || mkdir -p "$LOGDIR"
|
||||
LOGFILE="$LOGDIR/log"
|
||||
|
||||
err() {
|
||||
echo "${ERR}ERROR:${OFF} ${1:-}" >/dev/stderr
|
||||
}
|
||||
|
||||
info() {
|
||||
echo "${INFO}Info:${OFF} ${1:-}" >/dev/stderr
|
||||
}
|
||||
|
||||
debug() {
|
||||
echo "${DBG}DEBUG${OFF} ${INFO} [$$] $(date)${OFF}: $*" >>"$LOGFILE"
|
||||
}
|
@@ -1,5 +1,10 @@
|
||||
APP_NAME="muf"
|
||||
APP_VERSION="zero.zero"
|
||||
APP_WEBSITE="https://git.indyfac.ch/amin/muf"
|
||||
# Application information
|
||||
if [ ! "${INFO_LOADED:-}" ]; then
|
||||
APP_NAME="fuzic"
|
||||
APP_VERSION="0.1"
|
||||
APP_WEBSITE="https://git.indyfac.ch/amin/fuzic"
|
||||
WINDOW_TITLE="🔎🎶 $APP_NAME | a simple music finder and player"
|
||||
export APP_NAME APP_VERSION APP_WEBSITE WINDOW_TITLE
|
||||
|
||||
export INFO_LOADED=1
|
||||
fi
|
||||
|
410
src/sh/keys.sh
410
src/sh/keys.sh
@@ -1,64 +1,380 @@
|
||||
KEYS_INPUT_SINGLE='0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,!,",#,$,%,&,\,(,),*,+,,,-,.,/,:,;,<,=,>,?,@,[,\,\,],^,_,`,{,|,},~'
|
||||
KEYS_INPUT_SINGLE="$KEYS_INPUT_SINGLE,'"
|
||||
KEYS_INPUT_SPECIAL="space,backspace,delete,left,right"
|
||||
export KEYS_INPUT_SINGLE KEYS_INPUT_SPECIAL
|
||||
# List of keys, organized in groups
|
||||
#
|
||||
# Mode selection:
|
||||
# - KEYS_I_NORMAL: Switch to normal mode (insert mode)
|
||||
# - KEYS_N_INSERT: Switch to insert mode (normal mode)
|
||||
#
|
||||
# Vertical navigation:
|
||||
# - KEYS_DOWN: Move cursor to the next line
|
||||
# - KEYS_UP: Move cursor to the previous line
|
||||
# - KEYS_HALFPAGE_UP: Move cursor half a page up
|
||||
# - KEYS_HALFPAGE_DOWN: Move cursor half a page up
|
||||
# - KEYS_N_DOWN: Move cursor to the next line (normal mode)
|
||||
# - KEYS_N_UP: Move cursor to the previous line (normal mode)
|
||||
# - KEYS_N_BOT: Move cursor to the last line (normal mode)
|
||||
# - KEYS_N_TOP: Move cursor to the first line (normal mode)
|
||||
#
|
||||
# Horizontal navigation:
|
||||
# - KEYS_IN: Enter into selected item, down the hierarchy
|
||||
# - KEYS_OUT: Leave current item, up the hierarchy
|
||||
# - KEYS_N_IN: Enter into selected item, down the hierarchy (normal mode)
|
||||
# - KEYS_N_OUT: Leave current item, up the hierarchy (normal mode)
|
||||
# - KEYS_SELECT_ARTIST: Go to artist of selected entry (in case of multiple
|
||||
# artists, provide a choice)
|
||||
# - KEYS_LIST_ARTISTS: Go to VIEW_LIST_ARTISTS
|
||||
# - KEYS_LIST_ALBUMS: Go to VIEW_LIST_ALBUMS
|
||||
# - KEYS_SEARCH_ARTIST: Go to VIEW_SEARCH_ARTIST
|
||||
# - KEYS_SEARCH_ALBUM: Go to VIEW_SEARCH_ALBUM
|
||||
# - KEYS_SWITCH_ARTIST_ALBUM: Switch artist and album views, i.e.,
|
||||
# VIEW_LIST_ARTISTS <-> VIEW_LIST_ALBUMS, and VIEW_SEARCH_ARTIST <->
|
||||
# VIEW_SEARCH_ALBUM.
|
||||
# - KEYS_SWITCH_LOCAL_REMOTE: Switch between locally available music and remote
|
||||
# search views, i.e., VIEW_LIST_ARTISTS <-> VIEW_SEARCH_ARTIST, and
|
||||
# VIEW_LIST_ALBUMS <-> VIEW_SEARCH_ALBUM.
|
||||
#
|
||||
# Filtering:
|
||||
# - KEYS_FILTER_LOCAL: List only locally available entries
|
||||
# - KEYS_FILTER_0: Clear query
|
||||
# - KEYS_FILTER_1: Reset query to the default one for the current view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_2: Preset query `2` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_3: Preset query `3` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_4: Preset query `4` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_5: Preset query `5` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_6: Preset query `6` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_7: Preset query `7` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_8: Preset query `8` depending on the view (see `src/sh/filter.sh`)
|
||||
# - KEYS_FILTER_9: Preset query `9` depending on the view (see `src/sh/filter.sh`)
|
||||
#
|
||||
# Specials:
|
||||
# - KEYS_BROWSE: Open MusicBrainz webpage of the selected item
|
||||
# - KEYS_OPEN: Open file manager in the directory of the selected item
|
||||
# - KEYS_N_YANK: Copy MusicBrainz ID of selected item to clipboard
|
||||
# - KEYS_YANK_CURRENT: Copy MusicBrainz ID of current item to clipboard
|
||||
# - KEYS_SHOW_PLAYLIST: Switch to playlist view
|
||||
# - KEYS_KEYBINDINGS: Show keybindings
|
||||
# - KEYS_QUIT: Quit application
|
||||
# - KEYS_N_QUIT: Quit application if we are in VIEW_LIST_ARTISTS, else go to
|
||||
# view VIEW_LIST_ARTISTS (normal mode)
|
||||
# - KEYS_SCROLL_PREVIEW_DOWN: Scroll preview down
|
||||
# - KEYS_SCROLL_PREVIEW_UP: Scroll preview up
|
||||
# - KEYS_PREVIEW_OPEN: Open preview window
|
||||
# - KEYS_PREVIEW_CLOSE: Close preview window
|
||||
# - KEYS_REFRESH: Refresh current entry
|
||||
#
|
||||
# Playback:
|
||||
# - KEYS_PLAY: Play selected release or selected track
|
||||
# - KEYS_QUEUE: Queue selected release or selected track
|
||||
# - KEYS_QUEUE_NEXT: Queue selected release or selected track as next entry in
|
||||
# the playlist
|
||||
# - KEYS_N_TOGGLE_PLAYBACK: Play-pause toggle
|
||||
# - KEYS_N_PLAY_NEXT: Play next track
|
||||
# - KEYS_N_PLAY_PREV: Play previous track
|
||||
# - KEYS_N_SEEK_FORWARD: Seek forward
|
||||
# - KEYS_N_SEEK_BACKWARD: Seek backward
|
||||
#
|
||||
# Playlist (in the playlist, there is no `insert` mode):
|
||||
# - KEYS_PLAYLIST_RELOAD: Manually reload playlist
|
||||
# - KEYS_PLAYLIST_REMOVE: Remove item from playlist
|
||||
# - KEYS_PLAYLIST_UP: Move item one position up
|
||||
# - KEYS_PLAYLIST_DOWN: Move item one position down
|
||||
# - KEYS_PLAYLIST_CLEAR: Clear playlist
|
||||
# - KEYS_PLAYLIST_CLEAR_ABOVE: Remove all items above incl. the selected one
|
||||
# - KEYS_PLAYLIST_CLEAR_BELOW: Remove all items below incl. the selected one
|
||||
# - KEYS_PLAYLIST_SHUFFLE: Shuffle playlist
|
||||
# - KEYS_PLAYLIST_UNSHUFFLE: Unshuffle previously shuffled playlist
|
||||
# - KEYS_PLAYLIST_GOTO_RELEASE: Jump to release or selected entry
|
||||
# - KEYS_PLAYLIST_STORE: Store current playlist as file
|
||||
# - KEYS_PLAYLIST_LOAD: Load playlist from file
|
||||
# - KEYS_PLAYLIST_QUIT: Quit playlist view
|
||||
|
||||
# Normal and insert mode
|
||||
if [ ! "${KEYS_LOADED:-}" ]; then
|
||||
# Mode selection:
|
||||
KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}"
|
||||
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/,?"}"
|
||||
export KEYS_I_NORMAL KEYS_N_INSERT
|
||||
|
||||
# Vertical navigation:
|
||||
KEYS_DOWN="${KEYS_DOWN:-"ctrl-j,down"}"
|
||||
KEYS_UP="${KEYS_UP:-"ctrl-k,up"}"
|
||||
KEYS_HALFPAGE_DOWN="${KEYS_HALFPAGE_DOWN:-"ctrl-d"}"
|
||||
KEYS_HALFPAGE_UP="${KEYS_HALFPAGE_UP:-"ctrl-u"}"
|
||||
KEYS_BROWSE="${KEYS_BROWSE:-"alt-b"}"
|
||||
KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
|
||||
KEYS_OUT="${KEYS_OUT:-"ctrl-h"}"
|
||||
KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}"
|
||||
KEYS_N_UP="${KEYS_N_UP:-"k"}"
|
||||
KEYS_N_BOT="${KEYS_N_BOT:-"G"}"
|
||||
KEYS_N_TOP="${KEYS_N_TOP:-"1"}"
|
||||
export KEYS_DOWN KEYS_UP KEYS_HALFPAGE_DOWN KEYS_HALFPAGE_UP KEYS_N_DOWN \
|
||||
KEYS_N_UP KEYS_N_BOT KEYS_N_TOP
|
||||
|
||||
# Horizontal navigation:
|
||||
KEYS_IN="${KEYS_IN:-"ctrl-l"}"
|
||||
KEYS_OUT="${KEYS_OUT:-"ctrl-h"}"
|
||||
KEYS_N_IN="${KEYS_N_IN:-"l"}"
|
||||
KEYS_N_OUT="${KEYS_N_OUT:-"h"}"
|
||||
KEYS_SELECT_ARTIST="${KEYS_SELECT_ARTIST:-"ctrl-a"}"
|
||||
KEYS_LIST_ARTISTS="${KEYS_LIST_ARTISTS:-"alt-a"}"
|
||||
KEYS_LIST_ALBUMS="${KEYS_LIST_ALBUMS:-"alt-s"}"
|
||||
KEYS_SEARCH_ARTIST="${KEYS_SEARCH_ARTIST:-"alt-z"}"
|
||||
KEYS_SEARCH_ALBUM="${KEYS_SEARCH_ALBUM:-"alt-x"}"
|
||||
KEYS_SWITCH_ARTIST_ALBUM="${KEYS_SWITCH_ARTIST_ALBUM:-"tab"}"
|
||||
KEYS_SWITCH_LOCAL_REMOTE="${KEYS_SWITCH_LOCAL_REMOTE:-"ctrl-/"}"
|
||||
export KEYS_IN KEYS_OUT KEYS_N_IN KEYS_N_OUT KEYS_SELECT_ARTIST \
|
||||
KEYS_LIST_ARTISTS KEYS_LIST_ALBUMS KEYS_SEARCH_ARTIST KEYS_SEARCH_ALBUM \
|
||||
KEYS_SWITCH_ARTIST_ALBUM KEYS_SWITCH_LOCAL_REMOTE
|
||||
|
||||
# Filtering:
|
||||
KEYS_FILTER_LOCAL="${KEYS_FILTER_LOCAL:-"alt-l"}"
|
||||
KEYS_FILTER_1="${KEYS_FILTER_1:-"alt-1"}"
|
||||
KEYS_FILTER_2="${KEYS_FILTER_2:-"alt-2"}"
|
||||
KEYS_FILTER_3="${KEYS_FILTER_3:-"alt-3"}"
|
||||
KEYS_FILTER_4="${KEYS_FILTER_4:-"alt-4"}"
|
||||
KEYS_SWITCH_ARTIST_ALBUM="${KEYS_SWITCH_ARTIST_ALBUM:-"tab"}"
|
||||
KEYS_SWITCH_LOCAL_REMOTE="${KEYS_SWITCH_LOCAL_REMOTE:-"ctrl-/"}"
|
||||
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
|
||||
KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}"
|
||||
KEYS_FILTER_5="${KEYS_FILTER_5:-"alt-5"}"
|
||||
KEYS_FILTER_6="${KEYS_FILTER_6:-"alt-6"}"
|
||||
KEYS_FILTER_7="${KEYS_FILTER_7:-"alt-7"}"
|
||||
KEYS_FILTER_8="${KEYS_FILTER_8:-"alt-8"}"
|
||||
KEYS_FILTER_9="${KEYS_FILTER_9:-"alt-9"}"
|
||||
KEYS_FILTER_0="${KEYS_FILTER_0:-"alt-0"}"
|
||||
KEYS_FILTER="$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_FILTER_5,$KEYS_FILTER_6,$KEYS_FILTER_7,$KEYS_FILTER_8,$KEYS_FILTER_9,$KEYS_FILTER_0"
|
||||
export KEYS_FILTER_LOCAL KEYS_FILTER_1 KEYS_FILTER_2 KEYS_FILTER_3 \
|
||||
KEYS_FILTER_4 KEYS_FILTER_5 KEYS_FILTER_6 KEYS_FILTER_7 KEYS_FILTER_8 \
|
||||
KEYS_FILTER_9 KEYS_FILTER_0 KEYS_FILTER
|
||||
|
||||
# Specials:
|
||||
KEYS_BROWSE="${KEYS_BROWSE:-"alt-b"}"
|
||||
KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
|
||||
KEYS_N_YANK="${KEYS_N_YANK:-"y"}"
|
||||
KEYS_YANK_CURRENT="${KEYS_YANK_CURRENT:-"ctrl-y"}"
|
||||
KEYS_SHOW_PLAYLIST="${KEYS_SHOW_PLAYLIST:-"ctrl-p"}"
|
||||
|
||||
# Keys in normal mode only
|
||||
KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}"
|
||||
KEYS_N_UP="${KEYS_N_UP:-"k"}"
|
||||
KEYS_N_OUT="${KEYS_N_OUT:-"h"}"
|
||||
KEYS_N_IN="${KEYS_N_IN:-"l"}"
|
||||
KEYS_N_TOP="${KEYS_N_TOP:-"1"}"
|
||||
KEYS_N_BOT="${KEYS_N_BOT:-"G"}"
|
||||
KEYS_KEYBINDINGS="${KEYS_KEYBINDINGS:-"alt-?"}"
|
||||
KEYS_QUIT="${KEYS_QUIT:-"ctrl-c"}"
|
||||
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
|
||||
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/"}"
|
||||
KEYS_N_TOGGLE_PLAY_PAUSE="${KEYS_N_TOGGLE_PLAY_PAUSE:-"space"}"
|
||||
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right"}"
|
||||
KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left"}"
|
||||
KEYS_N_SEEK_FORWARD="${KEYS_N_SEEK_FORWARD:-"shift-right"}"
|
||||
KEYS_N_SEEK_BACKWARD="${KEYS_N_SEEK_BACKWARD:-"shift-left"}"
|
||||
KEYS_SCROLL_PREVIEW_DOWN="${KEYS_SCROLL_PREVIEW_DOWN:-"page-down"}"
|
||||
KEYS_SCROLL_PREVIEW_UP="${KEYS_SCROLL_PREVIEW_UP:-"page-up"}"
|
||||
KEYS_PREVIEW_OPEN="${KEYS_PREVIEW_OPEN:-"alt-up"}"
|
||||
KEYS_PREVIEW_CLOSE="${KEYS_PREVIEW_CLOSE:-"alt-down"}"
|
||||
KEYS_REFRESH="${KEYS_REFRESH:-"ctrl-r"}"
|
||||
export KEYS_BROWSE KEYS_OPEN KEYS_N_YANK KEYS_YANK_CURRENT KEYS_SHOW_PLAYLIST \
|
||||
KEYS_KEYBINDINGS KEYS_QUIT KEYS_N_QUIT KEYS_SCROLL_PREVIEW_DOWN \
|
||||
KEYS_SCROLL_PREVIEW_UP KEYS_PREVIEW_CLOSE KEYS_PREVIEW_OPEN KEYS_REFRESH
|
||||
|
||||
# Special playlist keys
|
||||
KEYS_PLAYLIST_RELOAD="${KEYS_PLAYLIST_RELOAD:-"r"}"
|
||||
# Playback:
|
||||
KEYS_PLAY="${KEYS_PLAY:-"enter"}"
|
||||
KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}" # That's actually alt-enter
|
||||
KEYS_QUEUE_NEXT="${KEYS_QUEUE_NEXT:-"ctrl-alt-n"}"
|
||||
KEYS_TOGGLE_PLAYBACK="${KEYS_TOGGLE_PLAYBACK:-"ctrl-space"}"
|
||||
KEYS_PLAY_NEXT="${KEYS_PLAY_NEXT:-"alt-n"}"
|
||||
KEYS_PLAY_PREV="${KEYS_PLAY_PREV:-"alt-p"}"
|
||||
KEYS_SEEK_FORWARD="${KEYS_SEEK_FORWARD:-"alt-N"}"
|
||||
KEYS_SEEK_BACKWARD="${KEYS_SEEK_BACKWARD:-"alt-P"}"
|
||||
KEYS_PLAYBACK="$KEYS_PLAY,$KEYS_QUEUE,$KEYS_QUEUE_NEXT,$KEYS_TOGGLE_PLAYBACK,$KEYS_PLAY_NEXT,$KEYS_PLAY_PREV,$KEYS_SEEK_FORWARD,$KEYS_SEEK_BACKWARD"
|
||||
KEYS_N_PLAY="${KEYS_N_PLAY:-"."}"
|
||||
KEYS_N_QUEUE="${KEYS_N_QUEUE:-";"}"
|
||||
KEYS_N_QUEUE_NEXT="${KEYS_N_QUEUE_NEXT:-":"}"
|
||||
KEYS_N_TOGGLE_PLAYBACK="${KEYS_N_TOGGLE_PLAYBACK:-"space"}"
|
||||
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right,n"}"
|
||||
KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left,p"}"
|
||||
KEYS_N_SEEK_FORWARD="${KEYS_N_SEEK_FORWARD:-"N,f"}"
|
||||
KEYS_N_SEEK_BACKWARD="${KEYS_N_SEEK_BACKWARD:-"P,b"}"
|
||||
KEYS_N_PLAYBACK="$KEYS_N_PLAY,$KEYS_N_QUEUE,$KEYS_N_QUEUE_NEXT,$KEYS_N_TOGGLE_PLAYBACK,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD"
|
||||
export KEYS_PLAY KEYS_QUEUE KEYS_QUEUE_NEXT KEYS_TOGGLE_PLAYBACK \
|
||||
KEYS_PLAY_NEXT KEYS_PLAY_PREV KEYS_SEEK_FORWARD KEYS_SEEK_BACKWARD \
|
||||
KEYS_PLAYBACK KEYS_N_PLAY KEYS_N_QUEUE KEYS_N_QUEUE_NEXT \
|
||||
KEYS_N_TOGGLE_PLAYBACK KEYS_N_PLAY_NEXT KEYS_N_PLAY_PREV \
|
||||
KEYS_N_SEEK_FORWARD KEYS_N_SEEK_BACKWARD KEYS_N_PLAYBACK
|
||||
|
||||
# Keys in insert mode only
|
||||
KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}"
|
||||
# Playlist (in the playlist, there is no `insert` mode):
|
||||
KEYS_PLAYLIST_RELOAD="${KEYS_PLAYLIST_RELOAD:-"r,ctrl-r"}"
|
||||
KEYS_PLAYLIST_REMOVE="${KEYS_PLAYLIST_REMOVE:-"x,delete"}"
|
||||
KEYS_PLAYLIST_UP="${KEYS_PLAYLIST_UP:-"u"}"
|
||||
KEYS_PLAYLIST_DOWN="${KEYS_PLAYLIST_DOWN:-"d"}"
|
||||
KEYS_PLAYLIST_CLEAR="${KEYS_PLAYLIST_CLEAR:-"C"}"
|
||||
KEYS_PLAYLIST_CLEAR_ABOVE="${KEYS_PLAYLIST_CLEAR_ABOVE:-"U"}"
|
||||
KEYS_PLAYLIST_CLEAR_BELOW="${KEYS_PLAYLIST_CLEAR_BELOW:-"D"}"
|
||||
KEYS_PLAYLIST_SHUFFLE="${KEYS_PLAYLIST_SHUFFLE:-"s"}"
|
||||
KEYS_PLAYLIST_UNSHUFFLE="${KEYS_PLAYLIST_UNSHUFFLE:-"S"}"
|
||||
KEYS_PLAYLIST_GOTO_RELEASE="${KEYS_PLAYLIST_GOTO_RELEASE:-"ctrl-g"}"
|
||||
KEYS_PLAYLIST_STORE="${KEYS_PLAYLIST_STORE:-"ctrl-s"}"
|
||||
KEYS_PLAYLIST_LOAD="${KEYS_PLAYLIST_LOAD:-"ctrl-o"}"
|
||||
export KEYS_PLAYLIST_RELOAD KEYS_PLAYLIST_REMOVE KEYS_PLAYLIST_UP \
|
||||
KEYS_PLAYLIST_DOWN KEYS_PLAYLIST_CLEAR KEYS_PLAYLIST_CLEAR_ABOVE \
|
||||
KEYS_PLAYLIST_CLEAR_BELOW KEYS_PLAYLIST_SHUFFLE KEYS_PLAYLIST_UNSHUFFLE \
|
||||
KEYS_PLAYLIST_GOTO_RELEASE KEYS_PLAYLIST_STORE KEYS_PLAYLIST_LOAD
|
||||
|
||||
# Grouping
|
||||
KEYS_GROUP_NI="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,$KEYS_OPEN,$KEYS_BROWSE,$KEYS_OUT,$KEYS_IN,$KEYS_SELECT_ARTIST,$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_SWITCH_ARTIST_ALBUM,$KEYS_SWITCH_LOCAL_REMOTE,$KEYS_PLAY,$KEYS_QUEUE,$KEYS_SHOW_PLAYLIST"
|
||||
export KEYS_LOADED=1
|
||||
fi
|
||||
|
||||
KEYS_GROUP_N="$KEYS_N_DOWN,$KEYS_N_UP,$KEYS_N_OUT,$KEYS_N_IN,$KEYS_N_TOP,$KEYS_N_BOT,$KEYS_N_QUIT,$KEYS_N_INSERT,$KEYS_N_TOGGLE_PLAY_PAUSE,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD"
|
||||
# Local method to print keybindin groups
|
||||
#
|
||||
# @argument $1: Group name
|
||||
# @argument $2: Keys for first item
|
||||
# @argument $3: Description of first item
|
||||
# @argument $4: Keys for second item (optional)
|
||||
# @argument $5: Description of second item (optional)
|
||||
# @argument ...
|
||||
#
|
||||
# This is a helper method for printing key-binding groups.
|
||||
__keybindinggroup_from_args() {
|
||||
printf "$KBF_GROUP\n" "$1"
|
||||
shift
|
||||
{
|
||||
while [ "$*" ]; do
|
||||
printf "$KBF_KEY:\t$KBF_DESC\n" "$1" "${2:-"no description"}"
|
||||
shift
|
||||
shift
|
||||
done
|
||||
} | column -t -s "$(printf '\t')"
|
||||
#} | column -t -s "$(printf '\t')" -c "$FZF_PREVIEW_COLUMNS" -W 2
|
||||
printf "\n\n"
|
||||
}
|
||||
|
||||
KEYS_GROUP_I="$KEYS_I_NORMAL"
|
||||
|
||||
KEYS_PLAYLIST="$KEYS_PLAYLIST_RELOAD"
|
||||
|
||||
KEYS_ALL="$KEYS_GROUP_NI,$KEYS_GROUP_N,$KEYS_GROUP_I,$KEYS_INPUT_SINGLE,$KEYS_INPUT_SPECIAL,$KEYS_PLAYLIST"
|
||||
|
||||
export KEYS_HALFPAGE_DOWN KEYS_HALFPAGE_UP KEYS_OPEN KEYS_BROWSE KEYS_OUT KEYS_IN \
|
||||
KEYS_SELECT_ARTIST KEYS_FILTER_LOCAL KEYS_FILTER_1 KEYS_FILTER_2 KEYS_FILETER_3 KEYS_FILTER_4 \
|
||||
KEYS_SWITCH_ARTIST_ALBUM KEYS_SWITCH_LOCAL_REMOTE KEYS_PLAY KEYS_QUEUE \
|
||||
KEYS_N_DOWN KEYS_N_UP KEYS_N_OUT KEYS_N_IN KEYS_N_TOP KEYS_N_BOT KEYS_N_QUIT KEYS_N_INSERT \
|
||||
KEYS_N_TOGGLE_PLAY_PAUSE KEYS_N_PLAY_NEXT KEYS_N_PLAY_PREV KEYS_N_SEEK_FORWARD \
|
||||
KEYS_N_SEEK_BACKWARD KEYS_SHOW_PLAYLIST \
|
||||
KEYS_I_NORMAL \
|
||||
KEYS_GROUP_NI KEYS_GROUP_N KEYS_GROUP_I KEYS PLAYLIST KEYS_ALL
|
||||
# Print view-dependent keybindings
|
||||
#
|
||||
# @argument $1: view
|
||||
#
|
||||
# This method pretty-prints the keybindings active at the given view.
|
||||
print_keybindings() {
|
||||
view=$1
|
||||
case "$view" in
|
||||
"$VIEW_SELECT_ARTIST")
|
||||
__keybindinggroup_from_args "Previews" \
|
||||
"$KEYS_SCROLL_PREVIEW_DOWN" "Scroll preview down" \
|
||||
"$KEYS_SCROLL_PREVIEW_UP" "Scroll preview up" \
|
||||
"$KEYS_KEYBINDINGS" "Show these keybindings" \
|
||||
"$KEYS_PREVIEW_OPEN" "Open preview window" \
|
||||
"$KEYS_PREVIEW_CLOSE" "Close preview window"
|
||||
__keybindinggroup_from_args "Navigation" \
|
||||
"$KEYS_DOWN" "Down" \
|
||||
"$KEYS_UP" "Up" \
|
||||
"$KEYS_HALFPAGE_DOWN" "Down half a page" \
|
||||
"$KEYS_HALFPAGE_UP" "Up half a page" \
|
||||
"enter,$KEYS_IN" "Go to selected artist" \
|
||||
"$KEYS_OUT,$KEYS_QUIT" "Return to previews view"
|
||||
__keybindinggroup_from_args "Views" \
|
||||
"$KEYS_LIST_ARTISTS" "Display artists in local database" \
|
||||
"$KEYS_LIST_ALBUMS" "Display albums in local database" \
|
||||
"$KEYS_SEARCH_ARTIST" "Show artist on MusicBrainz" \
|
||||
"$KEYS_SEARCH_ALBUM" "Show album on MusicBrainz"
|
||||
__keybindinggroup_from_args "Special operations" \
|
||||
"$KEYS_SHOW_PLAYLIST" "Show playlist" \
|
||||
"$KEYS_BROWSE" "Open artist in browser"
|
||||
__keybindinggroup_from_args "Filtering" \
|
||||
"$KEYS_FILTER_LOCAL" "Show only entries in local database"
|
||||
;;
|
||||
"$VIEW_PLAYLIST")
|
||||
__keybindinggroup_from_args "Previews" \
|
||||
"$KEYS_SCROLL_PREVIEW_DOWN" "Scroll preview down" \
|
||||
"$KEYS_SCROLL_PREVIEW_UP" "Scroll preview up" \
|
||||
"$KEYS_KEYBINDINGS" "Show these keybindings" \
|
||||
"$KEYS_PREVIEW_CLOSE" "Close preview window"
|
||||
__keybindinggroup_from_args "Navigation" \
|
||||
"$KEYS_DOWN,$KEYS_N_DOWN" "Down" \
|
||||
"$KEYS_UP,$KEYS_N_UP" "Up" \
|
||||
"$KEYS_HALFPAGE_DOWN" "Down half a page" \
|
||||
"$KEYS_HALFPAGE_UP" "Up half a page" \
|
||||
"$KEYS_N_TOP" "Go to first entry" \
|
||||
"$KEYS_N_BOT" "Go to last entry" \
|
||||
"$KEYS_OUT,$KEYS_N_OUT,$KEYS_QUIT,$KEYS_N_QUIT" "Leave playlist view" \
|
||||
"$KEYS_SELECT_ARTIST" "Go to artist of selected item"
|
||||
__keybindinggroup_from_args "Views" \
|
||||
"$KEYS_LIST_ARTISTS" "Display artists in local database" \
|
||||
"$KEYS_LIST_ALBUMS" "Display albums in local database" \
|
||||
"$KEYS_SEARCH_ARTIST" "Show artist on MusicBrainz" \
|
||||
"$KEYS_SEARCH_ALBUM" "Show album on MusicBrainz"
|
||||
__keybindinggroup_from_args "Playlist" \
|
||||
"$KEYS_PLAYLIST_RELOAD" "Reload playlist" \
|
||||
"$KEYS_PLAYLIST_REMOVE" "Remove selected track" \
|
||||
"$KEYS_PLAYLIST_UP" "Move track up" \
|
||||
"$KEYS_PLAYLIST_DOWN" "Move track down" \
|
||||
"$KEYS_PLAYLIST_CLEAR" "Clear playlist" \
|
||||
"$KEYS_PLAYLIST_CLEAR_ABOVE" "Remove all tracks above" \
|
||||
"$KEYS_PLAYLIST_CLEAR_BELOW" "Remove all tracks below" \
|
||||
"$KEYS_PLAYLIST_SHUFFLE" "Shuffle" \
|
||||
"$KEYS_PLAYLIST_UNSHUFFLE" "Undo shuffle" \
|
||||
"$KEYS_PLAYLIST_GOTO_RELEASE" "Show release of selected track"
|
||||
__keybindinggroup_from_args "Playback" \
|
||||
"$KEYS_PLAY,$KEYS_N_PLAY" "Play selected item" \
|
||||
"$KEYS_QUEUE,$KEYS_N_QUEUE" "Queue selected item" \
|
||||
"$KEYS_QUEUE_NEXT,$KEYS_N_QUEUE_NEXT" "Play selected item next" \
|
||||
"$KEYS_TOGGLE_PLAYBACK,$KEYS_N_TOGGLE_PLAYBACK" "Toggle playback" \
|
||||
"$KEYS_PLAY_NEXT,$KEYS_N_PLAY_NEXT" "Play next track" \
|
||||
"$KEYS_PLAY_PREV,$KEYS_N_PLAY_PREV" "Play previous track" \
|
||||
"$KEYS_SEEK_FORWARD,$KEYS_N_SEEK_FORWARD" "Seek forward" \
|
||||
"$KEYS_SEEK_BACKWARD,$KEYS_N_SEEK_BACKWARD" "Seek backward"
|
||||
__keybindinggroup_from_args "Special operations" \
|
||||
"$KEYS_BROWSE" "Open selected item in browser" \
|
||||
"$KEYS_OPEN" "Open selected item in file manager" \
|
||||
"$KEYS_N_YANK" "Copy MusicBrainz track ID" \
|
||||
"$KEYS_YANK_CURRENT" "Copy MusicBrainz release ID"
|
||||
;;
|
||||
*)
|
||||
__keybindinggroup_from_args "Switch between modes" \
|
||||
"$KEYS_I_NORMAL" "Swtich to normal mode (insert)" \
|
||||
"$KEYS_N_INSERT" "Swtich to insert mode (normal)"
|
||||
__keybindinggroup_from_args "Previews" \
|
||||
"$KEYS_SCROLL_PREVIEW_DOWN" "Scroll preview down" \
|
||||
"$KEYS_SCROLL_PREVIEW_UP" "Scroll preview up" \
|
||||
"$KEYS_KEYBINDINGS" "Show these keybindings" \
|
||||
"$KEYS_PREVIEW_OPEN" "Open preview window" \
|
||||
"$KEYS_PREVIEW_CLOSE" "Close preview window"
|
||||
__keybindinggroup_from_args "Navigation" \
|
||||
"$KEYS_DOWN" "Down" \
|
||||
"$KEYS_UP" "Up" \
|
||||
"$KEYS_N_DOWN" "Down (normal)" \
|
||||
"$KEYS_N_UP" "Up (normal)" \
|
||||
"$KEYS_HALFPAGE_DOWN" "Down half a page" \
|
||||
"$KEYS_HALFPAGE_UP" "Up half a page" \
|
||||
"$KEYS_N_TOP" "Go to first entry (normal)" \
|
||||
"$KEYS_N_BOT" "Go to last entry (normal)" \
|
||||
"$KEYS_IN" "Open selected item" \
|
||||
"$KEYS_N_IN" "Open selected item (normal)" \
|
||||
"$KEYS_OUT" "Leave current item" \
|
||||
"$KEYS_N_OUT" "Leave current item (normal)" \
|
||||
"$KEYS_SELECT_ARTIST" "Go to artist of selected item"
|
||||
__keybindinggroup_from_args "Views" \
|
||||
"$KEYS_LIST_ARTISTS" "Display artists in local database" \
|
||||
"$KEYS_LIST_ALBUMS" "Display albums in local database" \
|
||||
"$KEYS_SEARCH_ARTIST" "Show artist on MusicBrainz" \
|
||||
"$KEYS_SEARCH_ALBUM" "Show album on MusicBrainz" \
|
||||
"$KEYS_SWITCH_ARTIST_ALBUM" "Swtich artist / album" \
|
||||
"$KEYS_SWITCH_LOCAL_REMOTE" "Swtich local database / MusicBrainz"
|
||||
__keybindinggroup_from_args "Filtering" \
|
||||
"$KEYS_FILTER_LOCAL" "Show only entries in local database" \
|
||||
"$KEYS_FILTER_0" "Clear filter" \
|
||||
"$KEYS_FILTER_1" "Reset filter to default for current view" \
|
||||
"$KEYS_FILTER_2" "Custom filter" \
|
||||
"$KEYS_FILTER_3" "Custom filter" \
|
||||
"$KEYS_FILTER_4" "Custom filter" \
|
||||
"$KEYS_FILTER_5" "Custom filter" \
|
||||
"$KEYS_FILTER_6" "Custom filter" \
|
||||
"$KEYS_FILTER_7" "Custom filter" \
|
||||
"$KEYS_FILTER_8" "Custom filter" \
|
||||
"$KEYS_FILTER_9" "Custom filter"
|
||||
__keybindinggroup_from_args "Playback" \
|
||||
"$KEYS_PLAY" "Play selected item" \
|
||||
"$KEYS_QUEUE" "Queue selected item" \
|
||||
"$KEYS_QUEUE_NEXT" "Play selected item next" \
|
||||
"$KEYS_TOGGLE_PLAYBACK" "Toggle playback" \
|
||||
"$KEYS_PLAY_NEXT" "Play next track" \
|
||||
"$KEYS_PLAY_PREV" "Play previous track" \
|
||||
"$KEYS_SEEK_FORWARD" "Seek forward" \
|
||||
"$KEYS_SEEK_BACKWARD" "Seek backward"
|
||||
__keybindinggroup_from_args "Playback (normal)" \
|
||||
"$KEYS_N_PLAY" "Play selected item" \
|
||||
"$KEYS_N_QUEUE" "Queue selected item" \
|
||||
"$KEYS_N_QUEUE_NEXT" "Play selected item next" \
|
||||
"$KEYS_N_TOGGLE_PLAYBACK" "Toggle playback" \
|
||||
"$KEYS_N_PLAY_NEXT" "Play next track" \
|
||||
"$KEYS_N_PLAY_PREV" "Play previous track" \
|
||||
"$KEYS_N_SEEK_FORWARD" "Seek forward" \
|
||||
"$KEYS_N_SEEK_BACKWARD" "Seek backward"
|
||||
__keybindinggroup_from_args "Special operations" \
|
||||
"$KEYS_SHOW_PLAYLIST" "Show playlist" \
|
||||
"$KEYS_BROWSE" "Open selected item in browser" \
|
||||
"$KEYS_OPEN" "Open selected item in file manager" \
|
||||
"$KEYS_N_YANK" "Copy selected MusicBrainz ID (normal)" \
|
||||
"$KEYS_YANK_CURRENT" "Copy current MusicBrainz ID" \
|
||||
"$KEYS_REFRESH" "Refresh current entry" \
|
||||
"$KEYS_QUIT" "Quit applicaion" \
|
||||
"$KEYS_N_QUIT" "First view or quit (normal)"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
105
src/sh/lists.sh
105
src/sh/lists.sh
@@ -1,9 +1,12 @@
|
||||
# These methods generate lists that are used as input to FZF.
|
||||
|
||||
# List release groups of given artist
|
||||
# argument $1: MB artist id
|
||||
#
|
||||
# argument $1: MusicBrainz artist ID
|
||||
list_releasegroups() {
|
||||
name=$(mb_artist "$1" | $JQ -r '.name')
|
||||
name=$(mb_artist "$1" | $JQ '.name')
|
||||
mb_artist_releasegroups "$1" |
|
||||
$JQ -r '."release-groups"[] | [
|
||||
$JQ '."release-groups"[] | [
|
||||
.id,
|
||||
."primary-type",
|
||||
(."secondary-types" // []|join(";")),
|
||||
@@ -14,6 +17,7 @@ list_releasegroups() {
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v artist="$name" \
|
||||
-v artistid="$1" \
|
||||
-v file_local_releasegroups="${LOCALDATA_RELEASEGROUPS:-}" \
|
||||
-v format_release="$RGV_RELEASE" \
|
||||
-v format_release_w_artist="$RGV_RELEASE_W_ARTIST" \
|
||||
@@ -41,20 +45,20 @@ list_releasegroups() {
|
||||
"$AWK_RELEASEGROUPS" |
|
||||
sort -n -r |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
column -t -s "$(printf '\t')" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
}
|
||||
|
||||
# List releases in given relese group
|
||||
# argument $1: MB release-group id
|
||||
#
|
||||
# argument $1: MusicBrainz release-group ID
|
||||
list_releases() {
|
||||
title="$(mb_releasegroup "$1" |
|
||||
$JQ -r '.title')"
|
||||
$JQ '.title')"
|
||||
artist="$(mb_releasegroup "$1" |
|
||||
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
$JQ '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
|
||||
mb_releasegroup_releases "$1" |
|
||||
$JQ -r --arg rid "$1" '."releases"[] | [
|
||||
$rid,
|
||||
$JQ '."releases"[] | [
|
||||
.id,
|
||||
.status,
|
||||
.date,
|
||||
@@ -76,30 +80,32 @@ list_releases() {
|
||||
-v release_withdrawn="$FORMAT_STATUS_WITHDRAWN" \
|
||||
-v release_expunged="$FORMAT_STATUS_EXPUNGED" \
|
||||
-v release_cancelled="$FORMAT_STATUS_CANCELLED" \
|
||||
-v release_format="$RV_FORMAT" \
|
||||
-v release_format_title_artist="$RV_TITLE_ARTIST" \
|
||||
-v release_format_title="$RV_TITLE" \
|
||||
-v release_format_artist="$RV_ARTIST" \
|
||||
-v format_release="$RV_FORMAT" \
|
||||
-v format_release_title_artist="$RV_TITLE_ARTIST" \
|
||||
-v format_release_title="$RV_TITLE" \
|
||||
-v format_release_artist="$RV_ARTIST" \
|
||||
-v rg_artist="$artist" \
|
||||
-v rg_title="$title" \
|
||||
-v rgid="$1" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_RELEASES" |
|
||||
sort -n -r |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
column -t -s "$(printf '\t')" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
|
||||
}
|
||||
|
||||
# List recordings of given release
|
||||
# argument $1: MB release id
|
||||
#
|
||||
# argument $1: MusicBrainz release ID
|
||||
list_recordings() {
|
||||
deco="$(grep "$1" "$LOCALDATA_RELEASES" | cut -d "$(printf '\t')" -f 2)"
|
||||
if [ "$deco" ]; then
|
||||
rectmp=$(mktemp)
|
||||
$JQ -r '.tracks | keys | join("\n")' "$deco" >"$rectmp"
|
||||
$JQ '.tracks | keys | join("\n")' "$deco" >"$rectmp"
|
||||
fi
|
||||
mb_release "$1" |
|
||||
$JQ -r \
|
||||
$JQ \
|
||||
--arg rid "$1" \
|
||||
--arg deco "$deco" \
|
||||
'.media[] |
|
||||
@@ -123,73 +129,29 @@ list_recordings() {
|
||||
"$AWK_RECORDINGS" |
|
||||
sort -k1,1n -k2,2g |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -R 3,4,7 -E 0 |
|
||||
column -t -s "$(printf '\t')" -R 3,4,7 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
|
||||
if [ "${rectmp:-}" ] && [ -f "$rectmp" ]; then
|
||||
rm -f "$rectmp"
|
||||
fi
|
||||
}
|
||||
|
||||
# List artists (local)
|
||||
# List artists available locally
|
||||
list_local_artists() {
|
||||
cat "$LOCALDATA_ARTISTS_VIEW" 2>/dev/null
|
||||
}
|
||||
|
||||
# List release groups (local)
|
||||
# List release groups vailable locally
|
||||
list_local_releasegroups() {
|
||||
cat "$LOCALDATA_RELEASEGROUPS_VIEW" 2>/dev/null
|
||||
}
|
||||
|
||||
# List releases (local)
|
||||
list_local_releases() {
|
||||
cat "$LOCALDATA_RELEASES_VIEW" 2>/dev/null
|
||||
}
|
||||
|
||||
# Generate playlist from MB release ID and path to decoration
|
||||
# @argument $1: MusicBrainz Release ID
|
||||
# @argument $2: Path to decoration file
|
||||
# @argument $3: MusicBrainz Track ID to select (optional)
|
||||
generate_playlist() {
|
||||
printf "#EXTM3U\n"
|
||||
dir="$(dirname "$2")"
|
||||
mb_release "$1" |
|
||||
$JQ -r \
|
||||
--slurpfile decofile "$2" \
|
||||
--arg base "$dir" \
|
||||
--arg deco "$2" \
|
||||
--arg tid "${3:-}" \
|
||||
'$decofile[].tracks as $filenames |
|
||||
. |
|
||||
.id as $rid |
|
||||
.media[] |
|
||||
.position as $pos |
|
||||
.tracks |
|
||||
if ($tid == "") then . else map(select(.id == $tid)) end |
|
||||
map({
|
||||
t: [
|
||||
$rid,
|
||||
.id,
|
||||
$pos,
|
||||
.number,
|
||||
.length,
|
||||
.title,
|
||||
(."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
|
||||
$deco
|
||||
] | join("\t"),
|
||||
length: (.length / 1000 | round | tostring),
|
||||
$pos,
|
||||
number: .number,
|
||||
file: $filenames[.id]
|
||||
}) |
|
||||
map(if(.number | type == "string" and test("^[0-9]+$")) then .number |= tonumber else . end) |
|
||||
sort_by([.pos, .number]) |
|
||||
map("#EXTINF:" + .length + "," + .t + "\n" + $base + "/" + .file)[]'
|
||||
}
|
||||
|
||||
# Generate artist list from JSON
|
||||
# List artist from input json data
|
||||
#
|
||||
# The input is read from stdin
|
||||
list_artists_from_json() {
|
||||
cat |
|
||||
$JQ -r 'map([.artist.id, .artist.type, .name] | join("\t")) | join("\n")' |
|
||||
$JQ 'map([.artist.id, .artist.type, .name] | join("\t")) | join("\n")' |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_artists="${LOCALDATA_ARTISTS:-}" \
|
||||
@@ -198,11 +160,10 @@ list_artists_from_json() {
|
||||
-v format_disambiguation="$AV_DISAMBIGUATION" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_ARTISTS" |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
column -t -s "$(printf '\t')" -l 2
|
||||
}
|
||||
|
||||
# Generate playlist view
|
||||
# Print playlist currently loaded
|
||||
list_playlist() {
|
||||
count=$(mpv_playlist_count)
|
||||
[ "$count" -eq 0 ] && return 0
|
||||
@@ -228,7 +189,7 @@ list_playlist() {
|
||||
-v current_id="$current_id" \
|
||||
"$AWK_RECORDINGS" |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -R 5 -E 0 |
|
||||
column -t -s "$(printf '\t')" -R 5 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
|
||||
rm -f "$rectmp" "$mpvtmp"
|
||||
}
|
||||
|
378
src/sh/local.sh
378
src/sh/local.sh
@@ -1,14 +1,51 @@
|
||||
gettags() {
|
||||
# Database functionality to support local music.
|
||||
#
|
||||
# All local data is stored in the directory `LOCALDATADIR`. In the future, we
|
||||
# will also use the methods here, and modifications thereof, to support
|
||||
# MusicBainz collections.
|
||||
if [ ! "${LOCAL_LOADED:-}" ]; then
|
||||
LOCALDATADIR="$HOME/.cache/$APP_NAME/local"
|
||||
LOCALDATA_ARTISTS="$LOCALDATADIR/artists"
|
||||
LOCALDATA_RELEASEGROUPS="$LOCALDATADIR/releasegroups"
|
||||
LOCALDATA_RELEASES="$LOCALDATADIR/releases"
|
||||
LOCALDATA_ARTISTS_VIEW="$LOCALDATADIR/artists_view"
|
||||
LOCALDATA_RELEASEGROUPS_VIEW="$LOCALDATADIR/releasegroups_view"
|
||||
LOCALDATA_RELEASES_VIEW="$LOCALDATADIR/releases_view"
|
||||
LOCALDATA_ARTISTS_LIST="$LOCALDATADIR/artists_list"
|
||||
LOCALDATA_RELEASEGROUPS_LIST="$LOCALDATADIR/releasegroups_list"
|
||||
LOCALDATA_RELEASES_LIST="$LOCALDATADIR/releases_list"
|
||||
DECORATION_FILENAME=${DECORATION_FILENAME:-"mbid.json"}
|
||||
|
||||
export LOCALDATADIR LOCALDATA_ARTISTS LOCALDATA_RELEASEGROUPS \
|
||||
LOCALDATA_RELEASES LOCALDATA_ARTISTS_VIEW LOCALDATA_RELEASEGROUPS_VIEW \
|
||||
LOCALDATA_RELEASES_VIEW LOCALDATA_ARTISTS_LIST LOCALDATA_RELEASEGROUPS_LIST \
|
||||
LOCALDATA_RELEASES_LIST DECORATION_FILENAME
|
||||
|
||||
export LOCAL_LOADED=1
|
||||
fi
|
||||
|
||||
# Retrieve tags as json object from music file
|
||||
#
|
||||
# @argument $1: path to music file
|
||||
#
|
||||
# The tags retrieved are the MusicBrainz release ID and the MusicBrainz track
|
||||
# ID
|
||||
__gettags() {
|
||||
ffprobe -v error -show_entries format_tags -print_format json "$1" |
|
||||
$JQ -r --compact-output '.format.tags | {
|
||||
$JQ '.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.
|
||||
# Decorate locally available music
|
||||
#
|
||||
# @input $1: Path to directory with album
|
||||
#
|
||||
# This methods reads the music files in the specified directory and writes a
|
||||
# json file that points to all relevant MusicBrainz IDs. If the directory
|
||||
# contains untagged files, or files of different releases, then the decoration
|
||||
# process will fail, and an error is printed.
|
||||
decorate() {
|
||||
if [ -f "$1/$DECORATION_FILENAME" ]; then
|
||||
info "Directory $1 has already been decorated (skipping)"
|
||||
@@ -16,11 +53,11 @@ decorate() {
|
||||
fi
|
||||
decoration=$($JQ -n '.tracks = {}')
|
||||
tmpf=$(mktemp)
|
||||
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a') >"$tmpf"
|
||||
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a' -o -iname '*.ogg') >"$tmpf"
|
||||
while IFS= read -r f; do
|
||||
mbid=$(gettags "$1/$f")
|
||||
rid=$(echo "$mbid" | $JQ -r '.releaseid')
|
||||
tid=$(echo "$mbid" | $JQ -r '.trackid')
|
||||
mbid=$(__gettags "$1/$f")
|
||||
rid=$(echo "$mbid" | $JQ '.releaseid')
|
||||
tid=$(echo "$mbid" | $JQ '.trackid')
|
||||
if [ ! "$rid" ] || [ ! "$tid" ]; then
|
||||
err "File $f: Seems not tagged"
|
||||
releaseid=""
|
||||
@@ -40,82 +77,175 @@ decorate() {
|
||||
done <"$tmpf"
|
||||
rm -f "$tmpf"
|
||||
if [ "$releaseid" ]; then
|
||||
echo "$decoration" | $JQ --compact-output ".releaseid = \"$releaseid\"" >"$1/$DECORATION_FILENAME"
|
||||
echo "$decoration" | $JQ ".releaseid = \"$releaseid\"" >"$1/$DECORATION_FILENAME"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Decorate locally available music with specified MusicBrainz release
|
||||
#
|
||||
# @input $1: Path to directory with album
|
||||
# @input $2: MusicBrainz release ID
|
||||
#
|
||||
# Similar as `decorate`, but the MusicBrainz IDs are not inferred from the
|
||||
# tags, but passed as argument.
|
||||
decorate_as() {
|
||||
if [ -f "$1/$DECORATION_FILENAME" ]; then
|
||||
rid="$($JQ '.releaseid' "$1/$DECORATION_FILENAME")"
|
||||
title="$(mb_release "$rid" | $JQ '.title // ""')"
|
||||
artist="$(mb_release "$rid" | $JQ '."artist-credit" | map([.name, .joinphrase] | join("")) | join("")')"
|
||||
[ "$rid" = "$2" ] &&
|
||||
info "Directory $1 has already been decorated as the release '$title' - '$artist' with the identical MusicBrainz release ID." ||
|
||||
info "Directory $1 has already been decorated as the release '$title' - '$artist' with the MusicBrainz release ID $rid."
|
||||
while true; do
|
||||
infonn "Do you want to redecorate $1? (yes/no)"
|
||||
read -r yn
|
||||
case $yn in
|
||||
"yes") break ;;
|
||||
"no") return 0 ;;
|
||||
*) info "Please answer \"yes\" or \"no\"." ;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
# Print info
|
||||
title="$(mb_release "$2" | $JQ '.title // ""')"
|
||||
artist="$(mb_release "$2" | $JQ '."artist-credit" | map([.name, .joinphrase] | join("")) | join("")')"
|
||||
info "Decorating $1 as the release $title by $artist"
|
||||
# Start decoration
|
||||
decoration=$($JQ -n '.tracks = {}')
|
||||
tmpf=$(mktemp)
|
||||
(cd "$1" && find . -type f -iname '*.mp3' -o -iname '*.mp4' -o -iname '*.flac' -o -iname '*.m4a' -o -iname '*.ogg' | sort) >"$tmpf"
|
||||
# Compare number of tracks with release
|
||||
rcnt="$(mb_release "$2" | $JQ '.media | map(."track-count") | add')"
|
||||
dcnt="$(wc -l "$tmpf" | cut -d ' ' -f 1)"
|
||||
if [ ! "$rcnt" -eq "$dcnt" ]; then
|
||||
err "Number of tracks in directory ($dcnt) does not match number of tracks in release ($rcnt)."
|
||||
return 1
|
||||
fi
|
||||
#
|
||||
tmpj=$(mktemp)
|
||||
mb_release "$2" |
|
||||
$JQ '.media[] |
|
||||
.position as $pos |
|
||||
.tracks |
|
||||
map({
|
||||
$pos,
|
||||
"id": .id,
|
||||
"n": .number,
|
||||
"t": .title
|
||||
}) |
|
||||
map(if(.n | type == "string" and test("^[0-9]+$")) then .n |= tonumber else . end) |
|
||||
sort_by([.pos, .n])[] |
|
||||
[.t, .id] |
|
||||
join("\t")' >"$tmpj"
|
||||
assocfile=$(mktemp)
|
||||
awk -F '\t' '
|
||||
BEGIN { OFS = "\t" }
|
||||
FNR == NR { title[FNR] = $1; id[FNR] = $2 }
|
||||
FNR != NR { fname[FNR] = $1 }
|
||||
END { for (i in id) print title[i], id[i], fname[i] }
|
||||
' "$tmpj" "$tmpf" >"$assocfile"
|
||||
rm -f "$tmpj" "$tmpf"
|
||||
# Ask user if this is ok
|
||||
info "We discovered the following associatoin:"
|
||||
while IFS= read -r line; do
|
||||
t="$(echo "$line" | cut -d "$(printf '\t')" -f 1)"
|
||||
f="$(echo "$line" | cut -d "$(printf '\t')" -f 3)"
|
||||
printf "Track '%s'\tFile '%s'\n" "$t" "$f"
|
||||
done <"$assocfile" | column -t -s "$(printf '\t')"
|
||||
while true; do
|
||||
infonn "Are the track correctly associated to the audio files? (yes/no)"
|
||||
read -r yn
|
||||
case $yn in
|
||||
"yes") break ;;
|
||||
"no") return 0 ;;
|
||||
*) info "Please answer \"yes\" or \"no\"." ;;
|
||||
esac
|
||||
done
|
||||
# Construct decoration
|
||||
decoration=$($JQ -n '.tracks = {}')
|
||||
while IFS= read -r line; do
|
||||
i="$(echo "$line" | cut -d "$(printf '\t')" -f 2)"
|
||||
f="$(echo "$line" | cut -d "$(printf '\t')" -f 3)"
|
||||
decoration=$(echo "$decoration" | $JQ ".tracks += {\"$i\": \"$f\"}")
|
||||
done <"$assocfile"
|
||||
echo "$decoration" | $JQ ".releaseid = \"$2\"" >"$1/$DECORATION_FILENAME"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Load missing cache entries (batch mode)
|
||||
#
|
||||
# argument $1: type
|
||||
# argument $2: File with one ID per line
|
||||
#
|
||||
# This method reads one MusicBrainz IDs of the specified type from stdin (one
|
||||
# per line), and fetches the missing items.
|
||||
__batch_load_missing() {
|
||||
tmpf=$(mktemp)
|
||||
while IFS= read -r mbid; do
|
||||
if ! in_cache "$1" "$mbid"; then
|
||||
echo "$mbid" >>"$tmpf"
|
||||
fi
|
||||
done <"$2"
|
||||
if [ -s "$tmpf" ]; then
|
||||
cat |
|
||||
cache_get_file_batch "$1" |
|
||||
xargs \
|
||||
sh -c 'for f; do [ -e "$f" ] || echo "$f"; done' _ |
|
||||
cache_mbid_from_path_batch >"$tmpf"
|
||||
lines=$(wc -l "$tmpf" | cut -d ' ' -f 1)
|
||||
if [ "$lines" -gt 0 ]; then
|
||||
case "$1" in
|
||||
"$TYPE_ARTIST")
|
||||
tt="artists"
|
||||
;;
|
||||
"$TYPE_RELEASEGROUP")
|
||||
tt="release groups"
|
||||
;;
|
||||
"$TYPE_RELEASE")
|
||||
tt="releases"
|
||||
;;
|
||||
"$TYPE_ARTIST") tt="artists" ;;
|
||||
"$TYPE_RELEASEGROUP") tt="release groups" ;;
|
||||
"$TYPE_RELEASE") tt="releases" ;;
|
||||
esac
|
||||
info "Fetching $lines missing $tt"
|
||||
info "Fetching missing $tt"
|
||||
cnt=0
|
||||
while IFS= read -r mbid; do
|
||||
case "$1" in
|
||||
"$TYPE_ARTIST")
|
||||
name=$(mb_artist "$mbid" | $JQ -r ".name")
|
||||
;;
|
||||
"$TYPE_RELEASEGROUP")
|
||||
name=$(mb_releasegroup "$mbid" | $JQ -r ".title")
|
||||
;;
|
||||
"$TYPE_RELEASE")
|
||||
name=$(mb_release "$mbid" | $JQ -r ".title")
|
||||
name=$(mb_artist "$mbid" | $JQ '.name')
|
||||
;;
|
||||
"$TYPE_RELEASEGROUP") name=$(mb_releasegroup "$mbid" | $JQ '.title') ;;
|
||||
"$TYPE_RELEASE") name=$(mb_release "$mbid" | $JQ '.title') ;;
|
||||
esac
|
||||
cnt=$((cnt + 1))
|
||||
printf "\033[2K\r%d/%d (%s: %s)" "$cnt" "$lines" "$mbid" "$name"
|
||||
info "$(printf "%d/%d (%s: %s)" "$cnt" "$lines" "$mbid" "$name")"
|
||||
sleep 1
|
||||
done <"$tmpf"
|
||||
printf "\n"
|
||||
fi
|
||||
fi
|
||||
rm -f "$tmpf"
|
||||
}
|
||||
|
||||
LOCALDATADIR="$HOME/.cache/$APP_NAME/local"
|
||||
LOCALDATA_ARTISTS="$LOCALDATADIR/artists"
|
||||
LOCALDATA_RELEASEGROUPS="$LOCALDATADIR/releasegroups"
|
||||
LOCALDATA_RELEASES="$LOCALDATADIR/releases"
|
||||
LOCALDATA_ARTISTS_VIEW="$LOCALDATADIR/artists_view"
|
||||
LOCALDATA_RELEASEGROUPS_VIEW="$LOCALDATADIR/releasegroups_view"
|
||||
LOCALDATA_RELEASES_VIEW="$LOCALDATADIR/releases_view"
|
||||
DECORATION_FILENAME=${DECORATION_FILENAME:-"mbid.json"}
|
||||
|
||||
# Precompute views
|
||||
precompute_view() {
|
||||
info "Precomputing artist view"
|
||||
while IFS= read -r aid; do
|
||||
mb_artist "$aid" | $JQ -r '[
|
||||
# Precompute lists
|
||||
#
|
||||
# The main views (VIEW_ARTIST and TYPE_RELEASEGROUP) for locally available
|
||||
# music are theme dependent. These views are generated from the lists that are
|
||||
# produced with the present method. It contains all essential data, but in a
|
||||
# theme-independent fashion. The lists are stored in the files
|
||||
# `LOCALDATA_ARTISTS_LIST` and `LOCALDATA_RELEASEGROUPS_LIST`.
|
||||
__precompute_lists() {
|
||||
cache_get_file_batch "$TYPE_ARTIST" <"$LOCALDATA_ARTISTS" | xargs \
|
||||
$JQ '[
|
||||
.id,
|
||||
.type,
|
||||
.name,
|
||||
.disambiguation,
|
||||
.["life-span"].begin,
|
||||
.["life-span"].end
|
||||
] | join("\t")'
|
||||
done <"$LOCALDATA_ARTISTS" |
|
||||
] | join("\t")' >"$LOCALDATA_ARTISTS_LIST"
|
||||
cache_get_file_batch "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS" | xargs \
|
||||
$JQ '[
|
||||
.id,
|
||||
."primary-type",
|
||||
(."secondary-types" // []|join(";")),
|
||||
."first-release-date",
|
||||
.title,
|
||||
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
|
||||
] | join("\t")' >"$LOCALDATA_RELEASEGROUPS_LIST"
|
||||
}
|
||||
|
||||
# Precompute views
|
||||
#
|
||||
# This method injects the theme elements to the lists from `precompute_lists`.
|
||||
# The resulting views are stored in the files `LOCALDATA_ARTISTS_VIEW` and
|
||||
# `LOCALDATA_RELEASEGROUPS_VIEW`.
|
||||
precompute_views() {
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_artists="${LOCALDATA_ARTISTS:-}" \
|
||||
@@ -123,21 +253,11 @@ precompute_view() {
|
||||
-v format_group="$AV_GROUP" \
|
||||
-v format_disambiguation="$AV_DISAMBIGUATION" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_ARTISTS" |
|
||||
"$AWK_ARTISTS" "$LOCALDATA_ARTISTS_LIST" |
|
||||
sort |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|' >"$LOCALDATA_ARTISTS_VIEW"
|
||||
info "Precomputing releasegroup view"
|
||||
while IFS= read -r rgid; do
|
||||
mb_releasegroup "$rgid" | $JQ -r '[
|
||||
.id,
|
||||
."primary-type",
|
||||
(."secondary-types" // []|join(";")),
|
||||
."first-release-date",
|
||||
.title,
|
||||
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
|
||||
] | join("\t")'
|
||||
done <"$LOCALDATA_RELEASEGROUPS" |
|
||||
column -t -s "$(printf '\t')" -l 2 >"$LOCALDATA_ARTISTS_VIEW"
|
||||
#column -t -s "$(printf '\t')" |
|
||||
#sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|' >"$LOCALDATA_ARTISTS_VIEW"
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_releasegroups="${LOCALDATA_RELEASEGROUPS:-}" \
|
||||
@@ -164,76 +284,70 @@ precompute_view() {
|
||||
-v format_demo="$FORMAT_TYPE_SECONDARY_DEMO" \
|
||||
-v format_fieldrec="$FORMAT_TYPE_SECONDARY_FIELDREC" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_RELEASEGROUPS" |
|
||||
sort -n -r |
|
||||
"$AWK_RELEASEGROUPS" "$LOCALDATA_RELEASEGROUPS_LIST" | sort -n -r |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|' >"$LOCALDATA_RELEASEGROUPS_VIEW"
|
||||
info "Precomputing release view"
|
||||
cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" |
|
||||
while IFS= read -r rid; do
|
||||
mb_release "$rid" | $JQ -r '[
|
||||
"0",
|
||||
.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")'
|
||||
done |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_releases="${LOCALDATA_RELEASES:-}" \
|
||||
-v release_official="$FORMAT_STATUS_OFFICIAL" \
|
||||
-v release_promotion="$FORMAT_STATUS_PROMO" \
|
||||
-v release_bootleg="$FORMAT_STATUS_BOOTLEG" \
|
||||
-v release_pseudo="$FORMAT_STATUS_PSEUDO" \
|
||||
-v release_withdrawn="$FORMAT_STATUS_WITHDRAWN" \
|
||||
-v release_expunged="$FORMAT_STATUS_EXPUNGED" \
|
||||
-v release_cancelled="$FORMAT_STATUS_CANCELLED" \
|
||||
-v release_format="$RV_FORMAT" \
|
||||
-v release_format_title_artist="$RV_TITLE_ARTIST" \
|
||||
-v release_format_title="$RV_TITLE" \
|
||||
-v release_format_artist="$RV_ARTIST" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_RELEASES" |
|
||||
sort -n -r |
|
||||
cut -d "$(printf '\t')" -f 2- |
|
||||
column -t -s "$(printf '\t')" -E 0 |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|' >"$LOCALDATA_RELEASES_VIEW"
|
||||
column -t -s "$(printf '\t')" -l 5 >"$LOCALDATA_RELEASEGROUPS_VIEW"
|
||||
#column -t -s "$(printf '\t')" |
|
||||
#sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|' >"$LOCALDATA_RELEASEGROUPS_VIEW"
|
||||
}
|
||||
|
||||
# Load local music
|
||||
#
|
||||
# argument $1: path to decorated music files
|
||||
load_local() {
|
||||
[ -d "$LOCALDATADIR" ] || mkdir -p "$LOCALDATADIR"
|
||||
tmpreleases=$(mktemp)
|
||||
[ -f "$tmpreleases" ] || exit 1
|
||||
info "Locating and parsing decoration files ($DECORATION_FILENAME)"
|
||||
#
|
||||
# This method parses all decorations and generates a line-by-line database of
|
||||
# locally available artists, releases, and release groups. This data is stored
|
||||
# in the files `LOCALDATA_ARTISTS`, `LOCALDATA_RELEASES`, and
|
||||
# `LOCALDATA_RELEASEGROUPS`.
|
||||
reloaddb() {
|
||||
rm -rf "$LOCALDATADIR"
|
||||
mkdir -p "$LOCALDATADIR"
|
||||
find "$1" -type f -name "$DECORATION_FILENAME" -print0 |
|
||||
xargs -0 -P 4 $JQ -r '.releaseid+"\t"+input_filename' |
|
||||
tee "$LOCALDATA_RELEASES" |
|
||||
cut -d "$(printf '\t')" -f 1 >"$tmpreleases"
|
||||
__batch_load_missing "$TYPE_RELEASE" "$tmpreleases"
|
||||
# Get release groups and album artists
|
||||
while IFS= read -r rid; do
|
||||
mb=$(mb_release "$rid")
|
||||
echo "$mb" | $JQ -r '."release-group".id' >>"$LOCALDATA_RELEASEGROUPS"
|
||||
echo "$mb" | $JQ -r '."release-group"."artist-credit" | map(.artist.id) | join("\n")' >>"$LOCALDATA_ARTISTS"
|
||||
done <"$tmpreleases"
|
||||
tf=$(mktemp)
|
||||
sort "$LOCALDATA_RELEASEGROUPS" | uniq >"$tf" && mv "$tf" "$LOCALDATA_RELEASEGROUPS"
|
||||
sort "$LOCALDATA_ARTISTS" | uniq >"$tf" && mv "$tf" "$LOCALDATA_ARTISTS"
|
||||
# Populate cache with missing data
|
||||
__batch_load_missing "$TYPE_RELEASEGROUP" "$LOCALDATA_RELEASEGROUPS"
|
||||
__batch_load_missing "$TYPE_ARTIST" "$LOCALDATA_ARTISTS"
|
||||
rm -f "$tmpreleases"
|
||||
info "Resetting views"
|
||||
rm -f "$LOCALDATA_ARTISTS_VIEW" "$LOCALDATA_RELEASEGROUPS_VIEW" "$LOCALDATA_RELEASES_VIEW"
|
||||
precompute_view
|
||||
xargs -0 $JQ '.releaseid+"\t"+input_filename' >"$LOCALDATA_RELEASES"
|
||||
# Get necessary metadata and setup lists
|
||||
tmpreleases=$(mktemp)
|
||||
cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" |
|
||||
tee "$tmpreleases" |
|
||||
__batch_load_missing "$TYPE_RELEASE"
|
||||
tmpreleasefiles=$(mktemp)
|
||||
cache_get_file_batch "$TYPE_RELEASE" <"$tmpreleases" >"$tmpreleasefiles"
|
||||
xargs \
|
||||
$JQ '."release-group".id' \
|
||||
<"$tmpreleasefiles" >"$LOCALDATA_RELEASEGROUPS"
|
||||
xargs \
|
||||
$JQ '."release-group"."artist-credit" | map(.artist.id) | join("\n")' \
|
||||
<"$tmpreleasefiles" >"$LOCALDATA_ARTISTS"
|
||||
rm -f "$tmpreleases" "$tmpreleasefiles"
|
||||
tf1=$(mktemp)
|
||||
tf2=$(mktemp)
|
||||
sort "$LOCALDATA_RELEASEGROUPS" | uniq >"$tf1"
|
||||
mv "$tf1" "$LOCALDATA_RELEASEGROUPS"
|
||||
sort "$LOCALDATA_ARTISTS" | uniq >"$tf2"
|
||||
mv "$tf2" "$LOCALDATA_ARTISTS"
|
||||
__batch_load_missing "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS"
|
||||
__batch_load_missing "$TYPE_ARTIST" <"$LOCALDATA_ARTISTS"
|
||||
__precompute_lists
|
||||
}
|
||||
|
||||
# Check if necessary cache files are present or not
|
||||
#
|
||||
# This method returns a non-zero value if some cached file is required to exist
|
||||
# for the computation of the lists (and views). This does not include the
|
||||
# derivation of the MusicBrainz artist IDs and MusicBrainz release-group IDs
|
||||
# from the MusicBrainz releases (see the `reloaddb` method above).
|
||||
local_files_present() {
|
||||
cache_get_file_batch "$TYPE_ARTIST" <"$LOCALDATA_ARTISTS" | xargs ls >/dev/null 2>&1 || return 1
|
||||
cache_get_file_batch "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS" | xargs ls >/dev/null 2>&1 || return 1
|
||||
#cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" | cache_get_file_batch "$TYPE_RELEASE" | xargs ls >/dev/null 2>&1 || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
# Load missing files
|
||||
#
|
||||
# If missing files were detected with `local_files_present`, then these missing
|
||||
# files may be cached using the present method.
|
||||
load_missing_files() {
|
||||
__batch_load_missing "$TYPE_ARTIST" <"$LOCALDATA_ARTISTS"
|
||||
__batch_load_missing "$TYPE_RELEASEGROUP" <"$LOCALDATA_RELEASEGROUPS"
|
||||
#cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" | __batch_load_missing "$TYPE_RELEASE"
|
||||
}
|
||||
|
32
src/sh/log.sh
Normal file
32
src/sh/log.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
# Logging methods
|
||||
#
|
||||
# The default log file is `LOGFILE`. In the future, this file may become
|
||||
# configurable.
|
||||
if [ ! "${LOG_LOADED:-}" ]; then
|
||||
ERR="\033[38;5;196m"
|
||||
INFO="\033[38;5;75m"
|
||||
OFF="\033[m"
|
||||
LOGDIR="$HOME/.local/state/$APP_NAME"
|
||||
[ -d "$LOGDIR" ] || mkdir -p "$LOGDIR"
|
||||
LOGFILE="$LOGDIR/log"
|
||||
export ERR INFO OFF LOGFILE
|
||||
|
||||
export LOG_LOADED=1
|
||||
fi
|
||||
|
||||
# Print an error message to stderr and log it incuding the time stamp and PID
|
||||
# to the log file.
|
||||
err() {
|
||||
echo "$(date) [$$]>${ERR}ERROR:${OFF} ${1:-}" | tee -a "$LOGFILE" | cut -d ">" -f 2- >/dev/stderr
|
||||
}
|
||||
|
||||
# Print information to stderr and log it incuding the time stamp and PID to the
|
||||
# log file.
|
||||
info() {
|
||||
echo "$(date) [$$]>${INFO}Info:${OFF} ${1:-}" | tee -a "$LOGFILE" | cut -d ">" -f 2- >/dev/stderr
|
||||
}
|
||||
|
||||
# Like `info` but without newlnes on stderr.
|
||||
infonn() {
|
||||
echo "$(date) [$$]>${INFO}Info:${OFF} ${1:-}" | tee -a "$LOGFILE" | cut -d ">" -f 2- | tr '\n' ' ' >/dev/stderr
|
||||
}
|
177
src/sh/mb.sh
177
src/sh/mb.sh
@@ -1,7 +1,13 @@
|
||||
# The only IDs uses here are MusicBrainz IDs
|
||||
# This files provides a high-level access to the MusicBrainz databse. The only
|
||||
# IDs used here are MusicBrainz IDs
|
||||
|
||||
# Helper methods to retrieve from cache, if it exists, and otherwise populate
|
||||
# cache and retrieve
|
||||
# The following methods are local methods that combines the MusicBrainz API
|
||||
# with the caching methods.
|
||||
|
||||
# Retrieve MusicBrainz data for artist from cache (if it exists), and otherwise
|
||||
# download it using the MusicBrainz API.
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
__mb_artist_cache_or_fetch() {
|
||||
if ! cache_get_artist "$1"; then
|
||||
api_mb_artist "$1" | cache_put_artist "$1"
|
||||
@@ -9,6 +15,10 @@ __mb_artist_cache_or_fetch() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Retrieve MusicBrainz data for release group from cache (if it exists), and
|
||||
# otherwise download it using the MusicBrainz API.
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
__mb_releasegroup_cache_or_fetch() {
|
||||
if ! cache_get_releasegroup "$1"; then
|
||||
api_mb_releasegroup "$1" | cache_put_releasegroup "$1"
|
||||
@@ -16,6 +26,10 @@ __mb_releasegroup_cache_or_fetch() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Retrieve MusicBrainz data for release from cache (if it exists), and
|
||||
# otherwise download it using the MusicBrainz API.
|
||||
#
|
||||
# @argument $1: MusicBrainz release ID
|
||||
__mb_release_cache_or_fetch() {
|
||||
if ! cache_get_release "$1"; then
|
||||
api_mb_release "$1" | cache_put_release "$1"
|
||||
@@ -23,11 +37,15 @@ __mb_release_cache_or_fetch() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Retrieve MusicBrainz data for release groups of given artist from cache (if
|
||||
# it exists), and otherwise download it using the MusicBrainz API.
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
__mb_artist_cache_or_fetch_releasegroups() {
|
||||
if ! cache_get_artist_releasegroups "$1"; then
|
||||
api_mb_browse_artist_releasegroups "$1" | cache_put_artist_releasegroups "$1"
|
||||
rg="$(cache_get_artist_releasegroups "$1")"
|
||||
total=$(printf "%s" "$rg" | $JQ -r '."release-group-count"')
|
||||
total=$(printf "%s" "$rg" | $JQ '."release-group-count"')
|
||||
seen=$MB_BROWSE_STEPS
|
||||
while [ "$total" -gt "$seen" ]; do
|
||||
# Fetch remaning release groups, and append to cache
|
||||
@@ -39,11 +57,15 @@ __mb_artist_cache_or_fetch_releasegroups() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Retrieve MusicBrainz data for releases of given release group from cache (if
|
||||
# it exists), and otherwise download it using the MusicBrainz API.
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
__mb_releasegroup_cache_or_fetch_releases() {
|
||||
if ! cache_get_releasegroup_releases "$1"; then
|
||||
api_mb_browse_releasegroup_releases "$1" | cache_put_releasegroup_releases "$1"
|
||||
releases="$(cache_get_releasegroup_releases "$1")"
|
||||
total=$(printf "%s" "$releases" | $JQ -r '."release-count"')
|
||||
total=$(printf "%s" "$releases" | $JQ '."release-count"')
|
||||
seen=$MB_BROWSE_STEPS
|
||||
while [ "$total" -gt "$seen" ]; do
|
||||
# Fetch remaning releases, and append to cache
|
||||
@@ -55,18 +77,22 @@ __mb_releasegroup_cache_or_fetch_releases() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Get MusicBrainz json for artist
|
||||
# @argument $1: MusicBrainz Artist ID
|
||||
# The following methods provide the external interface
|
||||
|
||||
# Retrieve MusicBrainz data for artist
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
mb_artist() {
|
||||
__mb_artist_cache_or_fetch "$1"
|
||||
}
|
||||
|
||||
# Get Wikidata json for artist
|
||||
# @argument $1: MusicBrainz Artist ID
|
||||
# Retrieve Wikidata data for artist
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
mb_artist_wikidata() {
|
||||
if ! cache_get_artist_wikidata "$1"; then
|
||||
wikidataid=$(mb_artist "$1" |
|
||||
$JQ -r '.relations |
|
||||
$JQ '.relations |
|
||||
map(select(.type=="wikidata")) |
|
||||
.[0].url.resource // ""' |
|
||||
awk -F "/" '{print $NF}')
|
||||
@@ -76,8 +102,9 @@ mb_artist_wikidata() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Get Wikipedia (English) summary json for artist
|
||||
# @argument $1: MusicBrainz Artist ID
|
||||
# Retrieve Wikipedia (English) summary json for artist
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
mb_artist_enwikipedia() {
|
||||
if ! cache_get_artist_enwikipedia "$1"; then
|
||||
# To fetch the wikipedia data, we need the wikipedia URL
|
||||
@@ -89,7 +116,7 @@ mb_artist_enwikipedia() {
|
||||
# take the second route.
|
||||
wikidata=$(mb_artist_wikidata "$1" || true)
|
||||
wikiid=$(printf "%s" "$wikidata" |
|
||||
$JQ -r '.enwiki.url // ""' |
|
||||
$JQ '.enwiki.url // ""' |
|
||||
awk -F "/" '{print $NF}')
|
||||
[ ! "$wikiid" ] && return
|
||||
api_wikipedia_en_summary "$wikiid" | cache_put_artist_enwikipedia "$1"
|
||||
@@ -97,12 +124,13 @@ mb_artist_enwikipedia() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Get Discogs json for artist
|
||||
# @argument $1: MusicBrainz Artist ID
|
||||
# Retrieve Discogs json for artist
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
mb_artist_discogs() {
|
||||
if ! cache_get_artist_discogs "$1"; then
|
||||
discogsid=$(mb_artist "$1" |
|
||||
$JQ -r '.relations |
|
||||
$JQ '.relations |
|
||||
map(select(.type=="discogs")) |
|
||||
.[0].url.resource // ""' |
|
||||
awk -F "/" '{print $NF}')
|
||||
@@ -112,22 +140,131 @@ mb_artist_discogs() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Get release-groups json for artist
|
||||
# @argument $1: MusicBrainz Artist ID
|
||||
# Retrieve release groups for artist
|
||||
#
|
||||
# @argument $1: MusicBrainz artist ID
|
||||
mb_artist_releasegroups() {
|
||||
__mb_artist_cache_or_fetch_releasegroups "$1"
|
||||
}
|
||||
|
||||
# Get MusicBrainz json for release group
|
||||
# @argument $1: MusicBrainz Release-Group ID
|
||||
# Retrieve MusicBrainz release group
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
mb_releasegroup() {
|
||||
__mb_releasegroup_cache_or_fetch "$1"
|
||||
}
|
||||
|
||||
# Retrieve MusicBrainz releases of release group
|
||||
#
|
||||
# @argument $1: MusicBrainz release-group ID
|
||||
mb_releasegroup_releases() {
|
||||
__mb_releasegroup_cache_or_fetch_releases "$1"
|
||||
}
|
||||
|
||||
# Retrieve MusicBrainz release
|
||||
#
|
||||
# @argument $1: MusicBrainz release ID
|
||||
mb_release() {
|
||||
__mb_release_cache_or_fetch "$1"
|
||||
}
|
||||
|
||||
# Reload hook that is used after a change in the query (when searching
|
||||
# MusicBrainz).
|
||||
#
|
||||
# This method waits for the search to complete, then it parses the search
|
||||
# results and prints them.
|
||||
mb_results_async() {
|
||||
# Wait for async. process to terminate
|
||||
sleep 1
|
||||
while [ -f "$LOCKFILE" ]; do
|
||||
sleep 1
|
||||
done
|
||||
# Show results
|
||||
column -t -s "$(printf '\t')" "$RESULTS" |
|
||||
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
|
||||
}
|
||||
|
||||
# Initiate search on MusicBrainz
|
||||
#
|
||||
# @argument $1: view
|
||||
#
|
||||
# This methods initiates an asynchronous search for both views
|
||||
# (VIEW_SEARCH_ARTIST and VIEW_SEARCH_ALBUM). If a running query is detected,
|
||||
# that one is killed first. The search results are then stored and become
|
||||
# retrievable using `mb_results_async`.
|
||||
mb_search_async() {
|
||||
view="$1"
|
||||
# Kill any running search
|
||||
if [ -f "$PIDFILE" ]; then
|
||||
pid=$(cat "$PIDFILE")
|
||||
rm -f "$PIDFILE"
|
||||
kill -9 "$pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
# Stop, if no search string is given
|
||||
[ "$FZF_QUERY" ] || exit 0
|
||||
# Store PID of current process
|
||||
echo "$$" >"$PIDFILE"
|
||||
touch "$LOCKFILE"
|
||||
sleep 1
|
||||
if [ "$view" = "$VIEW_SEARCH_ARTIST" ]; then
|
||||
api_mb_search_artist "$FZF_QUERY" |
|
||||
$JQ '.artists[] | [
|
||||
.id,
|
||||
.type,
|
||||
.name,
|
||||
.disambiguation,
|
||||
.["life-span"].begin,
|
||||
.["life-span"].end
|
||||
] | join("\t")' |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_artists="${LOCALDATA_ARTISTS:-}" \
|
||||
-v format_person="$AV_PERSON" \
|
||||
-v format_group="$AV_GROUP" \
|
||||
-v format_disambiguation="$AV_DISAMBIGUATION" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_ARTISTS" >"$RESULTS" ||
|
||||
true
|
||||
else
|
||||
api_mb_search_releasegroup "$FZF_QUERY" |
|
||||
$JQ '."release-groups"[] | [
|
||||
.id,
|
||||
."primary-type",
|
||||
(."secondary-types" // []|join(";")),
|
||||
."first-release-date",
|
||||
.title,
|
||||
(."artist-credit" | map(([.name, .joinphrase]|join(""))) | join(""))
|
||||
] | join("\t")' |
|
||||
awk \
|
||||
-F "\t" \
|
||||
-v file_local_releasegroups="${LOCALDATA_RELEASEGROUPS:-}" \
|
||||
-v format_release="$RGV_RELEASE" \
|
||||
-v format_release_w_artist="$RGV_RELEASE_W_ARTIST" \
|
||||
-v format_year="$RGV_YEAR" \
|
||||
-v format_album="$FORMAT_TYPE_ALBUM" \
|
||||
-v format_single="$FORMAT_TYPE_SINGLE" \
|
||||
-v format_ep="$FORMAT_TYPE_EP" \
|
||||
-v format_broadcast="$FORMAT_TYPE_BROADCAST" \
|
||||
-v format_other="$FORMAT_TYPE_OTHER" \
|
||||
-v format_has_secondary="$FORMAT_TYPE_HAS_SECONDARY" \
|
||||
-v format_secondary="$FORMAT_TYPE_SECONDARY" \
|
||||
-v format_compilation="$FORMAT_TYPE_SECONDARY_COMPILATION" \
|
||||
-v format_soundtrack="$FORMAT_TYPE_SECONDARY_SOUNDTRACK" \
|
||||
-v format_spokenword="$FORMAT_TYPE_SECONDARY_SPOKENWORD" \
|
||||
-v format_interview="$FORMAT_TYPE_SECONDARY_INTERVIEW" \
|
||||
-v format_audiobook="$FORMAT_TYPE_SECONDARY_AUDIOBOOK" \
|
||||
-v format_audiodrama="$FORMAT_TYPE_SECONDARY_AUDIODRAMA" \
|
||||
-v format_live="$FORMAT_TYPE_SECONDARY_LIVE" \
|
||||
-v format_remix="$FORMAT_TYPE_SECONDARY_REMIX" \
|
||||
-v format_djmix="$FORMAT_TYPE_SECONDARY_DJMIX" \
|
||||
-v format_mixtape="$FORMAT_TYPE_SECONDARY_MIXTAPE" \
|
||||
-v format_demo="$FORMAT_TYPE_SECONDARY_DEMO" \
|
||||
-v format_fieldrec="$FORMAT_TYPE_SECONDARY_FIELDREC" \
|
||||
-v format_local="$FORMAT_LOCAL" \
|
||||
"$AWK_RELEASEGROUPS" |
|
||||
cut -d "$(printf '\t')" -f 2- >"$RESULTS" ||
|
||||
true
|
||||
fi
|
||||
# Process ends now: Display and quit
|
||||
rm -f "$LOCKFILE" "$PIDFILE"
|
||||
}
|
||||
|
@@ -1,45 +1,114 @@
|
||||
# Interface to the mpv music player. This interface communicates to an mpv
|
||||
# instance through the socket `MPV_SOCKET`.
|
||||
|
||||
# Internal helper method to send a command without arguments to mpv
|
||||
#
|
||||
# @argument $1: command
|
||||
__mpv_command() {
|
||||
printf "{ \"command\": [\"%s\"] }\n" "$1" | $SOCAT - "$MPV_SOCKET"
|
||||
}
|
||||
|
||||
# Internal helper method to send a command with a single argument to mpv
|
||||
#
|
||||
# @argument $1: command
|
||||
# @argument $2: argument
|
||||
__mpv_command_with_arg() {
|
||||
printf "{ \"command\": [\"%s\", \"%s\"] }\n" "$1" "$2" | $SOCAT - "$MPV_SOCKET"
|
||||
}
|
||||
|
||||
# Internal helper method to send a command with two arguments to mpv
|
||||
#
|
||||
# @argument $1: command
|
||||
# @argument $2: argument 1
|
||||
# @argument $3: argument 2
|
||||
__mpv_command_with_args2() {
|
||||
printf "{ \"command\": [\"%s\", \"%s\", \"%s\"] }\n" "$1" "$2" "$3" | $SOCAT - "$MPV_SOCKET"
|
||||
}
|
||||
|
||||
# Internal helper method to resolve mpv variables
|
||||
#
|
||||
# @argument $1: mpv expression
|
||||
__mpv_get() {
|
||||
__mpv_command_with_arg "expand-text" "$1" | $JQ -r '.data'
|
||||
__mpv_command_with_arg "expand-text" "$1" | $JQ '.data'
|
||||
}
|
||||
|
||||
# Get the total number of tracks in the playlist
|
||||
mpv_playlist_count() {
|
||||
__mpv_get '${playlist-count}'
|
||||
}
|
||||
|
||||
# Get the position of the current track in the playlist (0 based)
|
||||
mpv_playlist_position() {
|
||||
__mpv_get '${playlist-pos}'
|
||||
}
|
||||
|
||||
# Move track on playlist
|
||||
#
|
||||
# @argument $1: track index 1
|
||||
# @argument $2: track index 2
|
||||
#
|
||||
# Moves the track at the first index to the position of the track of the second
|
||||
# index. Also here, indices are 0 based.
|
||||
mpv_playlist_move() {
|
||||
__mpv_command_with_args2 "playlist-move" "$1" "$2" >>/tmp/foo
|
||||
}
|
||||
|
||||
# Remove all tracks from the playlist
|
||||
mpv_playlist_clear() {
|
||||
__mpv_command "playlist-clear"
|
||||
}
|
||||
|
||||
# Randomly shuffle the order of the tracks in the playlist
|
||||
mpv_playlist_shuffle() {
|
||||
__mpv_command "playlist-shuffle"
|
||||
}
|
||||
|
||||
# Revert a previously shuffle command
|
||||
#
|
||||
# This method works only for a first shuffle.
|
||||
mpv_playlist_unshuffle() {
|
||||
__mpv_command "playlist-unshuffle"
|
||||
}
|
||||
|
||||
# Quit the mpv instance bound to the socket `MPV_SOCKET`
|
||||
mpv_quit() {
|
||||
__mpv_command "quit"
|
||||
}
|
||||
|
||||
# Start an mpv instance and bind it to the socket `MPV_SOCKET`
|
||||
mpv_start() {
|
||||
MPV_SOCKET="$(mktemp --suffix=.sock)"
|
||||
trap 'mpv_quit >/dev/null; rm -f "$MPV_SOCKET"' EXIT INT
|
||||
$MPV --no-config --no-terminal --input-ipc-server="$MPV_SOCKET" --idle --no-osc --no-input-default-bindings &
|
||||
}
|
||||
|
||||
# Play the track at the specified index in the playlist
|
||||
#
|
||||
# @argument $1: index (0 based)
|
||||
mpv_play_index() {
|
||||
__mpv_command_with_arg "playlist-play-index" "$1"
|
||||
}
|
||||
|
||||
# Remove the track at the specified index from the playlist
|
||||
#
|
||||
# @argument $1: index (0 based)
|
||||
mpv_rm_index() {
|
||||
__mpv_command_with_arg "playlist-remove" "$1"
|
||||
}
|
||||
|
||||
# Load the playlist with the specified list, and start playing
|
||||
#
|
||||
# This method reads from stdin a playlist file, e.g., a .m3u file.
|
||||
mpv_play_list() {
|
||||
t=$(mktemp)
|
||||
cat >"$t"
|
||||
debug "Playing $(cat "$t")"
|
||||
__mpv_command_with_arg "loadlist" "$t"
|
||||
rm -f "$t"
|
||||
}
|
||||
|
||||
# Append the playlist with the specified list, and start playing
|
||||
#
|
||||
# This method reads from stdin a playlist file, e.g., a .m3u file.
|
||||
mpv_queue_list() {
|
||||
t=$(mktemp)
|
||||
cat >"$t"
|
||||
@@ -47,22 +116,47 @@ mpv_queue_list() {
|
||||
rm -f "$t"
|
||||
}
|
||||
|
||||
# Insert the playlist with the specified list as the next item, and start
|
||||
# playing
|
||||
#
|
||||
# This method reads from stdin a playlist file, e.g., a .m3u file.
|
||||
mpv_queue_next_list() {
|
||||
t=$(mktemp)
|
||||
cat >"$t"
|
||||
pos=$(mpv_playlist_position)
|
||||
cnt1=$(mpv_playlist_count)
|
||||
__mpv_command_with_args2 "loadlist" "$t" "append-play"
|
||||
rm -f "$t"
|
||||
cnt2=$(mpv_playlist_count)
|
||||
diff=$((cnt2 - cnt1))
|
||||
[ "$diff" -gt 0 ] || return
|
||||
# Move added items right after current item (numbers are 0 based)
|
||||
for i in $(seq "$diff"); do
|
||||
mpv_playlist_move $((cnt1 + i - 1)) $((pos + i))
|
||||
done
|
||||
}
|
||||
|
||||
# Play next track on playlist
|
||||
mpv_next() {
|
||||
__mpv_command "playlist-next"
|
||||
}
|
||||
|
||||
# Play previous track on playlist
|
||||
mpv_prev() {
|
||||
__mpv_command "playlist-prev"
|
||||
}
|
||||
|
||||
# Seek forward by 10 seconds
|
||||
mpv_seek_forward() {
|
||||
__mpv_command_with_arg "seek" "10"
|
||||
}
|
||||
|
||||
# Seek backward by 10 seconds
|
||||
mpv_seek_backward() {
|
||||
__mpv_command_with_arg "seek" "-10"
|
||||
}
|
||||
|
||||
# Pause if mpv plays, and play if it is paused
|
||||
mpv_toggle_pause() {
|
||||
__mpv_command_with_arg "cycle" "pause"
|
||||
}
|
||||
|
138
src/sh/playback.sh
Normal file
138
src/sh/playback.sh
Normal file
@@ -0,0 +1,138 @@
|
||||
# Playback tools and helper
|
||||
#
|
||||
# The methods to control the mpv instance are in `src/sh/mpv.sh`. Here,
|
||||
# a higher-level playback functionality is provided.
|
||||
|
||||
# Available playback commands
|
||||
if [ ! "${PLAYBACK_LOADED:-}" ]; then
|
||||
PLAYBACK_CMD_PLAY="play"
|
||||
PLAYBACK_CMD_QUEUE="queue"
|
||||
PLAYBACK_CMD_QUEUE_NEXT="queue-next"
|
||||
PLAYBACK_CMD_TOGGLE_PLAYBACK="toggle"
|
||||
PLAYBACK_CMD_PLAY_NEXT="next"
|
||||
PLAYBACK_CMD_PLAY_PREV="prev"
|
||||
PLAYBACK_CMD_SEEK_FORWARD="seekf"
|
||||
PLAYBACK_CMD_SEEK_BACKWARD="seekb"
|
||||
export PLAYBACK_CMD_PLAY PLAYBACK_CMD_QUEUE PLAYBACK_CMD_QUEUE_NEXT \
|
||||
PLAYBACK_CMD_TOGGLE_PLAYBACK PLAYBACK_CMD_PLAY_NEXT \
|
||||
PLAYBACK_CMD_PLAY_PREV PLAYBACK_CMD_SEEK_FORWARD PLAYBACK_CMD_SEEK_BACKWARD
|
||||
|
||||
export PLAYBACK_LOADED=1
|
||||
fi
|
||||
|
||||
# Obtain playback command from key press
|
||||
#
|
||||
# @argument $1: key
|
||||
__playback_cmd_from_key() {
|
||||
key=$1
|
||||
case ",$KEYS_PLAY," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY" && return ;; esac
|
||||
case ",$KEYS_N_PLAY," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY" && return ;; esac
|
||||
case ",$KEYS_QUEUE," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE" && return ;; esac
|
||||
case ",$KEYS_N_QUEUE," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE" && return ;; esac
|
||||
case ",$KEYS_QUEUE_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE_NEXT" && return ;; esac
|
||||
case ",$KEYS_N_QUEUE_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_QUEUE_NEXT" && return ;; esac
|
||||
case ",$KEYS_TOGGLE_PLAYBACK," in *",$key,"*) echo "$PLAYBACK_CMD_TOGGLE_PLAYBACK" && return ;; esac
|
||||
case ",$KEYS_N_TOGGLE_PLAYBACK," in *",$key,"*) echo "$PLAYBACK_CMD_TOGGLE_PLAYBACK" && return ;; esac
|
||||
case ",$KEYS_PLAY_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_NEXT" && return ;; esac
|
||||
case ",$KEYS_N_PLAY_NEXT," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_NEXT" && return ;; esac
|
||||
case ",$KEYS_PLAY_PREV," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_PREV" && return ;; esac
|
||||
case ",$KEYS_N_PLAY_PREV," in *",$key,"*) echo "$PLAYBACK_CMD_PLAY_PREV" && return ;; esac
|
||||
case ",$KEYS_SEEK_FORWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_FORWARD" && return ;; esac
|
||||
case ",$KEYS_N_SEEK_FORWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_FORWARD" && return ;; esac
|
||||
case ",$KEYS_SEEK_BACKWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_BACKWARD" && return ;; esac
|
||||
case ",$KEYS_N_SEEK_BACKWARD," in *",$key,"*) echo "$PLAYBACK_CMD_SEEK_BACKWARD" && return ;; esac
|
||||
}
|
||||
|
||||
# Generate playlist from MB release ID and path to decoration
|
||||
#
|
||||
# @argument $1: MusicBrainz release ID
|
||||
# @argument $2: Path to decoration file
|
||||
# @argument $3: MusicBrainz track ID to select (optional)
|
||||
__generate_playlist() {
|
||||
printf "#EXTM3U\n"
|
||||
dir="$(dirname "$2")"
|
||||
mb_release "$1" |
|
||||
$JQ \
|
||||
--slurpfile decofile "$2" \
|
||||
--arg base "$dir" \
|
||||
--arg deco "$2" \
|
||||
--arg tid "${3:-}" \
|
||||
'$decofile[].tracks as $filenames |
|
||||
. |
|
||||
.id as $rid |
|
||||
.media[] |
|
||||
.position as $pos |
|
||||
.tracks |
|
||||
if ($tid == "") then . else map(select(.id == $tid)) end |
|
||||
map({
|
||||
t: [
|
||||
$rid,
|
||||
.id,
|
||||
$pos,
|
||||
.number,
|
||||
.length,
|
||||
.title,
|
||||
(."artist-credit" | map([.name, .joinphrase] | join("")) | join("")),
|
||||
$deco
|
||||
] | join("\t"),
|
||||
length: (.length // 0 / 1000 | round | tostring),
|
||||
$pos,
|
||||
number: .number,
|
||||
file: $filenames[.id]
|
||||
}) |
|
||||
map(if(.number | type == "string" and test("^[0-9]+$")) then .number |= tonumber else . end) |
|
||||
sort_by([.pos, .number]) |
|
||||
map("#EXTINF:" + .length + "," + .t + "\n" + $base + "/" + .file)[]'
|
||||
}
|
||||
|
||||
# Main playback method
|
||||
#
|
||||
# @argument $1: view
|
||||
# @argument $2: MusicBrainz ID of current object
|
||||
# @argument $3: MusicBrainz ID of selected object
|
||||
# @argument $4: Path to decoration file
|
||||
#
|
||||
# This option controls the mpv instance via a key pressed in fzf. The key
|
||||
# pressed is stored in the environment variable FZF_KEY and is resolved to
|
||||
# the playback command through the method `__playback_cmd_from_key`.
|
||||
playback() {
|
||||
view=${1:-}
|
||||
mbid_current="${2:-}"
|
||||
mbid="${3:-}"
|
||||
path="${4:-}"
|
||||
pbcmd=$(__playback_cmd_from_key "$FZF_KEY")
|
||||
case "$pbcmd" in
|
||||
"$PLAYBACK_CMD_PLAY")
|
||||
[ "$path" ] || exit 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") info "not implemented" ;;
|
||||
"$VIEW_RELEASEGROUP") __generate_playlist "$mbid" "$path" | mpv_play_list >/dev/null ;;
|
||||
"$VIEW_RELEASE") __generate_playlist "$mbid_current" "$path" "$mbid" | mpv_play_list >/dev/null ;;
|
||||
"$VIEW_PLAYLIST") mpv_play_index $((FZF_POS - 1)) >/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
"$PLAYBACK_CMD_QUEUE")
|
||||
[ "$path" ] || exit 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") info "not implemented" ;;
|
||||
"$VIEW_RELEASEGROUP") __generate_playlist "$mbid" "$path" | mpv_queue_list >/dev/null ;;
|
||||
"$VIEW_RELEASE") __generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_list >/dev/null ;;
|
||||
"$VIEW_PLAYLIST") __generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_list >/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
"$PLAYBACK_CMD_QUEUE_NEXT")
|
||||
[ "$path" ] || exit 0
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_SEARCH_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") info "not implemented" ;;
|
||||
"$VIEW_RELEASEGROUP") __generate_playlist "$mbid" "$path" | mpv_queue_next_list >/dev/null ;;
|
||||
"$VIEW_RELEASE") __generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_next_list >/dev/null ;;
|
||||
"$VIEW_PLAYLIST") __generate_playlist "$mbid_current" "$path" "$mbid" | mpv_queue_next_list >/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
"$PLAYBACK_CMD_TOGGLE_PLAYBACK") mpv_toggle_pause ;;
|
||||
"$PLAYBACK_CMD_PLAY_NEXT") mpv_next ;;
|
||||
"$PLAYBACK_CMD_PLAY_PREV") mpv_prev ;;
|
||||
"$PLAYBACK_CMD_SEEK_FORWARD") mpv_seek_forward ;;
|
||||
"$PLAYBACK_CMD_SEEK_BACKWARD") mpv_seek_backward ;;
|
||||
esac
|
||||
}
|
47
src/sh/playlist.sh
Normal file
47
src/sh/playlist.sh
Normal file
@@ -0,0 +1,47 @@
|
||||
# Playlist manipulation
|
||||
#
|
||||
# This files provides an interface to manipulate the playlist. The available
|
||||
# commands are defined in the following variables.
|
||||
if [ ! "${PLAYLIST_LOADED:-}" ]; then
|
||||
PLAYLIST_CMD_REMOVE="rm"
|
||||
PLAYLIST_CMD_UP="up"
|
||||
PLAYLIST_CMD_DOWN="down"
|
||||
PLAYLIST_CMD_CLEAR="clear"
|
||||
PLAYLIST_CMD_CLEAR_ABOVE="clear-above"
|
||||
PLAYLIST_CMD_CLEAR_BELOW="clear-below"
|
||||
PLAYLIST_CMD_SHUFFLE="shuffle"
|
||||
PLAYLIST_CMD_UNSHUFFLE="unshuffle"
|
||||
export PLAYLIST_CMD_REMOVE PLAYLIST_CMD_UP PLAYLIST_CMD_DOWN \
|
||||
PLAYLIST_CMD_CLEAR PLAYLIST_CMD_CLEAR_ABOVE PLAYLIST_CMD_CLEAR_BELOW \
|
||||
PLAYLIST_CMD_SHUFFLE PLAYLIST_CMD_UNSHUFFLE
|
||||
|
||||
export PLAYLIST_LOADED=1
|
||||
fi
|
||||
|
||||
# Run playback commands
|
||||
#
|
||||
# @argument $1: playlist command
|
||||
#
|
||||
# This is a wrapper to execute mpv commands.
|
||||
playlist() {
|
||||
case "$1" in
|
||||
"$PLAYLIST_CMD_REMOVE") mpv_rm_index $((FZF_POS - 1)) ;;
|
||||
"$PLAYLIST_CMD_UP") mpv_playlist_move $((FZF_POS - 1)) $((FZF_POS - 2)) ;;
|
||||
"$PLAYLIST_CMD_DOWN") mpv_playlist_move $((FZF_POS - 0)) $((FZF_POS - 1)) ;;
|
||||
"$PLAYLIST_CMD_CLEAR") mpv_playlist_clear ;;
|
||||
"$PLAYLIST_CMD_CLEAR_ABOVE")
|
||||
for _ in $(seq "$FZF_POS"); do
|
||||
mpv_rm_index 0
|
||||
done
|
||||
;;
|
||||
"$PLAYLIST_CMD_CLEAR_BELOW")
|
||||
cnt=$(mpv_playlist_count)
|
||||
rem=$((cnt - FZF_POS + 1))
|
||||
for _ in $(seq "$rem"); do
|
||||
mpv_rm_index $((FZF_POS - 1))
|
||||
done
|
||||
;;
|
||||
"$PLAYLIST_CMD_SHUFFLE") mpv_playlist_shuffle ;;
|
||||
"$PLAYLIST_CMD_UNSHUFFLE") mpv_playlist_unshuffle ;;
|
||||
esac
|
||||
}
|
@@ -1,18 +1,27 @@
|
||||
# Preview methods
|
||||
#
|
||||
# For now, only artist previews are supported.
|
||||
|
||||
# This internal method reshapes the text to be shown in the preview. This
|
||||
# creates a border on both horizontal ends.
|
||||
#
|
||||
# The text is read from stdin.
|
||||
__shape() {
|
||||
cat | tr -d '\r' | fold -s -w "$((FZF_PREVIEW_COLUMNS - 4))" | awk '{print " "$0" "}'
|
||||
}
|
||||
|
||||
# Print preview of artist
|
||||
# @input $1: MusicBrainz Artist ID
|
||||
__preview_artist() {
|
||||
desc=$(mb_artist_enwikipedia "$1" | $JQ -r '.extract' | __shape)
|
||||
[ "$desc" ] || desc=$(mb_artist_discogs "$1" | $JQ -r '.profile' | sed 's/\[a=\([^]]*\)\]/\1/g' | __shape)
|
||||
if [ "$(mb_artist "$1" | $JQ -r '.type')" = "Person" ]; then
|
||||
#
|
||||
# @input $1: MusicBrainz artist ID
|
||||
preview_artist() {
|
||||
desc=$(mb_artist_enwikipedia "$1" | $JQ '.extract' | __shape)
|
||||
[ "$desc" ] || desc=$(mb_artist_discogs "$1" | $JQ '.profile' | sed 's/\[a=\([^]]*\)\]/\1/g' | __shape)
|
||||
if [ "$(mb_artist "$1" | $JQ '.type')" = "Person" ]; then
|
||||
# Show birth place and death place of person
|
||||
lsb=$(mb_artist "$1" | $JQ -r '."life-span".begin // ""' | head -c 4)
|
||||
lse=$(mb_artist "$1" | $JQ -r '."life-span".end // ""' | head -c 4)
|
||||
ab=$(mb_artist "$1" | $JQ -r '."begin-area".name // ""')
|
||||
ae=$(mb_artist "$1" | $JQ -r '."end-area".name // ""')
|
||||
lsb=$(mb_artist "$1" | $JQ '."life-span".begin // ""' | head -c 4)
|
||||
lse=$(mb_artist "$1" | $JQ '."life-span".end // ""' | head -c 4)
|
||||
ab=$(mb_artist "$1" | $JQ '."begin-area".name // ""')
|
||||
ae=$(mb_artist "$1" | $JQ '."end-area".name // ""')
|
||||
if [ "$lsb" ] && [ "$ab" ]; then
|
||||
begin=$(printf "$APV_DATEPLACE" "$lsb" "$ab")
|
||||
elif [ "$lsb" ]; then
|
||||
@@ -37,3 +46,8 @@ __preview_artist() {
|
||||
#link=$(printf "More info:\033]8;;%s\033\\ %s\033]8;;\033\\" "https://musicbrainz.org/" "[MusicBrainz]")
|
||||
printf "$APV_FORMAT" "$desc" "${lifespan:-}"
|
||||
}
|
||||
|
||||
# Print message if there is nothing to be shown
|
||||
preview_nothing() {
|
||||
echo "No preview available."
|
||||
}
|
||||
|
160
src/sh/query.sh
Normal file
160
src/sh/query.sh
Normal file
@@ -0,0 +1,160 @@
|
||||
# The default queries depend on the current view, and are usually derived from
|
||||
# the theme. Nevertheless, they may be overwritten with the configuration file.
|
||||
# Note that filters are not used in the views VIEW_SEARCH_ARTIST and
|
||||
# VIEW_SEARCH_ALBUM. The reason for this is that in those modes, changing the
|
||||
# query string triggers a search on the MusicBrainz website (the input is not a
|
||||
# filter, but a query).
|
||||
#
|
||||
# The keybinding KEYS_FILTER_LOCAL triggers a filter of QUERY_LOCAL in the
|
||||
# views VIEW_ARTIST, VIEW_RELEASEGROUP, and VIEW_RELEASE only. Here, it is only
|
||||
# possible to adjust QUERY_LOCAL via the configuration. The keybinding KEYS_FILTER_0
|
||||
# resets the query. F_1_.. filters are the default filters when the respective
|
||||
# view is entered. For all other keys, the filters are individually
|
||||
# configurable, by specifying e.g., F_3_VIEW_LIST_ALBUMS.
|
||||
#
|
||||
# Derived queries
|
||||
# To derive the queries from the theme, we must perform some steps: 1) remove
|
||||
# colors, and 2) escape white spaces. This is implemented in the method
|
||||
# `__clean_filter`.
|
||||
#
|
||||
# List of derived queries:
|
||||
# - QUERY_LOCAL: Hide items that are not locally available
|
||||
# - q_has_secondary: Release groups with secondary types
|
||||
# - q_album: Release group is of type Album
|
||||
# - q_ep: Release group is of type EP
|
||||
# - q_single: Release group is of type single
|
||||
# - q_official: Release is official
|
||||
|
||||
# Clean a filter string
|
||||
#
|
||||
# This method reads from stdin a string and removes all colors and escapes
|
||||
# white spaces.
|
||||
__clean_filter() {
|
||||
cat | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g"
|
||||
}
|
||||
|
||||
# Determine preset query
|
||||
#
|
||||
# @argument $1: Current view
|
||||
# @argument $2: Key pressed (optional)
|
||||
#
|
||||
# If the key is not given, then the F_1_.. query is used for the respective
|
||||
# view, i.e, its as if a key from KEYS_FILTER_1 has been pressed.
|
||||
default_query() {
|
||||
view=$1
|
||||
key="${2:-"$(echo "$KEYS_FILTER_1" | cut -d ',' -f 1)"}"
|
||||
case ",$KEYS_FILTER_LOCAL," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST" | "$VIEW_RELEASEGROUP" | "$VIEW_RELEASE") echo "$QUERY_LOCAL" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_1," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_1_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_1_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_1_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_1_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_1_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_2," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_2_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_2_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_2_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_2_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_2_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_3," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_3_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_3_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_3_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_3_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_3_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_4," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_4_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_4_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_4_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_4_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_4_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_5," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_5_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_5_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_5_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_5_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_5_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_6," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_6_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_6_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_6_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_6_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_6_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_7," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_7_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_7_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_7_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_7_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_7_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_8," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_8_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_8_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_8_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_8_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_8_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case ",$KEYS_FILTER_9," in
|
||||
*",$key,"*)
|
||||
case "$view" in
|
||||
"$VIEW_ARTIST") echo "$F_9_VIEW_ARTIST" ;;
|
||||
"$VIEW_RELEASEGROUP") echo "$F_9_VIEW_RELEASEGROUP" ;;
|
||||
"$VIEW_RELEASE") echo "$F_9_VIEW_RELEASE" ;;
|
||||
"$VIEW_LIST_ARTISTS") echo "$F_9_LIST_ARTISTS" ;;
|
||||
"$VIEW_LIST_ALBUMS") echo "$F_9_LIST_ALBUMS" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
# Doing nothing is the same as this last block:
|
||||
# case ",$KEYS_FILTER_0," in
|
||||
# *",$key,"*)
|
||||
# case "$view" in
|
||||
# "$VIEW_ARTIST" | "$VIEW_RELEASEGROUP" | "$VIEW_RELEASE" | "$VIEW_LIST_ARTISTS" | "$VIEW_LIST_ALBUMS") echo "" ;;
|
||||
# esac
|
||||
# ;;
|
||||
# esac
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
# Update state
|
||||
# @argument $1: view
|
||||
# @argument $2: mode
|
||||
# @argument $3: arguments
|
||||
state_update() {
|
||||
mv "$STATEFILE" "$STATEFILE_LAST"
|
||||
mv "$ARGSFILE" "$ARGSFILE_LAST"
|
||||
printf "%s#%s" "${1:-}" "${2:-}" >"$STATEFILE"
|
||||
printf "%s" "${3:-}" >"$ARGSFILE"
|
||||
}
|
||||
|
||||
# Initialize state
|
||||
# @argument $1: view
|
||||
# @argument $2: mode
|
||||
# @argument $3: arguments
|
||||
state_init() {
|
||||
state_update "$1" "$2" "$3"
|
||||
state_update "$1" "$2" "$3"
|
||||
}
|
||||
|
||||
# Update state and keep arguments
|
||||
# @argument $1: view
|
||||
# @argument $2: mode
|
||||
state_update_keep_args() {
|
||||
mv "$STATEFILE" "$STATEFILE_LAST"
|
||||
cp "$ARGSFILE" "$ARGSFILE_LAST"
|
||||
printf "%s#%s" "${1:-}" "${2:-}" >"$STATEFILE"
|
||||
}
|
||||
|
||||
# Go back to previous state
|
||||
state_revert() {
|
||||
cp "$STATEFILE_LAST" "$STATEFILE"
|
||||
cp "$ARGSFILE_LAST" "$ARGSFILE"
|
||||
}
|
||||
|
||||
# Get view
|
||||
state_get_view() {
|
||||
cut -d "#" -f 1 "$STATEFILE"
|
||||
}
|
||||
|
||||
# Get mode
|
||||
state_get_mode() {
|
||||
cut -d "#" -f 2 "$STATEFILE"
|
||||
}
|
||||
|
||||
# Get args
|
||||
state_get_args() {
|
||||
cat "$ARGSFILE"
|
||||
}
|
@@ -6,15 +6,19 @@
|
||||
|
||||
# Colors (internal only)
|
||||
ESC=$(printf '\033')
|
||||
BOLD="${ESC}[1m"
|
||||
FAINT="${ESC}[2m"
|
||||
UNDERLINE="${ESC}[4m"
|
||||
CARTIST="${ESC}[38;5;209m"
|
||||
CTITLE="${ESC}[38;5;229m"
|
||||
CRELINFO="${ESC}[38;5;179m"
|
||||
CYEAR="${ESC}[38;5;179m"
|
||||
CDISAMB="$FAINT${ESC}[38;5;172m"
|
||||
CNOTE="${ESC}[38;5;242m"
|
||||
CXXX="${ESC}[38;5;109m"
|
||||
CDESC="${ESC}[38;5;254m"
|
||||
CLIFE="${ESC}[38;5;251m"
|
||||
CKB="${ESC}[38;5;224m"
|
||||
OFF="${ESC}[m"
|
||||
|
||||
# Pointers
|
||||
@@ -23,23 +27,26 @@ OFF="${ESC}[m"
|
||||
FORMAT_LOCAL="${FORMAT_LOCAL:-"🔆"}"
|
||||
# Pointer to the track currently playing (playlist)
|
||||
FORMAT_CURRENT="${FORMAT_CURRENT:-"👉"}"
|
||||
export FORMAT_LOCAL FORMAT_CURRENT
|
||||
|
||||
# Input prompts
|
||||
# Input prompt
|
||||
# =============
|
||||
# General search prompt
|
||||
# Search prompt
|
||||
SEARCH_PROMPT=${SEARCH_PROMPT:-"🔎 〉"}
|
||||
# Prompt that takes an artist name as argument
|
||||
ARTIST_PROMPT="${ARTIST_PROMPT:-"🎤 ${CARTIST}%s$OFF 〉"}"
|
||||
# Prompt that takes an artist name and a release name as arguments (in that
|
||||
# order)
|
||||
FULL_PROMPT="${FULL_PROMPT:-"🎤 ${CARTIST}%s$OFF 》${CTITLE}%s$OFF 〉"}"
|
||||
export SEARCH_PROMPT
|
||||
|
||||
# Visual representation of current mode
|
||||
# =====================================
|
||||
# Sign to indicate `normal` mode
|
||||
PROMPT_NORMAL="${PROMPT_NORMAL:-"${FAINT}[n]${OFF}"}"
|
||||
# Sign to indicate `insert` mode
|
||||
PROMPT_INSERT="${PROMPT_INSERT:-"${FAINT}[i]${OFF}"}"
|
||||
# Headers
|
||||
# =======
|
||||
# Header that displays artist's name
|
||||
HEADER_ARTIST="${HEADER_ARTIST:-"🎤 ${CARTIST}%s$OFF 〉"}"
|
||||
# Header that displays the release-group name after artist's
|
||||
HEADER_ARTIST_RELEASEGROUP="${HEADER_ARTIST_RELEASEGROUP:-"🎤 ${CARTIST}%s$OFF 》${CTITLE}%s$OFF 〉"}"
|
||||
# Header that in addition to `HEADER_ARTIST_RELEASEGROUP` also shows some
|
||||
# release information
|
||||
HEADER_RELEASE="${HEADER_RELEASE:-"🎤 ${CARTIST}%s$OFF 》${CTITLE}%s$OFF 〉%s"}"
|
||||
# The release information is formatted as follows (placeholders implicit):
|
||||
HEADER_RELEASE_FORMAT="${HEADER_RELEASE_FORMAT:-"${CRELINFO}<<tracks>> tx <<media>> $OFF|$CRELINFO <<label>> <<country>> <<year>>$OFF"}"
|
||||
export HEADER_ARTIST HEADER_ARTIST_RELEASEGROUP HEADER_RELEASE HEADER_RELEASE_FORMAT
|
||||
|
||||
# Artist view
|
||||
# ===========
|
||||
@@ -49,6 +56,7 @@ AV_PERSON="${AV_PERSON:-"🧑🎤 $CARTIST<<name>>$OFF"}"
|
||||
AV_GROUP="${AV_GROUP:-"🧑🤝🧑 $CARTIST<<name>>$OFF"}"
|
||||
# Artist disambiguation string
|
||||
AV_DISAMBIGUATION="${AV_DISAMBIGUATION:-"$CDISAMB(<<disambiguation>>)$OFF"}"
|
||||
export AV_PERSON AV_GROUP AV_DISAMBIGUATION
|
||||
|
||||
# Release-group view
|
||||
# ==================
|
||||
@@ -58,6 +66,7 @@ RGV_RELEASE="${RGV_RELEASE:-"${CTITLE}<<title>>$OFF"}"
|
||||
RGV_RELEASE_W_ARTIST="${RGV_RELEASE_W_ARTIST:-"${CTITLE}<<title>>$OFF — ${CARTIST}<<artist>>$OFF"}"
|
||||
# Year of the release group
|
||||
RGV_YEAR="${RGV_YEAR:-"${CYEAR}(<<year>>)$OFF"}"
|
||||
export RGV_RELEASE RGV_RELEASE_W_ARTIST RGV_YEAR
|
||||
|
||||
# Release-group types
|
||||
# ===================
|
||||
@@ -88,6 +97,15 @@ FORMAT_TYPE_SECONDARY_DJMIX="${FORMAT_TYPE_SECONDARY_DJMIX:-"🪩 DJ-mix"}"
|
||||
FORMAT_TYPE_SECONDARY_MIXTAPE="${FORMAT_TYPE_SECONDARY_MIXTAPE:-"📼 mixtape"}"
|
||||
FORMAT_TYPE_SECONDARY_DEMO="${FORMAT_TYPE_SECONDARY_DEMO:-"🧪 demo"}"
|
||||
FORMAT_TYPE_SECONDARY_FIELDREC="${FORMAT_TYPE_SECONDARY_FIELDREC:-"🌿 field recording"}"
|
||||
export FORMAT_TYPE_ALBUM FORMAT_TYPE_EP FORMAT_TYPE_SINGLE \
|
||||
FORMAT_TYPE_BROADCAST FORMAT_TYPE_OTHER FORMAT_TYPE_HAS_SECONDARY \
|
||||
FORMAT_TYPE_SECONDARY FORMAT_TYPE_SECONDARY_COMPILATION \
|
||||
FORMAT_TYPE_SECONDARY_SOUNDTRACK FORMAT_TYPE_SECONDARY_SPOKENWORD \
|
||||
FORMAT_TYPE_SECONDARY_INTERVIEW FORMAT_TYPE_SECONDARY_AUDIOBOOK \
|
||||
FORMAT_TYPE_SECONDARY_AUDIODRAMA FORMAT_TYPE_SECONDARY_LIVE \
|
||||
FORMAT_TYPE_SECONDARY_REMIX FORMAT_TYPE_SECONDARY_DJMIX \
|
||||
FORMAT_TYPE_SECONDARY_MIXTAPE FORMAT_TYPE_SECONDARY_DEMO \
|
||||
FORMAT_TYPE_SECONDARY_FIELDREC
|
||||
|
||||
# Artist Preview
|
||||
# ==============
|
||||
@@ -104,6 +122,7 @@ APV_DATEPLACE="${APV_DATEPLACE:-"$APV_DATE, $APV_PLACE"}"
|
||||
APV_BORN="${APV_BORN:-"🍼 Born: %s"}"
|
||||
# String to represent when/where a person died
|
||||
APV_DIED="${APV_DIED:-"🕯️ Died: %s"}"
|
||||
export APV_FORMAT APV_DATE APV_PLACE APV_DATEPLACE APV_BORN APV_DIED
|
||||
|
||||
# Release view
|
||||
# ============
|
||||
@@ -115,6 +134,7 @@ RV_TITLE_ARTIST="${RV_TITLE_ARTIST:-"${FAINT}as ${CTITLE}<<title>>$OFF by ${FAIN
|
||||
RV_TITLE="${RV_TITLE:-"${FAINT}as ${CTITLE}<<title>>$OFF"}"
|
||||
# Additional string to display the artist
|
||||
RV_ARTIST="${RV_ARTIST:-"${FAINT}by ${CARTIST}<<artist>>$OFF"}"
|
||||
export RV_FORMAT RV_TITLE_ARTIST RV_TITLE RV_ARTIST
|
||||
|
||||
# Release Status
|
||||
# ==============
|
||||
@@ -125,6 +145,9 @@ FORMAT_STATUS_PSEUDO="${FORMAT_STATUS_PSEUDO:-"🌀"}"
|
||||
FORMAT_STATUS_WITHDRAWN="${FORMAT_STATUS_WITHDRAWN:-"🔙"}"
|
||||
FORMAT_STATUS_EXPUNGED="${FORMAT_STATUS_EXPUNGED:-"🧹"}"
|
||||
FORMAT_STATUS_CANCELLED="${FORMAT_STATUS_CANCELLED:-"❌"}"
|
||||
export FORMAT_STATUS_OFFICIAL FORMAT_STATUS_PROMO FORMAT_STATUS_BOOTLEG \
|
||||
FORMAT_STATUS_PSEUDO FORMAT_STATUS_WITHDRAWN FORMAT_STATUS_EXPUNGED \
|
||||
FORMAT_STATUS_CANCELLED
|
||||
|
||||
# Recording view
|
||||
# ==============
|
||||
@@ -132,21 +155,14 @@ FORMAT_STATUS_CANCELLED="${FORMAT_STATUS_CANCELLED:-"❌"}"
|
||||
REC_FORMAT="${REC_FORMAT:-"${CNOTE}${FAINT}<<med>>\t${CNOTE}<<nr>>$OFF\t${CTITLE}<<title>>\t${CARTIST}<<artist>>\t${CXXX}<<duration>>$OFF"}"
|
||||
# Format of a track in the playlist
|
||||
REC_FORMAT_NO_NUMBER="${REC_FORMAT_NO_NUMBER:-"${CTITLE}<<title>>\t${CARTIST}<<artist>>\t${CXXX}<<duration>>$OFF"}"
|
||||
export REC_FORMAT REC_FORMAT_NO_NUMBER
|
||||
|
||||
# Derivatives
|
||||
# ===========
|
||||
QUERY_LOCAL=$(printf "%s" "$FORMAT_LOCAL" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_HAS_SECONDARY=$(printf "$FORMAT_TYPE_HAS_SECONDARY" "" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_ALBUM=$(printf "%s" "$FORMAT_TYPE_ALBUM" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_EP=$(printf "%s" "$FORMAT_TYPE_EP" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_SINGLE=$(printf "%s" "$FORMAT_TYPE_SINGLE" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_BROADCAST=$(printf "%s" "$FORMAT_TYPE_BROADCAST" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
QUERY_OTHER=$(printf "%s" "$FORMAT_TYPE_OTHER" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
if printf "$RV_FORMAT" | grep -q "<<status>>"; then
|
||||
QUERY_RV=$(printf "%s" "$FORMAT_STATUS_OFFICIAL" | sed "s/${ESC}\[[0-9;]*[mK]//g" | sed "s/ /\\\ /g")
|
||||
else
|
||||
QUERY_RV=""
|
||||
fi
|
||||
|
||||
# Necessary exports
|
||||
export QUERY_LOCAL QUERY_HAS_SECONDARY QUERY_ALBUM QUERY_EP QUERY_SINGLE QUERY_BROADCAST QUERY_OTHER QUERY_RV
|
||||
# Keybinding themes
|
||||
# =================
|
||||
# Format keybinding group
|
||||
KBF_GROUP="${KBF_GROUP:-"${UNDERLINE}${CKB}%s$OFF"}"
|
||||
# Format key
|
||||
KBF_KEY="${KBF_KEY:-"${BOLD}${CKB}%s$OFF"}"
|
||||
# Format description
|
||||
KBF_DESC="${KBF_DESC:-"${CKB}%s$OFF"}"
|
||||
export KBF_GROUP KBF_KEY KBF_DESC
|
||||
|
@@ -1,3 +1,14 @@
|
||||
# Load the tools required for this application. The tools are preset with
|
||||
# default command-line arguments.
|
||||
#
|
||||
# List of tools:
|
||||
# - fzf: in order to display, search, and navigate lists
|
||||
# - curl: for API access
|
||||
# - jq: to parse json files
|
||||
# - mpv: music player
|
||||
# - socat: to communicate with the socket mpv is bound to
|
||||
# - xsel: to copy content to the clipboard (not necessary)
|
||||
if [ ! "${TOOLS_LOADED:-}" ]; then
|
||||
if command -v "fzf" >/dev/null; then
|
||||
FZF="fzf --black --ansi --cycle --tiebreak=chunk,index"
|
||||
else
|
||||
@@ -15,7 +26,7 @@ fi
|
||||
export CURL
|
||||
|
||||
if command -v "jq" >/dev/null; then
|
||||
JQ="jq"
|
||||
JQ="jq -r --compact-output"
|
||||
else
|
||||
err "Did not find jq."
|
||||
exit 1
|
||||
@@ -37,3 +48,9 @@ else
|
||||
exit 1
|
||||
fi
|
||||
export SOCAT
|
||||
|
||||
command -v "xsel" >/dev/null && CLIP="xsel" || CLIP="true"
|
||||
export CLIP
|
||||
|
||||
export TOOLS_LOADED=1
|
||||
fi
|
||||
|
Reference in New Issue
Block a user