Change GetItem to return null to handle nullable LibraryManager (#137)

This commit is contained in:
rlauuzo 2024-05-01 13:45:57 +02:00 committed by TwistedUmbrellaX
parent fd3cf0c075
commit d1a4cacb8b
4 changed files with 31 additions and 6 deletions

View File

@ -153,8 +153,8 @@ public class SkipIntroController : ControllerBase
foreach (var intro in timestamps) foreach (var intro in timestamps)
{ {
// Get the details of the item from Jellyfin // Get the details of the item from Jellyfin
var rawItem = Plugin.Instance!.GetItem(intro.Key); 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"); throw new InvalidCastException("Unable to cast item id " + intro.Key + " to an Episode");
} }

View File

@ -140,6 +140,7 @@ public class VisualizationController : ControllerBase
foreach (var e in episodes) foreach (var e in episodes)
{ {
Plugin.Instance!.Intros.Remove(e.EpisodeId); Plugin.Instance!.Intros.Remove(e.EpisodeId);
Plugin.Instance!.Credits.Remove(e.EpisodeId);
} }
Plugin.Instance!.SaveTimestamps(); Plugin.Instance!.SaveTimestamps();

View File

@ -306,7 +306,7 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
return commit; return commit;
} }
internal BaseItem GetItem(Guid id) internal BaseItem? GetItem(Guid id)
{ {
return _libraryManager.GetItemById(id); return _libraryManager.GetItemById(id);
} }
@ -318,7 +318,15 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
/// <returns>Full path to item.</returns> /// <returns>Full path to item.</returns>
internal string GetItemPath(Guid id) 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;
} }
/// <summary> /// <summary>
@ -328,7 +336,15 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
/// <returns>List of chapters.</returns> /// <returns>List of chapters.</returns>
internal List<ChapterInfo> GetChapters(Guid id) internal List<ChapterInfo> 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<ChapterInfo>();
}
return _itemRepository.GetChapters(item);
} }
internal void UpdateTimestamps(Dictionary<Guid, Intro> newTimestamps, AnalysisMode mode) internal void UpdateTimestamps(Dictionary<Guid, Intro> newTimestamps, AnalysisMode mode)

View File

@ -63,7 +63,15 @@ public class QueueManager
{ {
foreach (var location in folder.Locations) 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) catch (Exception ex)