Repository navigation
Expand file tree
/
Copy pathphish-show-notes
More file actions
executable file
·238 lines (198 loc) · 6.27 KB
/
Copy pathphish-show-notes
File metadata and controls
executable file
·238 lines (198 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/env nix-shell
#!/usr/bin/env bash
#! nix-shell -i bash -p bash coreutils curl jq pandoc python3Packages.ftfy
# shellcheck shell=bash
# keep-sorted start skip_lines=1 prefix_order=type,,>,||
type \
curl \
fmt \
iconv \
jq \
pandoc \
phishin-auth-token \
>/dev/null \
|| exit 1
# keep-sorted end
set -euo pipefail
usage() {
# shellcheck disable=SC2059
[[ "$#" -eq 0 ]] || printf "$@" >&2
cat >&2 <<EOF
usage: ${0##*/} [-A] <show>
${0##*/} [-jt] <show>
Display notes for a Phish show, as provided by Phish.net. The output
is intended for human usage. It aims to mimic a common text style used
by the authors of "taper notes" that accompany fan-made recordings of
jam bands.
All data output by this program is courtesy of the Phish.net project,
with exception of taper notes provided by the Phish.in project.
options:
-A Use full names of songs only; disable abbreviations.
See <https://phish.net/abbr> for a guide.
-j Instead of displaying show notes, show Phish.net's
JSON data corresponding to <show>. (porcelain)
-t Output the taper notes for the show as corresponds
to Phish.in's recording.
<show> An ISO formatted date (ex. 1969-12-31).
environment variables:
\$NO_COLOR${NO_COLOR:+ (current: ${NO_COLOR@Q})}
If set, or if standard output is not a terminal, show notes will
not contain any ANSI escape codes (generated with \`pandoc -t
ansi\`). Instead, show notes will be converted to Markdown.
see also: the Phish.net project <https://phish.net>,
the Phish.in project <https://phish.in>.
Kylie McClain <kylie@somas.is>
EOF
[[ "$#" -eq 0 ]] || exit 1
exit 69
}
phishin_auth() {
local -
set +x
[[ -v PHISHIN_USER_TOKEN ]] || PHISHIN_USER_TOKEN=$(phishin-auth-token)
export PHISHIN_USER_TOKEN
}
phishnet_auth() {
local -
set +x
if [[ -z "${PHISHNET_SECRET:-}" ]] && [[ -n "${PHISHNET_SECRET_COMMAND:-}" ]]; then
PHISHNET_SECRET=$(eval "$PHISHNET_SECRET_COMMAND")
fi
: "${PHISHNET_SECRET:?no API secret for Phish.net provided in \$PHISHNET_SECRET or by \$PHISHNET_SECRET_COMMAND}"
export PHISHNET_SECRET
}
phishnet() {
phishnet_auth
command curl \
--no-progress-meter \
--user-agent 'phish-cli <kylie@somas.is>' \
--variable %PHISHNET_SECRET \
--expand-data apikey='{{PHISHNET_SECRET}}' \
"$@"
}
BASH_ARGV0="${0##*/}"
use_abbrev=true
mode=notes
while getopts :Ajt opt; do
case "$opt" in
A) use_abbrev=false ;;
j) mode=json ;;
t) mode=tapernotes ;;
?) usage '' ;;
esac
done
shift $((OPTIND - 1))
[[ "${1:-}" == --help ]] && usage
if [[ "$#" -ne 1 ]]; then
usage 'error: only one show argument allowed (%i provided)\n' "$#"
elif ! [[ "${1}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
usage 'error: show argument is not an ISO format date\n'
fi
if [[ "$mode" == 'tapernotes' ]]; then
phishin_auth
curl \
--fail-with-body \
--no-progress-meter \
--get \
--variable %PHISHIN_USER_TOKEN \
--expand-header 'X-Auth-Token: {{PHISHIN_USER_TOKEN}}' \
"https://phish.in/api/v2/shows/${1}" \
| jq -er .taper_notes
exit $?
fi
show_data=$(phishnet "https://api.phish.net/v5/shows/showdate/$1")
if [[ -z "$show_data" ]]; then
printf 'error: %s is not a valid Phish performance date\n' "$1" >&2
exit 1
fi
show_setlist_data=$(phishnet "https://api.phish.net/v5/setlists/showdate/$1")
# shellcheck disable=SC2016
jq_script='
.[1] as $show_setlist_data
| .[0].data[] | select(.artist_name == "Phish")
| {
show_data: tojson,
setlist_data: $show_setlist_data.data | tojson,
setlist_notes,
show_date: .showdate,
permalink,
tour_name,
show_venue: [
(.venue // ""),
(.city // ""),
(.state // ""),
(.country // "")
] | map(select(. != "")) | join(", ")
}
| .show_data = tojson
| to_entries
| map("\(.key)=\(.value|@sh)")[]
'
show_data_eval=$(
jq -rs "$jq_script" <<EOF
$show_data
$show_setlist_data
EOF
)
eval "$show_data_eval"
: "${show_data:?}"
: "${setlist_data:?}"
: "${setlist_notes?}"
: "${show_date:?}"
: "${permalink:?}"
: "${tour_name:?}"
: "${show_venue:?}"
if [[ "$mode" == 'json' ]]; then
jq '.show_data |= fromjson | .setlist_data |= fromjson' <<<"${show_data}"
exit $?
fi
# NOTE The use of ftfy here is because it seems that some show
# notes provided by Phish.net were improperly converted to UTF-8
# at some point in their processing. Thus, artifacts in text show
# up occasionally (see 1999-12-31 for a testcase).
if setlist_notes_fixed=$(ftfy -g <<<"$setlist_notes"); then
setlist_notes="${setlist_notes_fixed}"
fi
if show_venue_fixed=$(ftfy -g <<<"$show_venue"); then
show_venue="${show_venue_fixed}"
fi
printf 'Phish\n%s\n%s\n%s\n\n' "${show_date}" "${tour_name}" "${show_venue}"
mapfile -t show_sets < <(jq -r '[.[].set] | unique[]' <<<"$setlist_data")
for show_set in "${show_sets[@]}"; do
set_tracks=$(jq \
--argjson use_abbrev "$use_abbrev" \
--arg show_set "${show_set}" \
-r '
[(.[]|select((.set|tostring) == $show_set) | (
(if $use_abbrev == true then .nickname // .song else .song end)
| gsub("&"; "&")
), .trans_mark)] | join("")
' <<<"${setlist_data}")
case "${show_set}" in
e) show_set=Encore ;;
# additional encore; see 2018-10-21 for test case
e*) show_set="Encore ${show_set#e}" ;;
*) show_set="Set ${show_set}" ;;
esac
printf '%s: %s\n\n' "${show_set}" "${set_tracks}" | fmt -t
done
if [[ -n "$setlist_notes" ]]; then
pandoc_args=()
if [[ -v NO_COLOR ]] || [[ -t 1 ]]; then
pandoc_args+=(-t markdown-smart)
else
pandoc_args+=(-t ansi)
fi
setlist_notes=$(
pandoc \
-f html+smart \
"${pandoc_args[@]}" \
--columns 72 \
--wrap=auto \
<<<"$setlist_notes"
)
printf '%s\n\n' "${setlist_notes}"
fi
# TODO we could ought to print footnotes for songs,
# like Phish.net's own show overviews do...
printf '<%s>\n' "${permalink}"