Files
LastFM-NowPlaying/LastFM-NowPlaying.py
2026-02-01 13:43:45 +02:00

31 lines
1012 B
Python

from xml.dom import minidom
from urllib.request import urlopen
import sys
import time
import threading
userName = "karliyo"
#Public API Key for Accessing Last FM
apiKey = ("460cda35be2fbf4f28e8ea7a38580730")
#Global Variables
currentTrackURL = ('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&nowplaying="true"&user=' + str(userName) + '&api_key=' + str(apiKey))
noSongPlaying = ("Nothing Currently Playing ")
#Defines the funcions for use in different threads.
def checkForNewSong():
currentTrackXML = urlopen(currentTrackURL).read()
currentTrack = minidom.parseString(currentTrackXML)
songName = currentTrack.getElementsByTagName('name')
songArtist = currentTrack.getElementsByTagName('artist')
songInfo = songName[0].firstChild.nodeValue + " - " + songArtist[0].firstChild.nodeValue
print(songInfo)
#Closes the Application
sys.exit()
#Creates Threads for the two functions
newSongThread = threading.Thread(target=checkForNewSong)
newSongThread.start()