Last active
October 7, 2020 01:22
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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