diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs index 978d178..e373670 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/SkipIntroController.cs @@ -154,7 +154,7 @@ public class SkipIntroController : ControllerBase { // Get the details of the item from Jellyfin var rawItem = Plugin.Instance.GetItem(intro.Key); - if (rawItem is not Episode episode) + if (rawItem == null || rawItem is not Episode episode) { throw new InvalidCastException("Unable to cast item id " + intro.Key + " to an Episode"); } diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs index 08b3a85..0048c12 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs @@ -140,6 +140,7 @@ public class VisualizationController : ControllerBase foreach (var e in episodes) { Plugin.Instance!.Intros.Remove(e.EpisodeId); + Plugin.Instance!.Credits.Remove(e.EpisodeId); } Plugin.Instance!.SaveTimestamps(); diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs index f111d2c..e4d83b6 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs @@ -351,7 +351,7 @@ public class Plugin : BasePlugin, IHasWebPages return commit; } - internal BaseItem GetItem(Guid id) + internal BaseItem? GetItem(Guid id) { return _libraryManager.GetItemById(id); } @@ -363,7 +363,15 @@ public class Plugin : BasePlugin, IHasWebPages /// Full path to item. internal string GetItemPath(Guid id) { - return GetItem(id).Path; + var item = GetItem(id); + if (item == null) + { + // Handle the case where the item is not found + _logger.LogWarning("Item with ID {Id} not found.", id); + return string.Empty; + } + + return item.Path; } /// @@ -373,7 +381,15 @@ public class Plugin : BasePlugin, IHasWebPages /// List of chapters. internal List GetChapters(Guid id) { - return _itemRepository.GetChapters(GetItem(id)); + var item = GetItem(id); + if (item == null) + { + // Handle the case where the item is not found + _logger.LogWarning("Item with ID {Id} not found.", id); + return new List(); + } + + return _itemRepository.GetChapters(item); } internal void UpdateTimestamps(Dictionary newTimestamps, AnalysisMode mode) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs index 05b8427..a407613 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/QueueManager.cs @@ -63,7 +63,15 @@ public class QueueManager { foreach (var location in folder.Locations) { - QueueLibraryContents(_libraryManager.FindByPath(location, true).Id); + var item = _libraryManager.FindByPath(location, true); + + if (item is null) + { + _logger.LogWarning("Unable to find linked item at path {0}", location); + continue; + } + + QueueLibraryContents(item.Id); } } catch (Exception ex)