refactor request host

This commit is contained in:
InfinityPacer
2024-06-19 15:51:57 +08:00
parent e1cdc51904
commit cb0bb8a38e
4 changed files with 42 additions and 29 deletions

View File

@ -18,16 +18,10 @@ class Emby:
def __init__(self):
self._host = settings.EMBY_HOST
if self._host:
if not self._host.endswith("/"):
self._host += "/"
if not self._host.startswith("http"):
self._host = "http://" + self._host
self._host = RequestUtils.standardize_base_url(self._host)
self._playhost = settings.EMBY_PLAY_HOST
if self._playhost:
if not self._playhost.endswith("/"):
self._playhost += "/"
if not self._playhost.startswith("http"):
self._playhost = "http://" + self._playhost
self._playhost = RequestUtils.standardize_base_url(self._playhost)
self._apikey = settings.EMBY_API_KEY
self.user = self.get_user(settings.SUPERUSER)
self.folders = self.get_emby_folders()

View File

@ -15,16 +15,10 @@ class Jellyfin:
def __init__(self):
self._host = settings.JELLYFIN_HOST
if self._host:
if not self._host.endswith("/"):
self._host += "/"
if not self._host.startswith("http"):
self._host = "http://" + self._host
self._host = RequestUtils.standardize_base_url(self._host)
self._playhost = settings.JELLYFIN_PLAY_HOST
if self._playhost:
if not self._playhost.endswith("/"):
self._playhost += "/"
if not self._playhost.startswith("http"):
self._playhost = "http://" + self._playhost
self._playhost = RequestUtils.standardize_base_url(self._playhost)
self._apikey = settings.JELLYFIN_API_KEY
self.user = self.get_user(settings.SUPERUSER)
self.serverid = self.get_server_id()

View File

@ -11,6 +11,7 @@ from app import schemas
from app.core.config import settings
from app.log import logger
from app.schemas import MediaType
from app.utils.http import RequestUtils
class Plex:
@ -19,16 +20,10 @@ class Plex:
def __init__(self):
self._host = settings.PLEX_HOST
if self._host:
if not self._host.endswith("/"):
self._host += "/"
if not self._host.startswith("http"):
self._host = "http://" + self._host
self._host = RequestUtils.standardize_base_url(self._host)
self._playhost = settings.PLEX_PLAY_HOST
if self._playhost:
if not self._playhost.endswith("/"):
self._playhost += "/"
if not self._playhost.startswith("http"):
self._playhost = "http://" + self._playhost
self._playhost = RequestUtils.standardize_base_url(self._playhost)
self._token = settings.PLEX_TOKEN
if self._host and self._token:
try: