コード例 #1
0
ファイル: PlexConnector.java プロジェクト: juri8/openhab
  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()));
    }
  }
コード例 #2
0
ファイル: PlexConnector.java プロジェクト: juri8/openhab
  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);
    }
  }
コード例 #3
0
ファイル: PlexConnector.java プロジェクト: juri8/openhab
  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;
  }