mirror of
https://github.com/fergalmoran/dss.api.git
synced 2026-01-04 15:44:11 +00:00
Added metadata to radio
This commit is contained in:
45
core/radio/ice_scrobbler.py
Normal file
45
core/radio/ice_scrobbler.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from requests.packages.urllib3.connection import ConnectionError
|
||||
|
||||
|
||||
def get_server_details(server, port, mount):
|
||||
server = "http://%s:%s/status.xsl?mount=/%s" % (server, port, mount)
|
||||
print("Getting info for %s" % server)
|
||||
try:
|
||||
response = requests.get(server)
|
||||
html = response.text
|
||||
if html:
|
||||
try:
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
info = {
|
||||
'stream_title': soup.find(text="Stream Title:").findNext('td').contents[0],
|
||||
'stream_description': soup.find(text="Stream Description:").findNext('td').contents[0],
|
||||
'content_type': soup.find(text="Content Type:").findNext('td').contents[0],
|
||||
'mount_started': soup.find(text="Mount started:").findNext('td').contents[0],
|
||||
'current_listeners': soup.find(text="Current Listeners:").findNext('td').contents[0],
|
||||
'peak_listeners': soup.find(text="Peak Listeners:").findNext('td').contents[0],
|
||||
'stream_url': soup.find(text="Stream URL:").findNext('td').findNext('a').contents[0],
|
||||
'current_song': soup.find(text="Current Song:").findNext('td').contents[0]
|
||||
}
|
||||
return {
|
||||
'status': 2,
|
||||
'metadata': info
|
||||
}
|
||||
except AttributeError:
|
||||
return {
|
||||
'status': 1
|
||||
}
|
||||
else:
|
||||
return {
|
||||
'status': 0
|
||||
}
|
||||
except Exception as ex:
|
||||
return {
|
||||
'status': 0
|
||||
}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
d = get_server_details("localhost", "8000", "dss")
|
||||
print(d)
|
||||
Reference in New Issue
Block a user