Esempio n. 1
0
def JSConverter(file, options):
    f = open(sys.path[0] + "/assets/js/" + file)
    JS = f.read()
    f.close()
    
    # PlexConnect {{URL()}}->baseURL
    for path in set(re.findall(r'\{\{URL\((.*?)\)\}\}', JS)):
        JS = JS.replace('{{URL(%s)}}' % path, g_param['baseURL']+path)
    
    # localization
    JS = Localize.replaceTEXT(JS, options['aTVLanguage']).encode('utf-8')
    
    return JS
Esempio n. 2
0
def JSConverter(file, options):
    f = open(sys.path[0] + "/assets/js/" + file)
    JS = f.read()
    f.close()

    # PlexConnect {{URL()}}->baseURL
    for path in set(re.findall(r'\{\{URL\((.*?)\)\}\}', JS)):
        JS = JS.replace('{{URL(%s)}}' % path, g_param['baseURL'] + path)

    # localization
    JS = Localize.replaceTEXT(JS, options['aTVLanguage']).encode('utf-8')

    return JS
Esempio n. 3
0
 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)
         
         # brake up path, separate PlexConnect options
         options = {}
         while True:
             cmd_start = self.path.find('&PlexConnect')
             cmd_end = self.path.find('&', cmd_start+1)
             
             if cmd_start==-1:
                 break
             if cmd_end>-1:
                 cmd = self.path[cmd_start+1:cmd_end]
                 self.path = self.path[:cmd_start] + self.path[cmd_end:]
             else:
                 cmd = self.path[cmd_start+1:]
                 self.path = self.path[:cmd_start]
             
             parts = cmd.split('=', 1)
             if len(parts)==1:
                 options[parts[0]] = ''
             else:
                 options[parts[0]] = urllib.unquote(parts[1])
         
         # get aTV language setting
         options['aTVLanguage'] = Localize.pickLanguage(self.headers.get('Accept-Language', 'en'))
         
         dprint(__name__, 2, "cleaned path:\n{0}", self.path)
         dprint(__name__, 2, "request options:\n{0}", options)
         
         if 'User-Agent' in self.headers and \
            'AppleTV' in self.headers['User-Agent']:
             
             # recieve simple logging messages from the ATV
             if 'PlexConnectLog' in options:
                 dprint('ATVLogger', 0, options['PlexConnectLog'])
                 self.send_response(200)
                 self.send_header('Content-type', 'text/plain')
                 self.end_headers()
                 return
             
             # serve "application.js" to aTV
             # disregard the path - it is different for different iOS versions
             if self.path.endswith("application.js"):
                 dprint(__name__, 1, "serving application.js")
                 f = open(sys.path[0] + sep + "assets" + sep + "js" + sep + "application.js")
                 self.send_response(200)
                 self.send_header('Content-type', 'text/javascript')
                 self.end_headers()
                 self.wfile.write(f.read())
                 f.close()
                 return
             
             # serve all other .js files to aTV
             if self.path.endswith(".js"):
                 dprint(__name__, 1, "serving  " + sys.path[0] + sep + "assets" + self.path.replace('/',sep))
                 f = open(sys.path[0] + sep + "assets" + self.path.replace('/',sep))
                 self.send_response(200)
                 self.send_header('Content-type', 'text/javascript')
                 self.end_headers()
                 self.wfile.write(Localize.replaceTEXT(f.read(), options['aTVLanguage']).encode('utf-8'))
                 f.close()
                 return
             
             # serve "*.jpg" - thumbnails for old-style mainpage
             if self.path.endswith(".jpg"):
                 dprint(__name__, 1, "serving *.jpg: "+self.path)
                 f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                 self.send_response(200)
                 self.send_header('Content-type', 'image/jpeg')
                 self.end_headers()
                 self.wfile.write(f.read())
                 f.close()
                 return
             
             # serve "*.png" - only png's support transparent colors
             if self.path.endswith(".png"):
                 dprint(__name__, 1, "serving *.png: "+self.path)
                 f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                 self.send_response(200)
                 self.send_header('Content-type', 'image/png')
                 self.end_headers()
                 self.wfile.write(f.read())
                 f.close()
                 return
             
             # 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)
                 self.send_response(200)
                 self.send_header('Content-type', 'text/xml')
                 self.end_headers()
                 self.wfile.write(XML)
                 return
             
             """
             # unexpected request
             self.send_error(403,"Access denied: %s" % self.path)
             """
         
         else:
             self.send_error(403,"Not Serving Client %s" % self.client_address[0])
     except IOError:
         self.send_error(404,"File Not Found: %s" % self.path)
Esempio n. 4
0
 def do_GET(self):
     global g_param
     try:
         dprint(__name__, 2, "http request header:\n{0}", self.headers)
         dprint(__name__, 2, "http request path:\n{0}", self.path)
         
         # check for PMS address
         PMSaddress = ''
         pms_end = self.path.find(')')
         if self.path.startswith('/PMS(') and pms_end>-1:
             PMSaddress = urllib.unquote_plus(self.path[5:pms_end])
             self.path = self.path[pms_end+1:]
         
         # break up path, separate PlexConnect options
         options = {}
         while True:
             cmd_start = self.path.find('&PlexConnect')
             cmd_end = self.path.find('&', cmd_start+1)
             
             if cmd_start==-1:
                 break
             if cmd_end>-1:
                 cmd = self.path[cmd_start+1:cmd_end]
                 self.path = self.path[:cmd_start] + self.path[cmd_end:]
             else:
                 cmd = self.path[cmd_start+1:]
                 self.path = self.path[:cmd_start]
             
             parts = cmd.split('=', 1)
             if len(parts)==1:
                 options[parts[0]] = ''
             else:
                 options[parts[0]] = urllib.unquote(parts[1])
         
         # break up path, separate additional arguments
         # clean path needed for filetype decoding... has to be merged back when forwarded.
         parts = self.path.split('?', 1)
         if len(parts)==1:
             args = ''
         else:
             self.path = parts[0]
             args = '?'+parts[1]
         
         # get aTV language setting
         options['aTVLanguage'] = Localize.pickLanguage(self.headers.get('Accept-Language', 'en'))
         
         # add client address - to be used in case UDID is unknown
         options['aTVAddress'] = self.client_address[0]
         
         dprint(__name__, 2, "pms address:\n{0}", PMSaddress)
         dprint(__name__, 2, "cleaned path:\n{0}", self.path)
         dprint(__name__, 2, "PlexConnect options:\n{0}", options)
         dprint(__name__, 2, "additional arguments:\n{0}", args)
         
         if 'User-Agent' in self.headers and \
            'AppleTV' in self.headers['User-Agent']:
             
             # recieve simple logging messages from the ATV
             if 'PlexConnectATVLogLevel' in options:
                 dprint('ATVLogger', int(options['PlexConnectATVLogLevel']), options['PlexConnectLog'])
                 self.send_response(200)
                 self.send_header('Content-type', 'text/plain')
                 self.end_headers()
                 return
                 
             # serve "*.cer" - Serve up certificate file to atv
             if self.path.endswith(".cer"):
                 dprint(__name__, 1, "serving *.cer: "+self.path)
                 if g_param['CSettings'].getSetting('certfile').startswith('.'):
                     # relative to current path
                     cfg_certfile = sys.path[0] + sep + g_param['CSettings'].getSetting('certfile')
                 else:
                     # absolute path
                     cfg_certfile = g_param['CSettings'].getSetting('certfile')
                 f = open(path.splitext(cfg_certfile)[0] + '.cer', "rb")
                 self.send_response(200)
                 self.send_header('Content-type', 'text/xml')
                 self.end_headers()
                 self.wfile.write(f.read())
                 f.close()
                 return 
             
             # serve .js files to aTV
             if self.path.endswith(".js"):
                 dprint(__name__, 1, "serving  " + sys.path[0] + sep + "assets" + self.path.replace('/',sep).replace('appletv\us\\', '').replace('appletv/us/', ''))
                 f = open(sys.path[0] + sep + "assets" + self.path.replace('/',sep).replace('appletv\us\\', '').replace('appletv/us/', ''))
                 self.send_response(200)
                 self.send_header('Content-type', 'text/javascript')
                 self.end_headers()
                 self.wfile.write(Localize.replaceTEXT(f.read(), options['aTVLanguage']).encode('utf-8'))
                 f.close()
                 return
             
             # serve "*.jpg" - thumbnails for old-style mainpage
             if self.path.endswith(".jpg"):
                 dprint(__name__, 1, "serving *.jpg: "+self.path)
                 f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                 self.send_response(200)
                 self.send_header('Content-type', 'image/jpeg')
                 self.end_headers()
                 self.wfile.write(f.read())
                 f.close()
                 return
             
             # serve "*.png" - only png's support transparent colors
             if self.path.endswith(".png"):
                 dprint(__name__, 1, "serving *.png: "+self.path)
                 f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                 self.send_response(200)
                 self.send_header('Content-type', 'image/png')
                 self.end_headers()
                 self.wfile.write(f.read())
                 f.close()
                 return
             
             # 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(PMSaddress, self.path + args, options)
                 self.send_response(200)
                 self.send_header('Content-type', 'text/xml')
                 self.end_headers()
                 self.wfile.write(XML)
                 return
             
             """
             # unexpected request
             self.send_error(403,"Access denied: %s" % self.path)
             """
         
         else:
             self.send_error(403,"Not Serving Client %s" % self.client_address[0])
     except IOError:
         self.send_error(404,"File Not Found: %s" % self.path)
Esempio n. 5
0
    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)

            # check for PMS address
            PMSaddress = ""
            pms_end = self.path.find(")")
            if self.path.startswith("/PMS(") and pms_end > -1:
                PMSaddress = urllib.unquote_plus(self.path[5:pms_end])
                self.path = self.path[pms_end + 1 :]

            # break up path, separate PlexConnect options
            options = {}
            while True:
                cmd_start = self.path.find("&PlexConnect")
                cmd_end = self.path.find("&", cmd_start + 1)

                if cmd_start == -1:
                    break
                if cmd_end > -1:
                    cmd = self.path[cmd_start + 1 : cmd_end]
                    self.path = self.path[:cmd_start] + self.path[cmd_end:]
                else:
                    cmd = self.path[cmd_start + 1 :]
                    self.path = self.path[:cmd_start]

                parts = cmd.split("=", 1)
                if len(parts) == 1:
                    options[parts[0]] = ""
                else:
                    options[parts[0]] = urllib.unquote(parts[1])

            # break up path, separate additional arguments
            # clean path needed for filetype decoding... has to be merged back when forwarded.
            parts = self.path.split("?", 1)
            if len(parts) == 1:
                args = ""
            else:
                self.path = parts[0]
                args = "?" + parts[1]

            # get aTV language setting
            options["aTVLanguage"] = Localize.pickLanguage(self.headers.get("Accept-Language", "en"))

            # add client address - to be used in case UDID is unknown
            options["aTVAddress"] = self.client_address[0]

            dprint(__name__, 2, "pms address:\n{0}", PMSaddress)
            dprint(__name__, 2, "cleaned path:\n{0}", self.path)
            dprint(__name__, 2, "PlexConnect options:\n{0}", options)
            dprint(__name__, 2, "additional arguments:\n{0}", args)

            if "User-Agent" in self.headers and "AppleTV" in self.headers["User-Agent"]:

                # recieve simple logging messages from the ATV
                if "PlexConnectATVLogLevel" in options:
                    dprint("ATVLogger", int(options["PlexConnectATVLogLevel"]), options["PlexConnectLog"])
                    self.send_response(200)
                    self.send_header("Content-type", "text/plain")
                    self.end_headers()
                    return

                # serve "*.cer" - Serve up certificate file to atv
                if self.path.endswith(".cer"):
                    dprint(__name__, 1, "serving *.cer: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + sep + "certificates" + self.path, "rb")
                    self.send_response(200)
                    self.send_header("Content-type", "text/xml")
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve .js files to aTV
                if self.path.endswith(".js"):
                    dprint(
                        __name__,
                        1,
                        "serving  "
                        + sys.path[0]
                        + sep
                        + "assets"
                        + self.path.replace("/", sep).replace("appletv\us\\", "").replace("appletv/us/", ""),
                    )
                    f = open(
                        sys.path[0]
                        + sep
                        + "assets"
                        + self.path.replace("/", sep).replace("appletv\us\\", "").replace("appletv/us/", "")
                    )
                    self.send_response(200)
                    self.send_header("Content-type", "text/javascript")
                    self.end_headers()
                    self.wfile.write(Localize.replaceTEXT(f.read(), options["aTVLanguage"]).encode("utf-8"))
                    f.close()
                    return

                # serve "*.jpg" - thumbnails for old-style mainpage
                if self.path.endswith(".jpg"):
                    dprint(__name__, 1, "serving *.jpg: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header("Content-type", "image/jpeg")
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "*.png" - only png's support transparent colors
                if self.path.endswith(".png"):
                    dprint(__name__, 1, "serving *.png: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header("Content-type", "image/png")
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # 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(PMSaddress, self.path + args, options)
                    self.send_response(200)
                    self.send_header("Content-type", "text/xml")
                    self.end_headers()
                    self.wfile.write(XML)
                    return

                """
                # unexpected request
                self.send_error(403,"Access denied: %s" % self.path)
                """

            else:
                self.send_error(403, "Not Serving Client %s" % self.client_address[0])
        except IOError:
            self.send_error(404, "File Not Found: %s" % self.path)
Esempio n. 6
0
    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)

            # brake up path, separate PlexConnect options
            options = {}
            while True:
                cmd_start = self.path.find('&PlexConnect')
                cmd_end = self.path.find('&', cmd_start + 1)

                if cmd_start == -1:
                    break
                if cmd_end > -1:
                    cmd = self.path[cmd_start + 1:cmd_end]
                    self.path = self.path[:cmd_start] + self.path[cmd_end:]
                else:
                    cmd = self.path[cmd_start + 1:]
                    self.path = self.path[:cmd_start]

                parts = cmd.split('=', 1)
                if len(parts) == 1:
                    options[parts[0]] = ''
                else:
                    options[parts[0]] = urllib.unquote(parts[1])

            # get aTV language setting
            options['aTVLanguage'] = Localize.pickLanguage(
                self.headers.get('Accept-Language', 'en'))

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

            if 'User-Agent' in self.headers and \
               'AppleTV' in self.headers['User-Agent']:

                # recieve simple logging messages from the ATV
                if 'PlexConnectLog' in options:
                    dprint('ATVLogger', 0, options['PlexConnectLog'])
                    self.send_response(200)
                    self.send_header('Content-type', 'text/plain')
                    self.end_headers()
                    return

                # serve "application.js" to aTV
                # disregard the path - it is different for different iOS versions
                if self.path.endswith("application.js"):
                    dprint(__name__, 1, "serving application.js")
                    f = open(sys.path[0] + sep + "assets" + sep + "js" + sep +
                             "application.js")
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve all other .js files to aTV
                if self.path.endswith(".js"):
                    dprint(
                        __name__, 1, "serving  " + sys.path[0] + sep +
                        "assets" + self.path.replace('/', sep))
                    f = open(sys.path[0] + sep + "assets" +
                             self.path.replace('/', sep))
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(
                        Localize.replaceTEXT(f.read(), options['aTVLanguage']))
                    f.close()
                    return

                # serve "*.jpg" - thumbnails for old-style mainpage
                if self.path.endswith(".jpg"):
                    dprint(__name__, 1, "serving *.jpg: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'image/jpeg')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "*.png" - only png's support transparent colors
                if self.path.endswith(".png"):
                    dprint(__name__, 1, "serving *.png: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'image/png')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # 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)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/xml')
                    self.end_headers()
                    self.wfile.write(XML)
                    return
                """
                # unexpected request
                self.send_error(403,"Access denied: %s" % self.path)
                """

            else:
                self.send_error(
                    403, "Not Serving Client %s" % self.client_address[0])
        except IOError:
            self.send_error(404, "File Not Found: %s" % self.path)
Esempio n. 7
0
    def do_GET(self):
        global g_param
        try:
            dprint(__name__, 2, "http request header:\n{0}", self.headers)
            dprint(__name__, 2, "http request path:\n{0}", self.path)

            # check for PMS address
            PMSaddress = ''
            pms_end = self.path.find(')')
            if self.path.startswith('/PMS(') and pms_end > -1:
                PMSaddress = urllib.unquote_plus(self.path[5:pms_end])
                self.path = self.path[pms_end + 1:]

            # break up path, separate PlexConnect options
            options = {}
            while True:
                cmd_start = self.path.find('&PlexConnect')
                cmd_end = self.path.find('&', cmd_start + 1)

                if cmd_start == -1:
                    break
                if cmd_end > -1:
                    cmd = self.path[cmd_start + 1:cmd_end]
                    self.path = self.path[:cmd_start] + self.path[cmd_end:]
                else:
                    cmd = self.path[cmd_start + 1:]
                    self.path = self.path[:cmd_start]

                parts = cmd.split('=', 1)
                if len(parts) == 1:
                    options[parts[0]] = ''
                else:
                    options[parts[0]] = urllib.unquote(parts[1])

            # break up path, separate additional arguments
            # clean path needed for filetype decoding... has to be merged back when forwarded.
            parts = self.path.split('?', 1)
            if len(parts) == 1:
                args = ''
            else:
                self.path = parts[0]
                args = '?' + parts[1]

            # get aTV language setting
            options['aTVLanguage'] = Localize.pickLanguage(
                self.headers.get('Accept-Language', 'en'))

            # add client address - to be used in case UDID is unknown
            options['aTVAddress'] = self.client_address[0]

            dprint(__name__, 2, "pms address:\n{0}", PMSaddress)
            dprint(__name__, 2, "cleaned path:\n{0}", self.path)
            dprint(__name__, 2, "PlexConnect options:\n{0}", options)
            dprint(__name__, 2, "additional arguments:\n{0}", args)

            if 'User-Agent' in self.headers and \
               'AppleTV' in self.headers['User-Agent']:

                # recieve simple logging messages from the ATV
                if 'PlexConnectATVLogLevel' in options:
                    dprint('ATVLogger', int(options['PlexConnectATVLogLevel']),
                           options['PlexConnectLog'])
                    self.send_response(200)
                    self.send_header('Content-type', 'text/plain')
                    self.end_headers()
                    return

                # serve "*.cer" - Serve up certificate file to atv
                if self.path.endswith(".cer"):
                    dprint(__name__, 1, "serving *.cer: " + self.path)
                    if g_param['CSettings'].getSetting('certfile').startswith(
                            '.'):
                        # relative to current path
                        cfg_certfile = sys.path[0] + sep + g_param[
                            'CSettings'].getSetting('certfile')
                    else:
                        # absolute path
                        cfg_certfile = g_param['CSettings'].getSetting(
                            'certfile')
                    f = open(path.splitext(cfg_certfile)[0] + '.cer', "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'text/xml')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve .js files to aTV
                if self.path.endswith(".js"):
                    dprint(
                        __name__, 1, "serving  " + sys.path[0] + sep +
                        "assets" + self.path.replace('/', sep).replace(
                            'appletv\us\\', '').replace('appletv/us/', ''))
                    f = open(
                        sys.path[0] + sep + "assets" +
                        self.path.replace('/', sep).replace(
                            'appletv\us\\', '').replace('appletv/us/', ''))
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(
                        Localize.replaceTEXT(
                            f.read(), options['aTVLanguage']).encode('utf-8'))
                    f.close()
                    return

                # serve "*.jpg" - thumbnails for old-style mainpage
                if self.path.endswith(".jpg"):
                    dprint(__name__, 1, "serving *.jpg: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'image/jpeg')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "*.png" - only png's support transparent colors
                if self.path.endswith(".png"):
                    dprint(__name__, 1, "serving *.png: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'image/png')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # 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(PMSaddress,
                                                   self.path + args, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/xml')
                    self.end_headers()
                    self.wfile.write(XML)
                    return
                """
                # unexpected request
                self.send_error(403,"Access denied: %s" % self.path)
                """

            else:
                self.send_error(
                    403, "Not Serving Client %s" % self.client_address[0])
        except IOError:
            self.send_error(404, "File Not Found: %s" % self.path)