From 2fee654efee09eac192babc57a0d9224fa61d3ee Mon Sep 17 00:00:00 2001 From: wolffshots <16850875+wolffshots@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:28:50 +0200 Subject: [PATCH] chore: wrap itemYTId stuff in try catch --- .../Plugin.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs index 2dfac7f..cbb48e4 100644 --- a/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs +++ b/Jellyfin.Plugin.TubeArchivistMetadata/Plugin.cs @@ -178,17 +178,25 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata var isPlayed = eventArgs.Item.IsPlayed(user); Logger.LogDebug("User {UserId} changed watched status to {Status} for the item {ItemName}", eventArgs.UserId, isPlayed, eventArgs.Item.Name); string itemYTId; - if (eventArgs.Item is Series) + try { - itemYTId = Utils.GetChannelNameFromPath(eventArgs.Item.Path); + if (eventArgs.Item is Series) + { + itemYTId = Utils.GetChannelNameFromPath(eventArgs.Item.Path); + } + else if (eventArgs.Item is Episode) + { + itemYTId = Utils.GetVideoNameFromPath(eventArgs.Item.Path); // Potentially problematic line for Series + } + else + { + return; + } } - else if (eventArgs.Item is Episode) + catch (Exception ex) { - itemYTId = Utils.GetVideoNameFromPath(eventArgs.Item.Path); - } - else - { - return; + Logger.LogError(ex, "Error while processing item path: {ItemPath}", eventArgs.Item.Path ?? "null"); + return; // Exit the method if there's an error } var statusCode = await TubeArchivistApi.GetInstance().SetWatchedStatus(itemYTId, isPlayed).ConfigureAwait(true);