updated spotify_playlist_tracks_uri.sh

pull/2/head
Hari Sekhon 4 years ago
parent 72e19a3d02
commit 208c2d8226

@ -21,9 +21,8 @@ set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<playlist_id> [<curl_options>]"
# shellcheck disable=SC1090
. "$srcdir/lib/spotify.sh"
# shellcheck disable=SC2034
usage_description="
@ -46,8 +45,9 @@ Caveat: due to limitations of the Spotify API, this by default only works for pu
export SPOTIFY_ACCESS_TOKEN=\"\$(\"$srcdir/spotify_api_token_interactive.sh\")\"
"
# shellcheck disable=SC1090
. "$srcdir/lib/utils.sh"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="<playlist_id> [<curl_options>]"
help_usage "$@"
@ -59,16 +59,12 @@ if [ -z "$playlist_id" ]; then
usage "playlist id not defined"
fi
if [ -z "${SPOTIFY_ACCESS_TOKEN:-}" ]; then
SPOTIFY_ACCESS_TOKEN="$("$srcdir/spotify_api_token.sh")"
export SPOTIFY_ACCESS_TOKEN
fi
spotify_token
playlist_id="$("$srcdir/spotify_playlist_name_to_id.sh" "$playlist_id" "$@")"
offset="${SPOTIFY_OFFSET:-0}"
limit="${SPOTIFY_LIMIT:-50}"
# $limit/$offset defined in lib/spotify.sh
# shellcheck disable=SC2154
url_path="/v1/playlists/$playlist_id/tracks?limit=$limit&offset=$offset"
output(){
@ -76,25 +72,9 @@ output(){
jq -r '.items[] | select(.track.uri) | [.track.uri] | @tsv' <<< "$output"
}
get_next(){
jq -r '.next' <<< "$output"
}
has_next_url(){
[ -n "$url_path" ] && [ "$url_path" != null ]
}
has_jq_error(){
# shellcheck disable=SC2181
[ $? != 0 ] || [ "$(jq -r '.error' <<< "$output")" != null ]
}
while has_next_url; do
output="$("$srcdir/spotify_api.sh" "$url_path" "$@")"
if has_jq_error; then
echo "$output" >&2
exit 1
fi
exit_if_jq_error
url_path="$(get_next)"
output
done

Loading…
Cancel
Save