Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.