Skip to content

Instantly share code, notes, and snippets.

@dece
Last active May 21, 2017 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dece/5008875d79976d89ede54016182836c8 to your computer and use it in GitHub Desktop.
Save dece/5008875d79976d89ede54016182836c8 to your computer and use it in GitHub Desktop.
NectarinePlaying - Output on stdout the current track song and artist on Nectarine
#!/usr/bin/env python3
""" Output on stdout the current track song and artist on Nectarine.
It's mainly useful if you work with terminals around and don't want to keep the
Nectarine tab under your eyes all the time (even if it's raina's design). Due to
its nature it can be used with conky, but as it requests the nectarine page at
each execution, it would be better if you use it with the ${execi} command and a
big interval (10 or 20 seconds). Respect their servers, and long live Nectarine!
"""
import sys
import urllib.request
import xml.etree.ElementTree as ElementTree
QUEUE_URL = "https://www.scenemusic.net/demovibes/xml/queue/"
def get_now_playing():
# Get the XML of the queue list
try:
queue_resp = urllib.request.urlopen(QUEUE_URL)
except urllib.request.URLError:
print("Failed to open", QUEUE_URL)
sys.exit(1)
# Parse it to get the currently playing song
xml_tree = ElementTree.parse(queue_resp)
xml_root = xml_tree.getroot()
now_playing_node = xml_root.find("now").find("entry")
# Get everything in there to print it at the end
now_playing = ""
# Get and format artists list
artists = []
for artist in now_playing_node.getiterator("artist"):
artists.append(artist.text)
for artist in artists[:-1]:
now_playing += artist + " & "
now_playing += artists[-1]
now_playing += " - "
# Get song
now_playing += now_playing_node.find("song").text
# Get requester
now_playing += " (req. by " + now_playing_node.find("requester").text + ")"
return now_playing
def main():
print(get_now_playing())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment