private void resolveServer() throws UnknownHostException { MediaContainer container = getDocument(API_RESOURCES_URL, MediaContainer.class); // We need the IP-address to find this server in the server list on plex.tv String ip = resolveHostname(connection.getHost()); if (container != null) { for (Device device : container.getDevices()) { if (contains(device.getProvides(), "server")) { for (Connection deviceConnection : device.getConnections()) { boolean uriSet = (connection.getUri() != null); boolean portEqual = String.valueOf(connection.getPort()).equals(deviceConnection.getPort()); boolean hostEqual = ip.equals(deviceConnection.getAddress()); if (!uriSet && portEqual && hostEqual) { connection.setUri(deviceConnection.getUri()); connection.setApiLevel(PlexApiLevel.getApiLevel(device.getProductVersion())); logger.debug( "Server found, version {}, api level {}", device.getProductVersion(), connection.getApiLevel()); } } } } } if (connection.getUri() == null) { logger.warn( "Server not found in plex.tv device list, setting URI from configured data. Try configuring IP-address of host."); connection.setUri(String.format("http://%s:%d", ip, connection.getPort())); } }
private synchronized void refreshSessions() { logger.debug("Refreshing Plex sessions"); MediaContainer container = getDocument(sessionsUrl, MediaContainer.class); if (container != null) { Map<String, PlexSession> previousSessions = new HashMap<String, PlexSession>(sessions); sessions.clear(); addSessionFor(container.getVideos()); addSessionFor(container.getTracks()); setVolumeFromPreviousSessions(previousSessions); } }
private Server getHost(String machineIdentifier) { if (clientCache == null || new Date().getTime() - lastClientCacheUpdate.getTime() > CACHE_VALID_TIME || clientCache.getServer(machineIdentifier) == null) { lastClientCacheUpdate = new Date(); clientCache = getDocument(clientsUrl, MediaContainer.class); } Server server = clientCache.getServer(machineIdentifier); if (server != null) { return server; } return null; }