From 3e2dcc3e5b807c12c7ef158e9c8ee4d322fda620 Mon Sep 17 00:00:00 2001 From: Kyuuk <16566073+kyuuk@users.noreply.github.com> Date: Mon, 18 Mar 2024 07:50:49 +0100 Subject: [PATCH] Emby notification : upgrade library_update to latests api endpoints (#8736) * use endpoint /media/updated with path param to refresh only needed show instead of full library scan * Propose alternate solution * Propose alternate solution part2 * Revert "Propose alternate solutions" * Fix Emby /media/updated endpoint payload --------- Co-authored-by: BKSteve --- sickchill/oldbeard/notifiers/emby.py | 38 +++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/sickchill/oldbeard/notifiers/emby.py b/sickchill/oldbeard/notifiers/emby.py index afc75f2ae5..e7a5b23b8b 100644 --- a/sickchill/oldbeard/notifiers/emby.py +++ b/sickchill/oldbeard/notifiers/emby.py @@ -36,6 +36,28 @@ def _notify_emby(self, message, host=None, emby_apikey=None): logger.warning(_("EMBY: Warning: Could not contact Emby at {url} {error}").format(url=url, error=error)) return False + def _get_show_path(self, tvdbid): + """Get a show path in Emby library using Items endpoint + + Returns: + The show path in Emby or empty + + """ + get_path_params = {"Recursive": "true", "Fields": "Path", "IncludeItemTypes": "Series"} + url = urljoin(settings.EMBY_HOST, "/Items") + try: + get_path_params.update({"AnyProviderIdEquals": "tvdb.{id}".format(id=tvdbid)}) + items_response = requests.get(url, params=get_path_params, headers=self._make_headers()) + items_response.raise_for_status() + if items_response.json()["TotalRecordCount"] == 1: + return items_response.json()["Items"][0]["Path"] + else: + return "" + + except requests.exceptions.RequestException as error: + logger.warning(_("EMBY: Warning: Could not contact Emby at {url} {error}").format(url=url, error=error)) + return None + ############################################################################## # Public functions ############################################################################## @@ -55,12 +77,20 @@ def update_library(self, show=None): if not settings.EMBY_HOST: logger.debug(_("EMBY: No host specified, check your settings")) return False - params = {} - url = urljoin(settings.EMBY_HOST, "emby/Library/Refresh") - try: - response = requests.post(url, params=params, headers=self._make_headers()) + if show: + path = self._get_show_path(show.indexerid) + if path: + url = urljoin(settings.EMBY_HOST, "emby/Library/Media/Updated") + params.update({"Updates": {"Path": path, "UpdateType": "Created"}}) + else: + url = urljoin(settings.EMBY_HOST, "emby/Library/Refresh") + else: + url = urljoin(settings.EMBY_HOST, "emby/Library/Refresh") + + response = requests.post(url, json=params, headers=self._make_headers()) + response.raise_for_status() logger.debug(_("EMBY: HTTP status: {status_code}, response: {content}").format(status_code=response.status_code, content=response.content)) return True