Created
May 18, 2012 03:09
-
-
Save livibetter/2722912 to your computer and use it in GitHub Desktop.
Tracks recently obsessed with using Last.fm library
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 | |
# Written by Yu-Jie Lin | |
# Public Domain | |
# | |
# Check Last.fm library to see what recent tracks has been played consecutively | |
# for three times at least. | |
# | |
# Usage: obs.sh APIKEY USERNAME | |
if (( $# != 2 )); then | |
echo 'obs.sh APIKEY USERNAME' >&2 | |
exit 1 | |
fi | |
MIN_COUNT=3 | |
API_URL="http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$2&api_key=$1&limit=200" | |
cat <(wget -q -O - "$API_URL&page=1") \ | |
<(wget -q -O - "$API_URL&page=2") \ | |
<(wget -q -O - "$API_URL&page=3") \ | |
<(wget -q -O - "$API_URL&page=4") \ | |
<(wget -q -O - "$API_URL&page=5") | | |
sed -n '/url/ s/ *<url>\(.*\)<\/url>/\1/p' | | |
awk -v min_count=$MIN_COUNT ' | |
BEGIN { | |
url = ""; | |
count = 0; | |
} | |
{ | |
if (url == $0) { | |
count++; | |
} else { | |
// only show the url when more than min_count consecutive play | |
if (count > min_count) | |
printf("%3d %s\n", count, url); | |
url = $0; | |
count = 1; | |
} | |
} | |
END { | |
if (count > min_count) | |
printf("%3d %s\n", count, url); | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment