Created
June 11, 2019 13:56
-
-
Save bphermansson/80f4ba4638eddd818c233e70373ed73a to your computer and use it in GitHub Desktop.
This script fetches information from the VLC media player. For this to work VLC has to be started with it's http-server activated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
getVlcData.py | |
This script fetches information from the VLC media player. | |
For this to work VLC has to be started with it's http-server activated. | |
This can be done with a command line like this: | |
vlc --aout=alsa --alsa-audio-device="hw:0,0" --daemon --syslog -I http --http-port 8080 --http-password <password> | |
Where you select the password yourself. This password is then used below ("vlcpass"). You also need the ip and the port number | |
of the VLC-server. | |
(C) Patrik Hermansson | |
''' | |
import requests | |
from requests.auth import HTTPBasicAuth | |
import xml.etree.ElementTree as ET | |
url = "http://192.168.1.190:8080/requests/status.xml" | |
vlcpass = "<password>" | |
print ("Get data from " + url) | |
r = requests.get(url, auth=('', vlcpass)) | |
if (r.status_code == 200): | |
print "Request succeded" | |
else: | |
print "Request failed, check your settings" | |
# Uncomment to see whole answer from VLC: | |
#print (r.text) | |
tree = ET.fromstring(r.text) | |
# All track data: | |
# print ("Decoded data: ") | |
# for info in tree.findall('./information/category/info'): | |
# print (info.text) | |
# Playlist name | |
for station in tree.findall("./information/category/info/[@name='title']"): | |
print ("Playlist name: " + station.text) | |
# Artist & track | |
for track in tree.findall("./information/category/info/[@name='now_playing']"): | |
print ("Current track: " + track.text) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment