Skip to content

Instantly share code, notes, and snippets.

@deseven
Last active October 7, 2020 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deseven/c1b65fa68babf46337605290e5513371 to your computer and use it in GitHub Desktop.
Save deseven/c1b65fa68babf46337605290e5513371 to your computer and use it in GitHub Desktop.
A simple script that filters the list of artists by checking their last.fm playcount (written for TMS search)
#!/bin/bash
# insert your last.fm api key (can be obtained by creating an app here - https://www.last.fm/api/account/create)
# change output_file and artist_play_limit how you like
# you'll also need to install jq
# USAGE:
# cat artists.txt | ./tms-obscure-artists.sh
lastfm_api_key=""
artist_play_limit=10000
output_file="/Volumes/slow/Downloads/tms_obscure_artists"
while read line; do
artist=$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
regex="^.* \([0-9]{1,2}\)$" # detecting "Artist (number)" entries
if [[ "$artist" =~ $regex ]]; then
artist=$(echo "$artist" | rev | cut -f2- -d' ' | rev)
fi
echo "checking \"$artist\":"
artist_urlencoded=$(php -r "echo urlencode(\"$artist\");")
plays=$(curl -s "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=$artist_urlencoded&api_key=$lastfm_api_key&format=json" | jq -M -c -r '.artist.stats.playcount')
echo " - - - $plays"
if [ "$plays" != "null" ]; then
if [ "$plays" -gt "$artist_play_limit" ]; then
echo " - - - artist has more than $artist_play_limit plays, skipping..."
else
echo "$line" >> "$output_file"
fi
else
echo "$line" >> "$output_file"
fi
/bin/sleep 0.3 # last.fm api has a ratelimit
echo
done < "${1:-/dev/stdin}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment