diff --git a/get-current-track.sh b/get-current-track.sh index 6a3757f..88bec79 100755 --- a/get-current-track.sh +++ b/get-current-track.sh @@ -1,3 +1,12 @@ -current_song="$HOME/.cmus/now-playing.txt" +# curl -s http://www.last.fm/user/captn3m0 > /tmp/lastfm.html -cat $current_song \ No newline at end of file +current_song="" +if [[ LASTFM_SONG="$(python get_current_track.py)" ]]; then + current_song="$HOME/.cmus/lastfm.txt" + echo $(/usr/bin/python get_current_track.py) > $current_song 2>&1 + # echo $(which python) > $current_song +else + current_song="$HOME/.cmus/now-playing.txt" +fi +cat $current_song +exit 0 \ No newline at end of file diff --git a/get_current_track.py b/get_current_track.py new file mode 100644 index 0000000..0379201 --- /dev/null +++ b/get_current_track.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from bs4 import BeautifulSoup +try: + with open('/tmp/lastfm.html', 'r') as myfile: + data = myfile.read() + soup = BeautifulSoup(data, 'html.parser') + chartlist = soup.find(class_="chartlist-now-scrobbling").parent.parent.find(class_='chartlist-name').get_text().strip().replace('\n', '') + print(chartlist) +except Exception as e: + print("FAILED") + exit(1)