Jellyfin Login ✓
This commit is contained in:
@@ -20,6 +20,7 @@ import csv
|
||||
import json
|
||||
import linecache
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import threading
|
||||
@@ -30,7 +31,6 @@ from urllib.parse import urlencode
|
||||
import cherrypy
|
||||
import mako.exceptions
|
||||
import mako.template
|
||||
import websocket
|
||||
from cherrypy import NotFound
|
||||
from cherrypy.lib.static import serve_file, serve_fileobj, serve_download
|
||||
from mako.lookup import TemplateLookup
|
||||
@@ -57,6 +57,7 @@ from jellypy import versioncheck
|
||||
from jellypy import webstart
|
||||
from jellypy.api2 import API2
|
||||
from jellypy.helpers import checked, addtoapi, create_https_certificates, build_datatables_json, sanitize_out
|
||||
from jellypy.jellyfin import Jellyfin
|
||||
from jellypy.password import make_hash
|
||||
from jellypy.session import get_session_info, get_session_user_id, allow_session_user, allow_session_library
|
||||
from jellypy.webauth import AuthController, requireAuth, member_of, check_auth
|
||||
@@ -4035,14 +4036,16 @@ class WebInterface(object):
|
||||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def get_server_id(self, hostname=None, port=None, identifier=None, ssl=0, remote=0, manual=0,
|
||||
get_url=False, test_websocket=False, **kwargs):
|
||||
""" Get the JELLYFIN server identifier.
|
||||
def check_login(self, hostname=None, port=None, ssl=0, remote=0, manual=0, user=None, password=None,
|
||||
get_url=False, test_websocket=False, **kwargs):
|
||||
""" Try Jellyfin Login.
|
||||
|
||||
```
|
||||
Required parameters:
|
||||
hostname (str): 'localhost' or '192.160.0.10'
|
||||
port (int): 32400
|
||||
port (int): 8096
|
||||
user (str): Jellyfin user
|
||||
password (str): Jellyfin password
|
||||
|
||||
Optional parameters:
|
||||
ssl (int): 0 or 1
|
||||
@@ -4054,66 +4057,54 @@ class WebInterface(object):
|
||||
```
|
||||
"""
|
||||
# Attempt to get the pms_identifier from plex.tv if the server is published
|
||||
# Works for all JELLYFIN SSL settings
|
||||
if not identifier and hostname and port:
|
||||
pass
|
||||
# TODO: Jellyfin
|
||||
# plex_tv = plextv.PlexTV()
|
||||
# servers = plex_tv.discover()
|
||||
# ip_address = get_ip(hostname)
|
||||
# Works for all Jellyfin SSL settings
|
||||
result = {"identifier": None}
|
||||
if hostname and port and user and password:
|
||||
path_regex = re.compile("^(https?://)?([^/:]+)(:[0-9]+)?(/.*)?$")
|
||||
|
||||
protocol, host, port, path = path_regex.match(hostname + ":" + port).groups()
|
||||
|
||||
if not protocol:
|
||||
protocol = "http://"
|
||||
|
||||
if protocol == "http://" and not port:
|
||||
port = "8096"
|
||||
|
||||
server = "".join(filter(bool, (protocol, host, port, path)))
|
||||
|
||||
jf = Jellyfin(server)
|
||||
if jf.login(user, password):
|
||||
result = {'identifier': jf.id}
|
||||
|
||||
# if identifier:
|
||||
# if helpers.bool_true(get_url):
|
||||
# server = self.get_server_resources(jellyfin_ip=hostname,
|
||||
# jellyfin_port=port,
|
||||
# jellyfin_ssl=ssl,
|
||||
# jellyfin_is_remote=remote,
|
||||
# jellyfin_url_manual=manual,
|
||||
# jellyfin_identifier=identifier)
|
||||
# result['url'] = server['jellyfin_url']
|
||||
# result['ws'] = None
|
||||
#
|
||||
# for server in servers:
|
||||
# if (server['ip'] == hostname or server['ip'] == ip_address) and server['port'] == port:
|
||||
# identifier = server['clientIdentifier']
|
||||
# break
|
||||
# if helpers.bool_true(test_websocket):
|
||||
# # Quick test websocket connection
|
||||
# ws_url = result['url'].replace('http', 'ws', 1) + '/:/websockets/notifications'
|
||||
# header = ['X-Plex-Token: %s' % jellypy.CONFIG.JELLYFIN_TOKEN]
|
||||
#
|
||||
# # Fallback to checking /identity endpoint if the server is unpublished
|
||||
# # Cannot set SSL settings on the JELLYFIN if unpublished so 'http' is okay
|
||||
# if not identifier:
|
||||
# scheme = 'https' if helpers.cast_to_int(ssl) else 'http'
|
||||
# url = '{scheme}://{hostname}:{port}'.format(scheme=scheme, hostname=hostname, port=port)
|
||||
# uri = '/identity'
|
||||
#
|
||||
# request_handler = http_handler.HTTPHandler(urls=url,
|
||||
# ssl_verify=False)
|
||||
# request = request_handler.make_request(uri=uri,
|
||||
# request_type='GET',
|
||||
# output_format='xml')
|
||||
# if request:
|
||||
# xml_head = request.getElementsByTagName('MediaContainer')[0]
|
||||
# identifier = xml_head.getAttribute('machineIdentifier')
|
||||
|
||||
result = {'identifier': identifier}
|
||||
|
||||
if identifier:
|
||||
if helpers.bool_true(get_url):
|
||||
server = self.get_server_resources(jellyfin_ip=hostname,
|
||||
jellyfin_port=port,
|
||||
jellyfin_ssl=ssl,
|
||||
jellyfin_is_remote=remote,
|
||||
jellyfin_url_manual=manual,
|
||||
jellyfin_identifier=identifier)
|
||||
result['url'] = server['jellyfin_url']
|
||||
result['ws'] = None
|
||||
|
||||
if helpers.bool_true(test_websocket):
|
||||
# Quick test websocket connection
|
||||
ws_url = result['url'].replace('http', 'ws', 1) + '/:/websockets/notifications'
|
||||
header = ['X-Plex-Token: %s' % jellypy.CONFIG.JELLYFIN_TOKEN]
|
||||
|
||||
logger.debug("Testing websocket connection...")
|
||||
try:
|
||||
test_ws = websocket.create_connection(ws_url, header=header)
|
||||
test_ws.close()
|
||||
logger.debug("Websocket connection test successful.")
|
||||
result['ws'] = True
|
||||
except (websocket.WebSocketException, IOError, Exception) as e:
|
||||
logger.error("Websocket connection test failed: %s" % e)
|
||||
result['ws'] = False
|
||||
# logger.debug("Testing websocket connection...")
|
||||
# try:
|
||||
# test_ws = websocket.create_connection(ws_url, header=header)
|
||||
# test_ws.close()
|
||||
# logger.debug("Websocket connection test successful.")
|
||||
# result['ws'] = True
|
||||
# except (websocket.WebSocketException, IOError, Exception) as e:
|
||||
# logger.error("Websocket connection test failed: %s" % e)
|
||||
# result['ws'] = False
|
||||
|
||||
return result
|
||||
else:
|
||||
logger.warn('Unable to retrieve the JELLYFIN identifier.')
|
||||
logger.warn('Unable to retrieve the Jellyfin identifier.')
|
||||
return result
|
||||
|
||||
@cherrypy.expose
|
||||
@@ -4480,8 +4471,8 @@ class WebInterface(object):
|
||||
|
||||
@addtoapi('jellyfin_image_proxy')
|
||||
def real_jellyfin_image_proxy(self, img=None, rating_key=None, width=750, height=1000,
|
||||
opacity=100, background='000000', blur=0, img_format='png',
|
||||
fallback=None, refresh=False, clip=False, **kwargs):
|
||||
opacity=100, background='000000', blur=0, img_format='png',
|
||||
fallback=None, refresh=False, clip=False, **kwargs):
|
||||
""" Gets an image from the JELLYFIN and saves it to the image cache directory.
|
||||
|
||||
```
|
||||
|
Reference in New Issue
Block a user