Updating the music display in statusbar

This commit is contained in:
Nemo 2017-01-30 16:15:11 +05:30
parent 757fdac685
commit 7eca894f8c
2 changed files with 23 additions and 2 deletions

View File

@ -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
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

12
get_current_track.py Normal file
View File

@ -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)