xxwhirlpool
·
2026-01-21
lastfm.sh
1#!/bin/bash
2
3USER="springpool"
4API_KEY=$(pass api/lastfm)
5
6URL="https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$USER&api_key=$API_KEY&format=json&limit=1"
7
8artist=$(curl -s ${URL} | jq -r '.recenttracks.track[0].artist."#text"')
9track=$(curl -s ${URL} | jq -r '.recenttracks.track[0].name')
10art=$(curl -s $URL | jq -r '.recenttracks.track[0].image[2]."#text"')
11
12tmp="/tmp"
13img_path="$tmp/lastfm-conky.png"
14
15getimg() {
16 if [ -n "$art" ]; then
17 if [[ "$art" = http* ]] || [[ "$art" = file:* ]]; then
18 curl -s "$art" -o "$img_path"
19 elif [ -f "$art" ]; then
20 cp "$art" "$img_path"
21 else
22 echo "something wrong with art"
23 exit 1
24 fi
25 fi
26}
27
28showimg() {
29 getimg
30 if [ -f "$img_path" ] && [ "$(wc -c "$img_path" | awk '{print $1}')" -gt 0 ]; then
31 echo "\${image $img_path -p 0,0 -s 125x125 -n}"
32 else
33 echo "\${image ./placeholder.png -p 0,0 -s 125x125}"
34 fi
35}
36
37if [ "$1" == "artist" ]; then
38 echo $artist
39elif [ "$1" == "track" ]; then
40 echo $track
41elif [ "$1" == "art" ]; then
42 showimg
43else
44 exit 1
45fi