Beispiel #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
Beispiel #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
Beispiel #3
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
         # clean path needed for filetype decoding
         parts = re.split(r'[?&]', self.path, 1)  # should be '?' only, but we do some things different :-)
         if len(parts)==1:
             self.path = parts[0]
             options = {}
             query = ''
         else:
             self.path = parts[0]
             
             # break up query string
             options = {}
             query = ''
             parts = parts[1].split('&')
             for part in parts:
                 if part.startswith('PlexConnect'):
                     # get options[]
                     opt = part.split('=', 1)
                     if len(opt)==1:
                         options[opt[0]] = ''
                     else:
                         options[opt[0]] = urllib.unquote(opt[1])
                 else:
                     # recreate query string (non-PlexConnect) - has to be merged back when forwarded
                     if query=='':
                         query = '?' + part
                     else:
                         query += '&' + part
         
         # 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
         if 'X-Forwarded-For' in self.headers:
             options['aTVAddress'] = self.headers['X-Forwarded-For'].split(',', 1)[0]
         else:
             options['aTVAddress'] = self.client_address[0]
         
         # get aTV hard-/software parameters
         options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1')
         options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720')
         
         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}", query)
         
         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')
                 cfg_certfile = path.normpath(cfg_certfile)
                 
                 cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                 try:
                     f = open(cfg_certfile, "rb")
                 except:
                     dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile)
                     return
                 
                 self.sendResponse(f.read(), 'text/xml', False)
                 f.close()
                 return 
             
             # serve .js files to aTV
             # application, main: ignore path, send /assets/js/application.js
             # otherwise: path should be '/js', send /assets/js/*.js
             dirname = path.dirname(self.path)
             basename = path.basename(self.path)
             if basename in ("application.js", "main.js", "javascript-packed.js", "bootstrap.js") or \
                basename.endswith(".js") and dirname == '/js':
                 if basename in ("main.js", "javascript-packed.js", "bootstrap.js"):
                     basename = "application.js"
                 dprint(__name__, 1, "serving /js/{0}", basename)
                 JS = JSConverter(basename, options)
                 self.sendResponse(JS, 'text/javascript', True)
                 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.sendResponse(f.read(), 'image/jpeg', False)
                 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.sendResponse(f.read(), 'image/png', False)
                 f.close()
                 return
             
             # serve subtitle file - transcoded to aTV subtitle json
             if 'PlexConnect' in options and \
                options['PlexConnect']=='Subtitle':
                 dprint(__name__, 1, "serving subtitle: "+self.path)
                 XML = Subtitle.getSubtitleJSON(PMSaddress, self.path + query, options)
                 self.sendResponse(XML, 'application/json', True)
                 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 + query, options)
                 self.sendResponse(XML, 'text/xml', True)
                 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:
         dprint(__name__, 0, 'File Not Found:\n{0}', traceback.format_exc())
         self.send_error(404,"File Not Found: %s" % self.path)
     except:
         dprint(__name__, 0, 'Internal Server Error:\n{0}', traceback.format_exc())
         self.send_error(500,"Internal Server Error: %s" % self.path)
Beispiel #4
0
 def _(self, msgid):
     return Localize.getTranslation(
         self.options['aTVLanguage']).ugettext(msgid)
Beispiel #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)
         
         # 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)
    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]

            # get aTV hard-/software parameters
            options['aTVFirmwareVersion'] = self.headers.get(
                'X-Apple-TV-Version', '5.1')
            options['aTVScreenResolution'] = self.headers.get(
                'X-Apple-TV-Resolution', '720')

            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')

                    cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                    try:
                        f = open(cfg_certfile, "rb")
                    except:
                        dprint(__name__, 0,
                               "Failed to access certificate: {0}",
                               cfg_certfile)
                        return

                    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
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if basename in ("application.js", "main.js", "javascript-packed.js") or \
                   basename.endswith(".js") and dirname == '/js':
                    if basename in ("main.js", "javascript-packed.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(JS)
                    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

            else:
                """
                # unexpected request
                self.send_error(403,"Access denied: %s" % self.path)
                """
                self.send_error(
                    403, "Not Serving Client %s" % self.client_address[0])
        except IOError:
            self.send_error(404, "File Not Found: %s" % self.path)
    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]
            
            # get aTV hard-/software parameters
            options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1')
            options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720')
            
            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')
                    
                    cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                    try:
                        f = open(cfg_certfile, "rb")
                    except:
                        dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile)
                        return
                    
                    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
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if basename in ("application.js", "main.js", "javascript-packed.js") or \
                   basename.endswith(".js") and dirname == '/js':
                    if basename in ("main.js", "javascript-packed.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(JS)
                    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

            else:
                # use the /plexconnect endpoint to discover plex connect servers in the network
                if '/plexconnect' == self.path :
                    self.send_response(200)
                    self.send_header('X-PlexConnect', 'Yeah!')
                    self.end_headers()
                    return

                """
                # unexpected request
                self.send_error(403,"Access denied: %s" % self.path)
                """
                self.send_error(403,self.path +"Not Serving Client %s" % self.client_address[0])
        except IOError:
            self.send_error(404,"File Not Found: %s" % self.path)
Beispiel #8
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
            # clean path needed for filetype decoding
            parts = re.split(
                r'[?&]', self.path,
                1)  # should be '?' only, but we do some things different :-)
            if len(parts) == 1:
                self.path = parts[0]
                options = {}
                query = ''
            else:
                self.path = parts[0]

                # break up query string
                options = {}
                query = ''
                parts = parts[1].split('&')
                for part in parts:
                    if part.startswith('PlexConnect'):
                        # get options[]
                        opt = part.split('=', 1)
                        if len(opt) == 1:
                            options[opt[0]] = ''
                        else:
                            options[opt[0]] = urllib.unquote(opt[1])
                    else:
                        # recreate query string (non-PlexConnect) - has to be merged back when forwarded
                        if query == '':
                            query = '?' + part
                        else:
                            query += '&' + part

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

            query = query.replace("yyltyy", "<").replace("yygtyy", ">")

            # add client address - to be used in case UDID is unknown
            if 'X-Forwarded-For' in self.headers:
                options['aTVAddress'] = self.headers['X-Forwarded-For'].split(
                    ',', 1)[0]
            else:
                options['aTVAddress'] = self.client_address[0]

            # get aTV hard-/software parameters
            options['aTVFirmwareVersion'] = self.headers.get(
                'X-Apple-TV-Version', '5.1')
            options['aTVScreenResolution'] = self.headers.get(
                'X-Apple-TV-Resolution', '720')

            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}", query)

            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')
                    cfg_certfile = path.normpath(cfg_certfile)

                    cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                    try:
                        f = open(cfg_certfile, "rb")
                    except:
                        dprint(__name__, 0,
                               "Failed to access certificate: {0}",
                               cfg_certfile)
                        return

                    self.sendResponse(f.read(), 'text/xml', False)
                    f.close()
                    return

                # serve .js files to aTV
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if basename in ("application.js", "main.js", "javascript-packed.js", "bootstrap.js") or \
                   basename.endswith(".js") and dirname == '/js':
                    if basename in ("main.js", "javascript-packed.js",
                                    "bootstrap.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.sendResponse(JS, 'text/javascript', True)
                    return

                # proxy phobos.apple.com to support  PlexConnect main icon
                if "a1.phobos.apple.com" in self.headers['Host']:
                    resource = self.headers['Host'] + self.path
                    icon = g_param['CSettings'].getSetting('icon')
                    if basename.startswith(icon):
                        icon_res = basename[len(
                            icon
                        ):]  # cut string from settings, keeps @720.png/@1080.png
                        resource = sys.path[0] + '/assets/icons/icon' + icon_res
                        dprint(
                            __name__, 1, "serving " + self.headers['Host'] +
                            self.path + " with " + resource)
                        r = open(resource, "rb")
                    else:
                        r = urllib.urlopen('http://' + resource)
                    self.sendResponse(r.read(), 'image/png', False)
                    r.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.sendResponse(f.read(), 'image/jpeg', False)
                    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.sendResponse(f.read(), 'image/png', False)
                    f.close()
                    return

                # serve subtitle file - transcoded to aTV subtitle json
                if 'PlexConnect' in options and \
                   options['PlexConnect']=='Subtitle':
                    dprint(__name__, 1, "serving subtitle: " + self.path)
                    XML = Subtitle.getSubtitleJSON(PMSaddress,
                                                   self.path + query, options)
                    self.sendResponse(XML, 'application/json', True)
                    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 + query, options)
                    self.sendResponse(XML, 'text/xml', True)
                    return
                """
                # unexpected request
                self.send_error(403,"Access denied: %s" % self.path)
                """

            else:
                """
                Added Up Page for docker helthcheck
                self.send_error(403,"Not Serving Client %s" % self.client_address[0])
                """
                dprint(__name__, 1, "serving *.html: " + self.path)
                f = open(sys.path[0] + sep + "assets/templates/up.html")
                self.sendResponse(f.read(), 'text/html', False)
                f.close()

        except IOError:
            dprint(__name__, 0, 'File Not Found:\n{0}', traceback.format_exc())
            self.send_error(404, "File Not Found: %s" % self.path)
        except:
            dprint(__name__, 0, 'Internal Server Error:\n{0}',
                   traceback.format_exc())
            self.send_error(500, "Internal Server Error: %s" % self.path)
Beispiel #9
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]

            # get aTV hard-/software parameters
            options['aTVFirmwareVersion'] = self.headers.get(
                'X-Apple-TV-Version', '5.1')
            options['aTVScreenResolution'] = self.headers.get(
                'X-Apple-TV-Resolution', '720')

            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']:

                # serve the plex icon
                if self.headers[
                        'Host'] == 'a1.phobos.apple.com' and self.path.endswith(
                            ".png"):
                    # possible icon
                    basename = path.basename(self.path)
                    iconname, ext = basename.split('.')
                    dprint(__name__, 2, "serving icon {0}", iconname)
                    name, rez = iconname.split('@')
                    dprint(__name__, 2, "icon name: {0} at {1}", name, rez)
                    hosticons = {
                        'www.icloud.com': 'Theater',
                        'atv.hbogo.com': 'HBOGo',
                        'atv.qello.com': 'QelloV2',
                        'appletv.app.hulu.com': 'huluplus',
                        'appletv.vevo.com': 'VevoV1',
                        'apps.sho.com': 'Smithsonian_V2',
                        'watchdisneyjunior.go.com': 'DisneyJR',
                        'watchdisneychannel.go.com': 'DisneyChannel_V2',
                        'watchdisneyxd.go.com': 'DisneyXD_V2',
                        'ssl.weather.com': 'weatherchannel',
                        'secure.marketwatch.com': 'wsj',
                        'trailers.apple.com': 'movie-trailers',
                        'secure.showtimeanytime.com': 'com.showtime.appletv',
                        'vimeo.com': 'vimeo',
                        'd6mhwe3a8uvr5.cloudfront.net': 'skynews',
                        'video.pbs.org': 'PBS_V2',
                        'neulion-a.akamaihd.net': 'MLS_V3',
                        'itunesconnect.apple.com': 'iTunesConnect',
                        'abcnews.go.com': 'ABC_News',
                        'atvapp.willow.tv': 'Willow',
                        'player.aetndigital.com': 'Lifetime_V2',
                        'www.crunchyroll.com': 'CrunchyRollV3',
                        'watchabc.go.com': 'ABC',
                        'appletv.redbull.tv': 'RedBullTV',
                        'neulion-a.akamaihd.net': 'NHL',
                        'appletv.cnbc.com': 'CNBC',
                        'appletv.now.nfl.com': 'NFL_Now',
                        'secure.net.wwe.com': 'WWE',
                        'api-global.netflix.com': 'netflix',
                        'player.aetndigital.com': 'AE_V2',
                        's.yimg.com': 'YahooScreen',
                        'kids.pbs.org': 'PBS_Kids',
                        'kortv.com': 'KORTV_V2',
                        'appletv.crackle.com': 'Crackle',
                        'd1d0j1u9ayd8uc.cloudfront.net': 'ACC_V2',
                        's.cdn.turner.com': 'nba',
                        'player.aetndigital.com': 'History_V2',
                        'aptve.foxneodigital.com': 'FOX_Now',
                        'appletv.flickr.com': 'Flickr',
                        'a248.e.akamai.net': 'ESPNv3',
                        'mobapi.bloomberg.com': 'Bloomberg_V2',
                        's.aolcdn.com': 'AOL_On'
                    }
                    if name == hosticons.get(g_param['HostToIntercept']):
                        dprint(__name__, 2, "getting plex icon")
                        f = open(
                            sys.path[0] + sep + "assets" + sep + "thumbnails" +
                            sep + "icon@" + rez + ".png", "rb")
                        self.send_response(200)
                        self.send_header('Content-type', 'image/png')
                        self.end_headers()
                        self.wfile.write(f.read())
                        f.close()
                        return
                    else:
                        dprint(__name__, 2, "getting app icon")
                        self.send_response(200)
                        self.send_header('Content-type', 'image/png')
                        self.end_headers()
                        self.wfile.write(
                            urllib.urlopen('http://' + self.headers['Host'] +
                                           self.path).read())
                        return
                elif self.headers['Host'] == 'a1.phobos.apple.com':
                    # something other than an icon was requested
                    self.send_response(200)
                    self.send_header('Content-type',
                                     self.headers['Content-type'])
                    self.end_headers()
                    self.wfile.write(
                        urllib.urlopen('http://' + self.headers['Host'] +
                                       self.path).read())
                    return

                # 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')
                    cfg_certfile = path.normpath(cfg_certfile)

                    cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                    try:
                        f = open(cfg_certfile, "rb")
                    except:
                        dprint(__name__, 0,
                               "Failed to access certificate: {0}",
                               cfg_certfile)
                        return

                    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
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if basename in ("application.js", "main.js", "javascript-packed.js") or \
                   basename.endswith(".js") and dirname == '/js':
                    if basename in ("main.js", "javascript-packed.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(JS)
                    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)
Beispiel #10
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]
         
         # get aTV hard-/software parameters
         options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1')
         options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720')
         
         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']:
             
             # serve the plex icon
             if self.headers['Host'] == 'a1.phobos.apple.com' and self.path.endswith(".png"):
                 # possible icon
                 basename = path.basename(self.path)
                 iconname, ext = basename.split('.')
                 dprint(__name__, 2, "serving icon {0}", iconname)
                 name, rez = iconname.split('@')
                 dprint(__name__, 2, "icon name: {0} at {1}", name, rez)
                 hosticons = {
                     'www.icloud.com': 'iMovieNewAuth',
                     'atv.hbogo.com': 'vega',
                     'atv.qello.com': 'qello',
                     'a248.e.akamai.net': 'hulu',
                     'appletv.vevo.com': 'com.vevo.appletv',
                     'apps.sho.com': 'com.smithsonian.appletv',
                     'appletv.watchdisneyjunior.go.com': 'com.disney.junior.appletv',
                     'appletv.watchdisneychannel.go.com': 'com.disney.channel.appletv',
                     'appletv.watchdisneyxd.go.com': 'com.disney.xd.appletv',
                     'ssl.weather.com': 'com.weather.appletv',
                     'secure.marketwatch.com': 'wsj',
                     'trailers.apple.com': 'movie-trailers',
                     'secure.showtimeanytime.com': 'com.showtime.appletv',
                     'vimeo.com': 'vimeo',
                     'd6mhwe3a8uvr5.cloudfront.net': 'skynews',
                     'video.pbs.org': 'com.pbs.appletv',
                     'neulion-a.akamaihd.net': 'com.mlssoccer.appletv',
                     'itunesconnect.apple.com': 'iTunesConnect',
                     'abcnews.go.com': 'com.abcnews.appletv',
                     'atvapp.willow.tv': 'com.willowtv.appletv',
                     'player.aetndigital.com': 'com.aenetworks.lifetime.appletv',
                     'www.crunchyroll.com': 'crunchyroll',
                     'watchabc.go.com': 'com.abc.appletv.v2',
                     'appletv.redbull.tv': 'com.redbulltv.appletv',
                     'neulion-a.akamaihd.net': 'NHL',
                     'appletv.cnbc.com': 'com.cnbc.appletv',
                     'appletv.now.nfl.com': 'com.nfl.now.appletv',
                     'secure.net.wwe.com': 'com.wwe.appletv.v2',
                     'api-global.netflix.com': 'netflix',
                     'player.aetndigital.com': 'com.aenetworks.appletv',
                     's.yimg.com': 'com.yahoo.screen.appletv',
                     'kids.pbs.org': 'com.pbskids.appletv.v2',
                     'kortv.com': 'com.wkntv.appletv',
                     'appletv.crackle.com': 'com.crackle.appletv.v2',
                     'd1d0j1u9ayd8uc.cloudfront.net': 'com.acc.appletv',
                     's.cdn.turner.com': 'nba',
                     'player.aetndigital.com': 'com.aenetworks.history.appletv',
                     'aptve.foxneodigital.com': 'com.foxnow.appletv',
                     'appletv.flickr.com': 'flickr',
                     'a248.e.akamai.net': 'carterville',
                     'securea.mlb.com': 'flagstaff',
                     'mobapi.bloomberg.com': 'com.bloomberg.appletv',
                     'aptve-fx.foxneodigital.com': 'com.fxnow.appletv',
                     'festival.itunes.apple.com': 'com.festival.appletv',
                     's.aolcdn.com': 'com.aolon.appletv'
                 }
                 if name == hosticons.get(g_param['HostToIntercept']):
                     dprint(__name__, 2, "getting plex icon")
                     f = open(sys.path[0] + sep + "assets" + sep + "thumbnails" + sep + "icon@" + rez + ".png", "rb")
                     self.send_response(200)
                     self.send_header('Content-type', 'image/png')
                     self.end_headers()
                     self.wfile.write(f.read())
                     f.close()
                     return
                 else:
                     dprint(__name__, 2, "getting app icon")
                     self.send_response(200)
                     self.send_header('Content-type', 'image/png')
                     self.end_headers()
                     self.wfile.write(urllib.urlopen('http://' + self.headers['Host'] + self.path).read())
                     return
             elif self.headers['Host'] == 'a1.phobos.apple.com':
             	# something other than an icon was requested
                 self.send_response(200)
                 self.send_header('Content-type', self.headers['Content-type'])
                 self.end_headers()
                 self.wfile.write(urllib.urlopen('http://' + self.headers['Host'] + self.path).read())
                 return
             
             # 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')
                 cfg_certfile = path.normpath(cfg_certfile)
                 
                 cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                 try:
                     f = open(cfg_certfile, "rb")
                 except:
                     dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile)
                     return
                 
                 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
             # application, main: ignore path, send /assets/js/application.js
             # otherwise: path should be '/js', send /assets/js/*.js
             dirname = path.dirname(self.path)
             basename = path.basename(self.path)
             if basename in ("application.js", "main.js", "javascript-packed.js") or \
                basename.endswith(".js") and dirname == '/js':
                 if basename in ("main.js", "javascript-packed.js"):
                     basename = "application.js"
                 dprint(__name__, 1, "serving /js/{0}", basename)
                 JS = JSConverter(basename, options)
                 self.send_response(200)
                 self.send_header('Content-type', 'text/javascript')
                 self.end_headers()
                 self.wfile.write(JS)
                 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)
Beispiel #11
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)
Beispiel #12
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
            # clean path needed for filetype decoding
            parts = re.split(r"[?&]", self.path, 1)  # should be '?' only, but we do some things different :-)
            if len(parts) == 1:
                self.path = parts[0]
                options = {}
                query = ""
            else:
                self.path = parts[0]

                # break up query string
                options = {}
                query = ""
                parts = parts[1].split("&")
                for part in parts:
                    if part.startswith("PlexConnect"):
                        # get options[]
                        opt = part.split("=", 1)
                        if len(opt) == 1:
                            options[opt[0]] = ""
                        else:
                            options[opt[0]] = urllib.unquote(opt[1])
                    else:
                        # recreate query string (non-PlexConnect) - has to be merged back when forwarded
                        if query == "":
                            query = "?" + part
                        else:
                            query += "&" + part

            # 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
            if "X-Forwarded-For" in self.headers:
                options["aTVAddress"] = self.headers["X-Forwarded-For"].split(",", 1)[0]
            else:
                options["aTVAddress"] = self.client_address[0]

            # get aTV hard-/software parameters
            options["aTVFirmwareVersion"] = self.headers.get("X-Apple-TV-Version", "5.1")
            options["aTVScreenResolution"] = self.headers.get("X-Apple-TV-Resolution", "720")

            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}", query)

            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")
                    cfg_certfile = path.normpath(cfg_certfile)

                    cfg_certfile = path.splitext(cfg_certfile)[0] + ".cer"
                    try:
                        f = open(cfg_certfile, "rb")
                    except:
                        dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile)
                        return

                    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
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if (
                    basename in ("application.js", "main.js", "javascript-packed.js", "bootstrap.js")
                    or basename.endswith(".js")
                    and dirname == "/js"
                ):
                    if basename in ("main.js", "javascript-packed.js", "bootstrap.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.send_response(200)
                    self.send_header("Content-type", "text/javascript")
                    self.end_headers()
                    self.wfile.write(JS)
                    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

                # serve subtitle file - transcoded to aTV subtitle json
                if "PlexConnect" in options and options["PlexConnect"] == "Subtitle":
                    dprint(__name__, 1, "serving subtitle: " + self.path)
                    XML = Subtitle.getSubtitleJSON(PMSaddress, self.path + query, options)
                    self.send_response(200)
                    self.send_header("Content-type", "application/json")
                    self.end_headers()
                    self.wfile.write(XML)
                    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 + query, 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)
Beispiel #13
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)
Beispiel #14
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 = ''
            # Build PMS address from settings. PSR
            PMSaddress = 'http://' + g_param['CSettings'].getSetting(
                'ip_pms') + ':' + g_param['CSettings'].getSetting('port_pms')

            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 PlexNMT options
            options = {}
            while True:
                cmd_start = self.path.find('&PlexNMT')
                if cmd_start == -1:
                    cmd_start = self.path.find('?PlexNMT')
                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 NMT language setting
            options['NMTLanguage'] = Localize.pickLanguage(
                self.headers.get('Accept-Language', 'en'))

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

            # get aTV hard-/software parameters
            #            options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1')
            #            options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720')

            dprint(__name__, 2, "pms address:\n{0}", PMSaddress)
            dprint(__name__, 2, "cleaned path:\n{0}", self.path)
            dprint(__name__, 2, "PlexNMT 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 NMT
                if 'PlexConnectNMTLogLevel' in options:
                    dprint('NMTLogger', int(options['PlexConnectNMTLogLevel']),
                           options['PlexNMTLog'])
                    self.send_response(200)
                    self.send_header('Content-type', 'text/plain')
                    self.end_headers()
                    return

                # serve .js files
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if basename in ("application.js", "main.js", "javascript-packed.js") or \
                   basename.endswith(".js") and dirname == '/js':
                    if basename in ("main.js", "javascript-packed.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(JS)
                    return

                # serve "*.ico" - favicon.ico
                if self.path.endswith(".ico"):
                    dprint(__name__, 1, "serving *.ico: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'image/ico')
                    self.end_headers()
                    self.wfile.write(f.read())
                    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

                # serve "*.js" - js are all from PlexNMT
                if self.path.endswith(".js"):
                    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', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "*.xsl"
                if self.path.endswith(".xsl"):
                    dprint(__name__, 1, "serving *.xsl: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + 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 "*.html"
                if self.path.endswith(".html"):
                    dprint(__name__, 1, "serving *.html: " + self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "/index.html"
                if self.path == "/":
                    dprint(__name__, 1, "serving /index.html")
                    try:
                        f = open(
                            sys.path[0] + sep + "assets" + sep + "index.html",
                            "rb")
                        self.send_response(200)
                        self.send_header('Content-type', 'text/html')
                        self.end_headers()
                        self.wfile.write(f.read())
                        f.close()
                        return
                    except:
                        dprint(__name__, 1, "No index.html; using root of pms")

                # get everything else from XMLConverter
                if True:
                    if self.path == "/pms":
                        self.path = "/"
                    dprint(__name__, 1, "serving .xml: " + self.path)
                    HTML = XMLConverter.XML_PMS2NMT(PMSaddress,
                                                    self.path + args, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()
                    self.wfile.write(HTML)
                    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)
Beispiel #15
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 = ''
            # Build PMS address from settings. PSR
            PMSaddress = 'http://' + g_param['CSettings'].getSetting('ip_pms') + ':' + g_param['CSettings'].getSetting('port_pms')

            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 PlexNMT options
            options = {}
            while True:
                cmd_start = self.path.find('&PlexNMT')
                if cmd_start==-1:
                    cmd_start = self.path.find('?PlexNMT')
                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 NMT language setting
            options['NMTLanguage'] = Localize.pickLanguage(self.headers.get('Accept-Language', 'en'))
            
            # add client address - to be used in case UDID is unknown
            options['NMTAddress'] = self.client_address[0]
            
            # get aTV hard-/software parameters
#            options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1')
#            options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720')

            dprint(__name__, 2, "pms address:\n{0}", PMSaddress)
            dprint(__name__, 2, "cleaned path:\n{0}", self.path)
            dprint(__name__, 2, "PlexNMT 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 NMT
                if 'PlexConnectNMTLogLevel' in options:
                    dprint('NMTLogger', int(options['PlexConnectNMTLogLevel']), options['PlexNMTLog'])
                    self.send_response(200)
                    self.send_header('Content-type', 'text/plain')
                    self.end_headers()
                    return
                    
                # serve .js files 
                # application, main: ignore path, send /assets/js/application.js
                # otherwise: path should be '/js', send /assets/js/*.js
                dirname = path.dirname(self.path)
                basename = path.basename(self.path)
                if basename in ("application.js", "main.js", "javascript-packed.js") or \
                   basename.endswith(".js") and dirname == '/js':
                    if basename in ("main.js", "javascript-packed.js"):
                        basename = "application.js"
                    dprint(__name__, 1, "serving /js/{0}", basename)
                    JS = JSConverter(basename, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(JS)
                    return
                
                # serve "*.ico" - favicon.ico
                if self.path.endswith(".ico"):
                    dprint(__name__, 1, "serving *.ico: "+self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'image/ico')
                    self.end_headers()
                    self.wfile.write(f.read())
                    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
                
                # serve "*.js" - js are all from PlexNMT
                if self.path.endswith(".js"):
                    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', 'text/javascript')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "*.xsl" 
                if self.path.endswith(".xsl"):
                    dprint(__name__, 1, "serving *.xsl: "+self.path)
                    f = open(sys.path[0] + sep + "assets" + 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 "*.html" 
                if self.path.endswith(".html"):
                    dprint(__name__, 1, "serving *.html: "+self.path)
                    f = open(sys.path[0] + sep + "assets" + self.path, "rb")
                    self.send_response(200)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return

                # serve "/index.html" 
                if self.path == "/":
                    dprint(__name__, 1, "serving /index.html")
                    try:
                        f = open(sys.path[0] + sep + "assets" + sep + "index.html", "rb")
                        self.send_response(200)
                        self.send_header('Content-type', 'text/html')
                        self.end_headers()
                        self.wfile.write(f.read())
                        f.close()
                        return
                    except:
                        dprint(__name__, 1, "No index.html; using root of pms")

                # get everything else from XMLConverter 
                if True:
                    if self.path == "/pms":
                        self.path = "/"
                    dprint(__name__, 1, "serving .xml: "+self.path)
                    HTML = XMLConverter.XML_PMS2NMT(PMSaddress, self.path + args, options)
                    self.send_response(200)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()
                    self.wfile.write(HTML)
                    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)
 def _(self, msgid):
     return Localize.getTranslation(self.options["NMTLanguage"]).ugettext(msgid)
Beispiel #17
0
# GUI Class
Path = "F:/4th year/Graduation project/Video-Forgery-Detection/Data set/12_forged.avi"
# InputOutput_obj=InputOutput.Input(Path)
# InputOutput_obj=InputOutput.Read()

InputOutput_obj = InputOutput.Read(Path)
InputOutput_obj.ReadVideo()
Video = InputOutput_obj.GetVideo()

FeaturesExtraction_obj = FeaturesExtraction.FeaturesExtraction(Video)
FeaturesExtraction_obj.WaveletDenoising()

FeaturesExtraction_obj.CorrelationCoefficient()
Features = FeaturesExtraction_obj.GetCorrelationCoefficient()
Classify_obj = ForgeryDetermination.Classify(Features)
forged = Classify_obj.GaussianMixture()

if (forged == True):
    Localize_obj = Localize.Localize(Features)
    Localize_obj.Thershold()
    Video, Result = Localize_obj.Localization(Video)
else:
    Result = "Original"
# output class in inputoutput file
for i in range(1, len(Video)):
    print(i)
    cv2.imshow('out', Video[i])
    cv2.waitKey(0)
print(Result)
Beispiel #18
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)
Beispiel #19
0
 def _(self, msgid):
     return Localize.getTranslation(self.options['aTVLanguage']).ugettext(msgid)
Beispiel #20
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]
         
         # get aTV hard-/software parameters
         options['aTVFirmwareVersion'] = self.headers.get('X-Apple-TV-Version', '5.1')
         options['aTVScreenResolution'] = self.headers.get('X-Apple-TV-Resolution', '720')
         
         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']:
             
             # serve the plex icon
             if self.headers['Host'] == 'a1.phobos.apple.com' and self.path.endswith(".png"):
                 # possible icon
                 basename = path.basename(self.path)
                 iconname, ext = basename.rsplit('.', 1)
                 dprint(__name__, 2, "serving icon {0}", iconname)
                 name, rez = iconname.split('@')
                 dprint(__name__, 2, "icon name: {0} at {1}", name, rez)
                 hosticons = {
                     'www.icloud.com': 'Theater',
                     'atv.hbogo.com': 'HBOGo',
                     'atv.qello.com': 'QelloV2',
                     'appletv.app.hulu.com': 'huluplus',
                     'appletv.vevo.com': 'VevoV1',
                     'apps.sho.com': 'SmithsonianBlue',
                     'watchdisneyjunior.go.com': 'DisneyJR',
                     'watchdisneychannel.go.com': 'DisneyChannel_V2',
                     'watchdisneyxd.go.com': 'DisneyXD_V2',
                     'ssl.weather.com': 'weatherchannel'
                 }
                 if name == hosticons.get(g_param['HostToIntercept']):
                     dprint(__name__, 2, "getting plex icon")
                     f = open(sys.path[0] + sep + "assets" + sep + "thumbnails" + sep + "icon@" + rez + ".png", "rb")
                     self.send_response(200)
                     self.send_header('Content-type', 'image/png')
                     self.end_headers()
                     self.wfile.write(f.read())
                     f.close()
                     return
                 else:
                     dprint(__name__, 2, "getting app icon")
                     self.send_response(200)
                     self.send_header('Content-type', 'image/png')
                     self.end_headers()
                     self.wfile.write(urllib.urlopen('http://' + self.headers['Host'] + self.path).read())
                     return
             elif self.headers['Host'] == 'a1.phobos.apple.com':
             	# something other than an icon was requested
                 self.send_response(200)
                 self.send_header('Content-type', self.headers['Content-type'])
                 self.end_headers()
                 self.wfile.write(urllib.urlopen('http://' + self.headers['Host'] + self.path).read())
                 return
                 
             # 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')
                 cfg_certfile = path.normpath(cfg_certfile)
                 
                 cfg_certfile = path.splitext(cfg_certfile)[0] + '.cer'
                 try:
                     f = open(cfg_certfile, "rb")
                 except:
                     dprint(__name__, 0, "Failed to access certificate: {0}", cfg_certfile)
                     return
                 
                 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
             # application, main: ignore path, send /assets/js/application.js
             # otherwise: path should be '/js', send /assets/js/*.js
             dirname = path.dirname(self.path)
             basename = path.basename(self.path)
             if basename in ("application.js", "main.js", "javascript-packed.js") or \
                basename.endswith(".js") and dirname == '/js':
                 if basename in ("main.js", "javascript-packed.js"):
                     basename = "application.js"
                 dprint(__name__, 1, "serving /js/{0}", basename)
                 JS = JSConverter(basename, options)
                 self.send_response(200)
                 self.send_header('Content-type', 'text/javascript')
                 self.end_headers()
                 self.wfile.write(JS)
                 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
             
             # serve subtitle file - transcoded to aTV subtitle json
             if 'PlexConnect' in options and \
                options['PlexConnect']=='Subtitle':
                 dprint(__name__, 1, "serving subtitle: "+self.path)
                 XML = Subtitle.getSubtitleJSON(PMSaddress, self.path + args, options)
                 self.send_response(200)
                 self.send_header('Content-type', 'application/json')
                 self.end_headers()
                 self.wfile.write(XML)
                 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)