Skip to content

Commit

Permalink
fix: jellyfin test notification endpoint update (#8766)
Browse files Browse the repository at this point in the history
* fix: jellyfin test notification endpoint update

* refactor: remove private `_notify_jellyfin` and handle logic directly in `jellyfin.test_notify`

* Fix indentation

* Format Jellyfin

remove last line

---------

Co-authored-by: root <[email protected]>
Co-authored-by: miigotu <[email protected]>
Co-authored-by: BKSteve <[email protected]>
  • Loading branch information
4 people authored Jul 12, 2024
1 parent 177c0c7 commit 30991bb
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions sickchill/oldbeard/notifiers/jellyfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,33 @@ class Notifier(object):
def _make_headers(self, jellyfin_apikey=None):
return CaseInsensitiveDict({"X-Emby-Token": jellyfin_apikey or settings.JELLYFIN_APIKEY, "Content-Type": "application/json"})

def _notify_jellyfin(self, message, host=None, jellyfin_apikey=None):
"""Handles notifying Jellyfin host via HTTP API
##############################################################################
# Public functions
##############################################################################

def test_notify(self, host, jellyfin_apikey):
"""Handles testing Jellyfin connection via HTTP API
Returns:
Returns True for no issue or False if there was an error
"""
# https://api.jellyfin.org/#tag/Notifications/operation/CreateAdminNotification
url = urljoin(host or settings.JELLYFIN_HOST, "Notifications/Admin")
params = {"Name": "SickChill", "Description": message, "NotificationLevel": "Normal"}

if not settings.USE_JELLYFIN:
logger.debug("Notification for Jellyfin not enabled, skipping this notification")
return False

# https://api.jellyfin.org/#tag/System/operation/GetEndpointInfo
url = urljoin(host or settings.JELLYFIN_HOST, "System/Endpoint")

try:
response = requests.post(url, json=params, headers=self._make_headers(jellyfin_apikey))
response = requests.get(url, headers=self._make_headers(jellyfin_apikey))
if response:
logger.debug(_("JELLYFIN: HTTP response: {content}").format(content=response.content))
response.raise_for_status()

return True
except RequestException as error:
logger.warning(_("JELLYFIN: Warning: Could not contact Jellyfin at {url} {error}").format(url=url, error=error))
return False

##############################################################################
# Public functions
##############################################################################

def test_notify(self, host, jellyfin_apikey):
return self._notify_jellyfin(_("This is a test notification from SickChill"), host, jellyfin_apikey)

def update_library(self, show=None):
"""Handles updating the Jellyfin Media Server via HTTP API
Returns:
Expand Down Expand Up @@ -70,5 +66,4 @@ def update_library(self, show=None):

except requests.exceptions.RequestException as error:
logger.warning(_("JELLYFIN: Warning: Could not contact Jellyfin at {url} {error}").format(url=url, error=error))

return False

0 comments on commit 30991bb

Please sign in to comment.