You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
Bash
81 lines
2.3 KiB
Bash
4 years ago
|
#!/usr/bin/env bash
|
||
|
# vim:ts=4:sts=4:sw=4:et
|
||
|
#
|
||
|
# args: test | tee /dev/stderr | spotify_uri_to_name.sh
|
||
|
#
|
||
|
# Author: Hari Sekhon
|
||
|
# Date: 2020-07-24 19:05:25 +0100 (Fri, 24 Jul 2020)
|
||
|
#
|
||
2 years ago
|
# https://github.com/HariSekhon/Spotify-Playlists
|
||
4 years ago
|
#
|
||
|
# License: see accompanying Hari Sekhon LICENSE file
|
||
|
#
|
||
|
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
|
||
|
#
|
||
2 years ago
|
# https://www.linkedin.com/in/HariSekhon
|
||
4 years ago
|
#
|
||
|
|
||
|
set -euo pipefail
|
||
|
[ -n "${DEBUG:-}" ] && set -x
|
||
|
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
||
1 year ago
|
# shellcheck disable=SC1090,SC1091
|
||
4 years ago
|
. "$srcdir/lib/spotify.sh"
|
||
|
|
||
|
# shellcheck disable=SC2034,SC2154
|
||
|
usage_description="
|
||
|
Lists duplicate Spotify URIs in a given playlist
|
||
|
|
||
|
Playlist must be specified as the first argument and can be either a Spotify playlist ID or a full playlist name (see spotify_playlists.sh)
|
||
|
|
||
4 years ago
|
You can combine this with spotify_uri_to_name.sh to see the duplicate track names eg. for a playlist called 'My Playlist':
|
||
4 years ago
|
|
||
4 years ago
|
${0##*/} 'My Playlist' | spotify_uri_to_name.sh
|
||
4 years ago
|
|
||
4 years ago
|
If \$SPOTIFY_DUPLICATE_TRACK_POSITIONS is set then also outputs the track position (zero-indexed to align with the Spotify API) as the first column with the URI as the second column
|
||
4 years ago
|
|
||
4 years ago
|
$usage_playlist_help
|
||
|
|
||
|
$usage_auth_help
|
||
|
"
|
||
|
|
||
|
# used by usage() in lib/utils.sh
|
||
|
# shellcheck disable=SC2034
|
||
|
usage_args="<playlist_name_or_id>"
|
||
|
|
||
|
help_usage "$@"
|
||
|
|
||
|
min_args 1 "$@"
|
||
|
|
||
|
playlist="$1"
|
||
|
shift || :
|
||
|
|
||
|
# requires authorized token
|
||
|
export SPOTIFY_PRIVATE=1
|
||
|
|
||
|
spotify_token
|
||
|
|
||
|
# this script returns the ID if it's already in the correct format, otherwise queries and returns the playlist ID for the playlist
|
||
|
playlist_id="$(SPOTIFY_PLAYLIST_EXACT_MATCH=1 "$srcdir/spotify_playlist_name_to_id.sh" "$playlist")"
|
||
|
|
||
|
# playlists max out at only around ~8000 tracks so this is safe to do in ram
|
||
|
tracklist_URIs="$("$srcdir/spotify_playlist_tracks_uri.sh" "$playlist_id")"
|
||
|
|
||
|
duplicate_URIs="$(sort <<< "$tracklist_URIs" | uniq -d)"
|
||
|
|
||
|
while read -r uri; do
|
||
|
[ -n "$uri" ] || continue
|
||
|
grep -Fxn "$uri" <<< "$tracklist_URIs" |
|
||
|
tail -n +2
|
||
|
done <<< "$duplicate_URIs" |
|
||
|
if [ -n "${SPOTIFY_DUPLICATE_TRACK_POSITIONS:-}" ]; then
|
||
|
sed 's/:/ /' |
|
||
4 years ago
|
while read -r track_position uri; do
|
||
|
((track_position-=1))
|
||
|
echo "$track_position $uri"
|
||
|
done |
|
||
4 years ago
|
column -t
|
||
|
else
|
||
4 years ago
|
sed 's/^[[:digit:]]*://'
|
||
4 years ago
|
fi
|