Skip to content

Commit

Permalink
Revert "URLs: WebServer to crack up path and options"
Browse files Browse the repository at this point in the history
This reverts commit c54bacf.
  • Loading branch information
iBaa committed Jun 9, 2013
1 parent c54bacf commit e7f8c0d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 47 deletions.
38 changes: 5 additions & 33 deletions WebServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,17 @@ def do_GET(self):
try:
dprint(__name__, 2, "http request header:\n{0}", self.headers)
dprint(__name__, 2, "http request path:\n{0}", self.path)

# break up path, separate options
# compare urlparse.parse_qs() but that returns {option:[lists of val]}
options = {}
if self.path.find('?')==-1 and \
self.path.find('&')==-1:
pass
else:
if not self.path.find('?')==-1:
parts = self.path.split('?',1)
else:
parts = self.path.split('&',1)
self.path = parts[0]

parts = parts[1].split('&')
for opt in parts:
opt_parts = opt.split('=',1)
if len(opt_parts)==1:
options[opt_parts[0]] = ''
else:
options[opt_parts[0]] = opt_parts[1]

dprint(__name__, 2, "cleaned path:\n{0}", self.path)
dprint(__name__, 2, "request args:\n{0}", options)

if self.headers['Host'] == g_param['HostToIntercept'] and \
self.headers['User-Agent'].startswith("iTunes-AppleTV"):

# recieve simple logging messages from the ATV
if 'PlexLog' in options: # self.path.endswith("&atvlogger"):
msg = options['PlexLog']
msg = msg.replace("%20", " ")
if self.path.endswith("&atvlogger"):
msg = self.path.replace("%20", " ")
msg = msg.replace("&lt;", "<")
msg = msg.replace("&gt;", ">")
msg = msg.replace("&fs;", "/")
msg = msg.replace("&qo;", '"')
msg = msg[1:len(msg)-10]
dprint('ATVLogger', 0, msg)
self.send_response(200)
self.send_header('Content-type', 'text/plain')
Expand Down Expand Up @@ -145,10 +120,7 @@ def do_GET(self):
# path could be a search string
if self.path.find('search') > -1:
dprint(__name__, 1, "Search Query=" + "/search?type=2&query=" +self.path[8:] + "&amp;PlexConnect=Search")
options = {'PlexConnect':'Search', \
'type':'4', \
'query':self.path[8:] }
XML = XMLConverter.XML_PMS2aTV(self.client_address, "/search", options)
XML = XMLConverter.XML_PMS2aTV(self.client_address, "/search?type=4&query=" +self.path[8:] + "&PlexConnect=Search")
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
Expand All @@ -158,7 +130,7 @@ def do_GET(self):
# get everything else from XMLConverter - formerly limited to trailing "/" and &PlexConnect Cmds
if True:
dprint(__name__, 1, "serving .xml: "+self.path)
XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path, options)
XML = XMLConverter.XML_PMS2aTV(self.client_address, self.path)
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
Expand Down
21 changes: 12 additions & 9 deletions XMLConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,20 @@ def XML_ReadFromURL(address, path):



def XML_PMS2aTV(address, path, options):
def XML_PMS2aTV(address, path):

cmd = ''
if 'PlexConnect' in options:
options = {}
pos = string.find(path, "&PlexConnect=")
if pos>-1:
params = path[pos+1:].split('&')
for p in params:
param = p.split('=')
options[param[0]] = param[1]
cmd = options['PlexConnect']
del options['PlexConnect']

if len(options)==0:
PMS = XML_ReadFromURL(address, path)
else:
PMS = XML_ReadFromURL(address, path + '?' + urlencode(options))
path = path[:pos]

PMS = XML_ReadFromURL(address, path)
if PMS==False:
return XML_Error('PlexConnect', 'No Response from Plex Media Server')

Expand Down
6 changes: 3 additions & 3 deletions assets/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ function loadPage(url)

/*
* ATVlogger
*/
*/
function log(msg)
{
msg = msg.replace(/ /g, "%20")
msg = msg.replace(/</g, "&lt;")
msg = msg.replace(/>/g, "&gt;")
msg = msg.replace(/\//g, "&fs;")
msg = msg.replace(/"/g, "&qo;")
msg = msg.replace(/"/g, "&qo;")

loadPage("http://trailers.apple.com/&PlexLog=" + msg);
loadPage("http://trailers.apple.com/" + msg + "&atvlogger");
};

/*
Expand Down
3 changes: 1 addition & 2 deletions assets/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ function log(msg)
msg = msg.replace(/>/g, "&gt;")
msg = msg.replace(/\//g, "&fs;")
msg = msg.replace(/"/g, "&qo;")

var req = new XMLHttpRequest();
var url = "http://trailers.apple.com/&PlexLog=" + msg;
var url = "http://trailers.apple.com/" + msg + "&atvlogger";
req.open('GET', url, true);
req.send();
};
Expand Down

0 comments on commit e7f8c0d

Please sign in to comment.