def discover_all_servers(self): if self.is_myplex_signedin(): printDebug.info( "PleXBMC -> Adding myplex as a server location") self.server_list = self.get_myplex_servers() if self.server_list: printDebug.info("MyPlex discovery completed") if settings.get_setting('discovery') == "1": printDebug.info("local GDM discovery setting enabled.") printDebug.info("Attempting GDM lookup on multicast") if settings.get_debug() >= printDebug.DEBUG_INFO: GDM_debug=3 else: GDM_debug=0 try: gdm_client = plexgdm.plexgdm(GDM_debug) gdm_client.discover() gdm_server_name = gdm_client.getServerList() except Exception, e: print "PleXBMC -> GDM Issue [%s]" % e else: if gdm_client.discovery_complete and gdm_server_name : printDebug.info("GDM discovery completed") for device in gdm_server_name: new_server=PlexMediaServer(name=device['serverName'],address=device['server'], port=device['port'], discovery='discovery', uuid=device['uuid']) new_server.set_user(self.effective_user) new_server.set_token(self.effective_token) self.merge_servers(new_server) else: printDebug.info("GDM was not able to discover any servers")
def get_server_from_ip(self, ip): printDebug.debug("IP to lookup: %s" % ip) if ':' in ip: # We probably have an IP:port being passed ip, port = ip.split(':') if not is_ip(ip): printDebug.info("Not an IP Address") return PlexMediaServer(name="dummy", address='127.0.0.1', port=32400, discovery='local') for server in self.server_list.values(): printDebug.debug("[%s] - checking ip:%s against server ip %s" % (server.get_name(), ip, server.get_address())) if server.find_address_match(ip, port): return server printDebug.info( "Unable to translate - Returning new plexserver set to %s" % ip) return PlexMediaServer(name="Unknown", address=ip, port=port, discovery='local')
def get_myplex_servers(self): tempServers = {} xml = self.talk_to_myplex("/pms/servers") if xml is False: return {} server_list = etree.fromstring(xml) count = 0 for server in server_list: myplex_server=PlexMediaServer( name = server.get('name').encode('utf-8'), address = server.get('address') , port = server.get('port'), discovery = "myplex" , token = server.get('accessToken'), uuid = server.get('machineIdentifier')) if server.get('owned') == "0": myplex_server.set_owned(0) if server.get('localAddresses') is not None: myplex_server.add_local_address(server.get('localAddresses')) myplex_server.set_user(self.effective_user) tempServers[myplex_server.get_uuid()]=myplex_server printDebug.info("Discovered myplex server %s %s" % (myplex_server.get_name(), myplex_server.get_uuid())) return tempServers
def get_myplex_servers(self): tempServers = {} xml = self.talk_to_myplex("/api/resources?includeHttps=1") if xml is False: return {} server_list = etree.fromstring(xml) count = 0 for server in server_list: # we are only interested in devices that offer media if server.get('provides').count('server') == 0: continue local_uris = [] remote_uri = None for c in server: if c.get('local') == "0": remote_uri = c.get('uri') else: local_uris.append(c.get('uri')) myplex_server=PlexMediaServer( name = server.get('name').encode('utf-8'), uri = remote_uri, discovery = "myplex" , token = server.get('accessToken'), uuid = server.get('clientIdentifier')) if server.get('owned') == "0": myplex_server.set_owned(0) myplex_server.set_local_uri(local_uris) myplex_server.set_user(self.effective_user) tempServers[myplex_server.get_uuid()]=myplex_server printDebug.info("Discovered myplex server %s %s" % (myplex_server.get_name(), myplex_server.get_uuid())) return tempServers
def discover_all_servers(self): if self.is_myplex_signedin(): printDebug.info( "PleXBMC -> Adding myplex as a server location") self.server_list = self.get_myplex_servers() if self.server_list: printDebug.info("MyPlex discovery completed") if settings.get_setting('discovery') == "1": printDebug.info("local GDM discovery setting enabled.") printDebug.info("Attempting GDM lookup on multicast") if settings.get_debug() >= printDebug.DEBUG_INFO: GDM_debug=3 else: GDM_debug=0 try: gdm_client = plexgdm.plexgdm(GDM_debug) gdm_client.discover() gdm_server_name = gdm_client.getServerList() except Exception, e: print "PleXBMC -> GDM Issue [%s]" % e else: if gdm_client.discovery_complete and gdm_server_name : printDebug.info("GDM discovery completed") for device in gdm_server_name: new_server=PlexMediaServer(name=device['serverName'],uri="http://"+device['server']+":"+device['port'], discovery='discovery', uuid=device['uuid']) new_server.set_user(self.effective_user) new_server.set_token(self.effective_token) self.merge_servers(new_server) else: printDebug.info("GDM was not able to discover any servers")
def get_server_from_url(self, url): url_parts = urlparse.urlparse(url) base_url = url_parts.scheme+"://"+url_parts.netloc for server in self.server_list.values(): printDebug.debug("[%s] - checking %s against server uri %s" % (server.get_name(), base_url, server.get_uri())) if server.find_uri_match(base_url): return server printDebug.info("Unable to translate - Returning new plexserver set to %s" % base_url ) return PlexMediaServer(name="Unknown",uri=base_url, discovery='local')
new_server.set_token(self.effective_token) self.merge_servers(new_server) else: printDebug.info("GDM was not able to discover any servers") #Set to Disabled else: if settings.get_setting('ipaddress'): if not settings.get_setting('port'): printDebug.info( "PleXBMC -> No port defined. Using default of " + DEFAULT_PORT) printDebug.info( "PleXBMC -> Settings hostname and port: %s : %s" % ( settings.get_setting('ipaddress'), settings.get_setting('port'))) local_server=PlexMediaServer(uri="http://"+settings.get_setting('ipaddress')+":"+settings.get_setting('port'), discovery='local') local_server.set_user(self.effective_user) local_server.set_token(self.effective_token) self.merge_servers(local_server) self.cache.writeCache(self.server_list_cache, self.server_list) printDebug.info("PleXBMC -> serverList is: %s " % self.server_list) return def get_myplex_queue(self): return self.get_processed_myplex_xml('/pms/playlists/queue/all') def get_myplex_sections(self): xml = self.talk_to_myplex('/pms/system/library/sections')
new_server.set_token(self.effective_token) self.merge_servers(new_server) else: printDebug.info("GDM was not able to discover any servers") #Set to Disabled else: if settings.get_setting('ipaddress'): if not settings.get_setting('port'): printDebug.info( "PleXBMC -> No port defined. Using default of " + DEFAULT_PORT) printDebug.info( "PleXBMC -> Settings hostname and port: %s : %s" % ( settings.get_setting('ipaddress'), settings.get_setting('port'))) local_server=PlexMediaServer(address=settings.get_setting('ipaddress'), port=settings.get_setting('port'), discovery='local') local_server.set_user(self.effective_user) local_server.set_token(self.effective_token) self.merge_servers(local_server) self.cache.writeCache(self.server_list_cache, self.server_list) printDebug.info("PleXBMC -> serverList is: %s " % self.server_list) return def get_myplex_queue(self): return self.get_processed_myplex_xml('/pms/playlists/queue/all') def get_myplex_sections(self): xml = self.talk_to_myplex('/pms/system/library/sections')
def get_myplex_servers(self): tempServers = {} xml = self.talk_to_myplex("/pms/servers") if xml is False: return {} server_list = etree.fromstring(xml) count = 0 for server in server_list: myplex_server = PlexMediaServer( name=server.get('name').encode('utf-8'), address=server.get('address'), port=server.get('port'), discovery="myplex", token=server.get('accessToken'), uuid=server.get('machineIdentifier')) if server.get('owned') == "0": myplex_server.set_owned(0) if server.get('localAddresses') is not None: myplex_server.add_local_address(server.get('localAddresses')) myplex_server.set_user(self.effective_user) tempServers[myplex_server.get_uuid()] = myplex_server printDebug.info( "Discovered myplex server %s %s" % (myplex_server.get_name(), myplex_server.get_uuid())) return tempServers
# Set to Disabled else: if settings.get_setting('ipaddress'): if not settings.get_setting('port'): printDebug.info( "PleXBMC -> No port defined. Using default of " + DEFAULT_PORT) printDebug.info( "PleXBMC -> Settings hostname and port: %s : %s" % (settings.get_setting('ipaddress'), settings.get_setting('port'))) local_server = PlexMediaServer( address=settings.get_setting('ipaddress'), port=settings.get_setting('port'), discovery='local') local_server.set_user(self.effective_user) local_server.set_token(self.effective_token) self.merge_servers(local_server) self.cache.writeCache(self.server_list_cache, self.server_list) printDebug.info("PleXBMC -> serverList is: %s " % self.server_list) return def get_myplex_queue(self): return self.get_processed_myplex_xml('/pms/playlists/queue/all') def get_myplex_sections(self):