]> git.basschouten.com Git - openhab-addons.git/commitdiff
Added URL path support. (#13436)
authorTobias Liese <56112387+SR-Lut3t1um@users.noreply.github.com>
Sat, 1 Oct 2022 13:32:11 +0000 (15:32 +0200)
committerGitHub <noreply@github.com>
Sat, 1 Oct 2022 13:32:11 +0000 (15:32 +0200)
Changes:
Fix: Now using KTOR instead of building the url by simple string concad. This fixes the https and port 443 bug that existed prier to this change. (https://example.com would look like: https://example.com:443)
Added: Support for jellyfins Base URL option. This allows the addon to be used on installations were jellyfin uses a base path.

Signed-off-by: tliese <mail@tobiasliese.me>
bundles/org.openhab.binding.jellyfin/README.md
bundles/org.openhab.binding.jellyfin/src/main/java/org/openhab/binding/jellyfin/internal/JellyfinServerConfiguration.java
bundles/org.openhab.binding.jellyfin/src/main/java/org/openhab/binding/jellyfin/internal/discovery/JellyfinServerDiscoveryService.java
bundles/org.openhab.binding.jellyfin/src/main/java/org/openhab/binding/jellyfin/internal/handler/JellyfinServerHandler.java
bundles/org.openhab.binding.jellyfin/src/main/resources/OH-INF/i18n/jellyfin.properties
bundles/org.openhab.binding.jellyfin/src/main/resources/OH-INF/thing/thing-types.xml

index 497d3024c36ce540b2af9d01b2f4d09f81f69995..903baf907e21e9d0f85bfbbf98d728a928bf7f20 100644 (file)
@@ -33,41 +33,42 @@ In order to assist you with this process the binding expose a simple login form
 
 ## Server Thing Configuration
 
-| Config   |  Type  | description                  |
-|----------|----------|------------------------------|
-| hostname | text | Hostname or IP address of the server (required) |
-| port | integer | Port of the server (required) |
-| ssl | boolean | Connect through https (required) |
-| refreshSeconds | integer | Interval to pull devices state from the server |
+| Config                    | Type    | description                                                                                  |
+|---------------------------|---------|----------------------------------------------------------------------------------------------|
+| hostname                  | text    | Hostname or IP address of the server (required)                                              |
+| port                      | integer | Port of the server (required)                                                                |
+| ssl                       | boolean | Connect through https (required)                                                             |
+| path                      | text    | Base path of the server                                                                      |
+| refreshSeconds            | integer | Interval to pull devices state from the server                                               |
 | clientActiveWithInSeconds | integer | Amount off seconds allowed since the last client activity to assert it's online (0 disabled) |
-| userId | text | The user id |
-| token | text | The user access token |
+| userId                    | text    | The user id                                                                                  |
+| token                     | text    | The user access token                                                                        |
 
 ## Channels
 
-| channel  | type   | description                  |
-|----------|--------|------------------------------|
-| send-notification  | String | Display message in client |
-| media-control  | Player | Control media playback |
-| playing-item-id  | String | Id of the item currently playing (readonly) |
-| playing-item-name  | String | Name of the item currently playing (readonly) |
-| playing-item-series-name  | String | Name of the item's series currently playing, only have value when item is an episode (readonly) |
-| playing-item-season-name  | String | Name of the item's season currently playing, only have value when item is an episode (readonly) |
-| playing-item-season  | Number | Number of the item's season currently playing, only have value when item is an episode (readonly) |
-| playing-item-episode  | Number | Number of the episode item currently playing, only have value when item is an episode (readonly) |
-| playing-item-genders  | String | Coma separate list genders of the item currently playing (readonly) |
-| playing-item-type  | String | Type of the item currently playing (readonly) |
-| playing-item-percentage  | Dimmer | Played percentage for the item currently playing, allow seek |
-| playing-item-second  | Number | Current second for the item currently playing, allow seek |
-| playing-item-total-seconds  | Number | Total seconds for the item currently playing (readonly) |
-| play-by-terms  | String | Play media by terms, works for series, episodes and movies; terms search is explained bellow |
-| play-next-by-terms  | String | Add to playback queue as next by terms, works for series, episodes and movies; terms search is explained bellow |
-| play-last-by-terms  | String | Add to playback queue as last by terms, works for series, episodes and movies; terms search is explained bellow |
-| browse-by-terms  | String | Browse media by terms, works for series, episodes and movies; terms search is explained bellow |
-| play-by-id  | String | Play media by id, works for series, episodes and movies; id search is explained bellow |
-| play-next-by-id  | String | Add to playback queue as next by id, works for series, episodes and movies |
-| play-last-by-id  | String | Add to playback queue as last by id, works for series, episodes and movies |
-| browse-by-id  | String | Browse media by id, works for series, episodes and movies |
+| channel                    | type   | description                                                                                                     |
+|----------------------------|--------|-----------------------------------------------------------------------------------------------------------------|
+| send-notification          | String | Display message in client                                                                                       |
+| media-control              | Player | Control media playback                                                                                          |
+| playing-item-id            | String | Id of the item currently playing (readonly)                                                                     |
+| playing-item-name          | String | Name of the item currently playing (readonly)                                                                   |
+| playing-item-series-name   | String | Name of the item's series currently playing, only have value when item is an episode (readonly)                 |
+| playing-item-season-name   | String | Name of the item's season currently playing, only have value when item is an episode (readonly)                 |
+| playing-item-season        | Number | Number of the item's season currently playing, only have value when item is an episode (readonly)               |
+| playing-item-episode       | Number | Number of the episode item currently playing, only have value when item is an episode (readonly)                |
+| playing-item-genders       | String | Coma separate list genders of the item currently playing (readonly)                                             |
+| playing-item-type          | String | Type of the item currently playing (readonly)                                                                   |
+| playing-item-percentage    | Dimmer | Played percentage for the item currently playing, allow seek                                                    |
+| playing-item-second        | Number | Current second for the item currently playing, allow seek                                                       |
+| playing-item-total-seconds | Number | Total seconds for the item currently playing (readonly)                                                         |
+| play-by-terms              | String | Play media by terms, works for series, episodes and movies; terms search is explained bellow                    |
+| play-next-by-terms         | String | Add to playback queue as next by terms, works for series, episodes and movies; terms search is explained bellow |
+| play-last-by-terms         | String | Add to playback queue as last by terms, works for series, episodes and movies; terms search is explained bellow |
+| browse-by-terms            | String | Browse media by terms, works for series, episodes and movies; terms search is explained bellow                  |
+| play-by-id                 | String | Play media by id, works for series, episodes and movies; id search is explained bellow                          |
+| play-next-by-id            | String | Add to playback queue as next by id, works for series, episodes and movies                                      |
+| play-last-by-id            | String | Add to playback queue as last by id, works for series, episodes and movies                                      |
+| browse-by-id               | String | Browse media by id, works for series, episodes and movies                                                       |
 ### Terms search:
 
 The terms search has a default behavior that can be modified sending some predefined prefixes.
index bedee67e2de6ea0f7093c02c724ceadb130e81dd..2099ea37b441ce5bb873042389a96f3699f91e99 100644 (file)
@@ -33,6 +33,10 @@ public class JellyfinServerConfiguration {
      * Use Https
      */
     public Boolean ssl = true;
+    /**
+     * Jellyfin base url
+     */
+    public String path = "";
     /**
      * Interval to pull devices state from the server
      */
index 0b98976db484706829d9ec51285ab8f74e845105..6d4490a4ec076808cf76a11070eae4a87bd2fd44 100644 (file)
@@ -107,19 +107,22 @@ public class JellyfinServerDiscoveryService extends AbstractDiscoveryService {
         new SystemApi(jellyClient).getPublicSystemInfo(asyncResponse);
         try {
             var publicSystemInfo = asyncResponse.awaitContent();
-            discoverServer(uri.getHost(), uri.getPort(), uri.getScheme().equalsIgnoreCase("https"), publicSystemInfo);
+            discoverServer(uri.getHost(), uri.getPort(), uri.getScheme().equalsIgnoreCase("https"), uri.getPath(),
+                    publicSystemInfo);
         } catch (SyncCallback.SyncCallbackError | ApiClientException e) {
             logger.warn("Discovery error: {}", e.getMessage());
         }
     }
 
-    private void discoverServer(String hostname, int port, boolean ssl, PublicSystemInfo publicSystemInfo) {
+    private void discoverServer(String hostname, int port, boolean ssl, String path,
+            PublicSystemInfo publicSystemInfo) {
         logger.debug("Server discovered: [{}:{}] {}", hostname, port, publicSystemInfo.getServerName());
         var id = Objects.requireNonNull(publicSystemInfo.getId());
         Map<String, Object> properties = new HashMap<>();
         properties.put("hostname", hostname);
         properties.put("port", port);
         properties.put("ssl", ssl);
+        properties.put("path", path);
         properties.put(Thing.PROPERTY_SERIAL_NUMBER, id);
         var productName = publicSystemInfo.getProductName();
         if (productName != null) {
index 2172001facb7ada06bf17c5eed4f616330dd2e4e..ddaed96b2c978b31b66eed00fecf9020932e91bb 100644 (file)
@@ -65,6 +65,9 @@ import org.openhab.core.types.Command;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import io.ktor.http.URLBuilder;
+import io.ktor.http.URLProtocol;
+
 /**
  * The {@link JellyfinServerHandler} is responsible for handling commands, which are
  * sent to one of the channels.
@@ -119,7 +122,16 @@ public class JellyfinServerHandler extends BaseBridgeHandler {
     }
 
     public String getServerUrl() {
-        return (config.ssl ? "https" : "http") + "://" + config.hostname + ":" + config.port;
+        var builder = new URLBuilder();
+        builder.setHost(config.hostname);
+        if (config.ssl) {
+            builder.setProtocol(URLProtocol.Companion.getHTTPS());
+        } else {
+            builder.setProtocol(URLProtocol.Companion.getHTTP());
+        }
+        builder.setPort(config.port);
+        builder.setEncodedPath(config.path);
+        return builder.buildString();
     }
 
     public boolean isOnline() {
index 5ffb84755e18b7f192af873422cf4e82629a6dd0..b564f966dce348e5670cbba98b5925af10ce20e9 100644 (file)
@@ -18,6 +18,8 @@ thing-type.config.jellyfin.server.hostname.label = Hostname/IP
 thing-type.config.jellyfin.server.hostname.description = Hostname or IP address of the server
 thing-type.config.jellyfin.server.port.label = Port
 thing-type.config.jellyfin.server.port.description = Port of the server
+thing-type.config.jellyfin.server.path.label = Base Path
+thing-type.config.jellyfin.server.path.description = Base path of the server
 thing-type.config.jellyfin.server.refreshSeconds.label = Refresh Seconds
 thing-type.config.jellyfin.server.refreshSeconds.description = Interval to pull devices state from the server
 thing-type.config.jellyfin.server.ssl.label = SSL
index 3147794e252f06e982b738501cc2942d8b7b156d..caa26edeed3e01e3d6a9928a6f6e9c45634bad6b 100644 (file)
                                <description>Connect through https</description>
                                <default>false</default>
                        </parameter>
+                       <parameter name="path" type="text" required="false">
+                               <label>Base Path</label>
+                               <description>Base path of the server</description>
+                       </parameter>
                        <parameter name="refreshSeconds" type="integer" min="10" max="300" required="true">
                                <label>Refresh Seconds</label>
                                <description>Interval to pull devices state from the server</description>