Skip to content

Commit

Permalink
0.4.2
Browse files Browse the repository at this point in the history
- check connection to PMS in server detection
  • Loading branch information
pannal committed Mar 9, 2021
1 parent 1c9ccb9 commit 99c3be6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.4.2
- check connection to PMS in server detection

0.4.1
- handle plugin errors more explicitly
- try to avoid TooManyRedirects
Expand Down
23 changes: 20 additions & 3 deletions kitana.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import io
import platform
import socket

import cherrypy
import requests
import xmltodict
Expand Down Expand Up @@ -61,7 +63,7 @@ def maintenance():

class Kitana(object):
PRODUCT_IDENTIFIER = "Kitana"
VERSION = "0.4.1"
VERSION = "0.4.2"
CLIENT_IDENTIFIER_BASE = "{}_{}".format(PRODUCT_IDENTIFIER, VERSION)
initialized = False
timeout = 5
Expand Down Expand Up @@ -430,6 +432,22 @@ def discover_pms(self, server_name=None, server_addr=None, blacklist_addr=None):
connection["unavailable"] = True
continue

try:
socket.create_connection((connection["address"], connection["port"]), timeout=self.timeout)
except OSError:
print("{}: {} Skipping unreachable connection".format(mask_str(device["name"]),
mask_url(connection["uri"])))
continue
else:
print("{}: {} Socket Connection successful".format(mask_str(device["name"]),
mask_url(connection["uri"])))
try:
self.session.get(connection["uri"] + "/servers", headers=self.full_headers, **self.req_defaults)
except:
print("{}: {} Skipping unreachable connection (2)".format(mask_str(device["name"]),
mask_url(connection["uri"])))
traceback.print_exc()

servers[device["name"]]["connections"].append(connection)
if server_name and server_name == device["name"]:
if server_addr and connection["uri"] == server_addr:
Expand All @@ -452,7 +470,6 @@ def discover_pms(self, server_name=None, server_addr=None, blacklist_addr=None):
server_addr = use_connection["uri"]

print("Server set to: {}, {}".format(mask_str(server_name), mask_url(server_addr)))
print("Verifying {}: {}".format(mask_str(server_name), mask_url(server_addr)))
try:
self.session.get(self.server_addr + "servers", headers=self.full_headers, **self.req_defaults)
except HTTPError as e:
Expand Down Expand Up @@ -733,7 +750,7 @@ def default(self, *args, **kwargs):
parser.add_argument('--shadow-assets', type=bool, default=not isWin32, metavar="BOOL", nargs="?", const=True,
help="Pass PMS assets through the app to avoid exposing the plex token? (default: {})"
.format(not isWin32))
parser.add_argument('-t', '--timeout', type=int, default=15,
parser.add_argument('-t', '--timeout', type=int, default=5,
help="Connection timeout to the PMS (default: 5)")
parser.add_argument('-pt', '--plextv-timeout', type=int, default=25,
help="Connection timeout to the Plex.TV API (default: 15)")
Expand Down
6 changes: 6 additions & 0 deletions static/sass/base.sass
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ $bgOpacity: opacity(30%)
#servers li, #plugins .plugin
cursor: pointer

&.no-click
background-color: $dark
cursor: default
&:hover
background-color: $dark

#plugins .plugin
img
max-width: 80px
Expand Down
7 changes: 5 additions & 2 deletions templates/servers.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block head %}
<script>
$(function () {
$('#servers li').on("click", function (e) {
$('#servers li:not(.no-click)').on("click", function (e) {
let $el = $(e.currentTarget), server_name = $el.data("server_name"),
server_addr = $el.data("server_addr");
if (server_name && server_addr) {
Expand All @@ -28,12 +28,15 @@
<div class="card-body">
<ul class="list-group list-group-flush">
{% for connection in data["connections"] %}
<li class="list-group-item" data-server_name="{{ server }}"
<li class="list-group-item{% if connection.NA %} no-click{% endif %}" data-server_name="{{ server }}"
data-server_addr="{% if connection.relay == "1" %}relay{% else %}{{ connection.uri }}{% endif %}">
{{ connection.address }}:{{ connection.port }}&nbsp;
{% if connection.unavailable %}
<span class="badge badge-warning">unavailable</span>
{% endif %}
{% if connection.NA %}
<span class="badge badge-danger">not connectable</span>
{% endif %}
{% if connection.local == "1" %}
<span class="badge badge-primary">local</span>
{% else %}
Expand Down

0 comments on commit 99c3be6

Please sign in to comment.