From c085974137ab9c7e8a55257540a42697801097a1 Mon Sep 17 00:00:00 2001 From: milaq Date: Mon, 21 Jan 2019 02:38:56 +0100 Subject: [PATCH] use host address from headers for redirects allow compatibility with other addresses (e.g. AVRs from other manufacturers) --- ycast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ycast.py b/ycast.py index dff48d3..6963522 100755 --- a/ycast.py +++ b/ycast.py @@ -8,7 +8,6 @@ import xml.etree.cElementTree as etree import yaml -VTUNER_DNS = 'http://radioyamaha.vtuner.com' VTUNER_INITURL = '/setupapp/Yamaha/asp/BrowseXML/loginXML.asp' XMLHEADER = '' YCAST_LOCATION = 'ycast' @@ -38,6 +37,7 @@ def url_to_text(url): class YCastServer(BaseHTTPRequestHandler): def do_GET(self): get_stations() + self.address = 'http://' + self.headers['Host'] if self.path == '/' \ or self.path == '/' + YCAST_LOCATION \ or self.path == '/' + YCAST_LOCATION + '/'\ @@ -49,7 +49,7 @@ class YCastServer(BaseHTTPRequestHandler): xml = self.create_root() for category in sorted(stations, key=str.lower): self.add_dir(xml, category, - VTUNER_DNS + '/' + YCAST_LOCATION + '/' + text_to_url(category)) + self.address + '/' + YCAST_LOCATION + '/' + text_to_url(category)) self.wfile.write(bytes(etree.tostring(xml).decode('utf-8'), 'utf-8')) elif self.path.startswith('/' + YCAST_LOCATION + '/'): category = url_to_text(self.path[len(YCAST_LOCATION) + 2:].partition('?')[0])