Skip to content

Commit

Permalink
fix: split library check in two
Browse files Browse the repository at this point in the history
Split the library exists check and library id is valid check into two, because the library id may be null if the virtual folder is in a bad state in core Jellyfin, but the library may still exist in the UI.
  • Loading branch information
revam committed Oct 28, 2024
1 parent 001731c commit 52ee4c4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Shokofin/Configuration/MediaFolderConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,12 @@ public async Task<MediaFolderConfiguration> GetOrCreateConfigurationForMediaFold
await LockObj.WaitAsync();
try {
var allVirtualFolders = LibraryManager.GetVirtualFolders();
if (allVirtualFolders.FirstOrDefault(p => p.Locations.Contains(mediaFolder.Path) && (collectionType is CollectionType.unknown || p.CollectionType.ConvertToCollectionType() == collectionType)) is not { } library || !Guid.TryParse(library.ItemId, out var libraryId))
if (allVirtualFolders.FirstOrDefault(p => p.Locations.Contains(mediaFolder.Path) && (collectionType is CollectionType.unknown || p.CollectionType.ConvertToCollectionType() == collectionType)) is not { } library)
throw new Exception($"Unable to find any library to use for media folder \"{mediaFolder.Path}\"");

if (string.IsNullOrEmpty(library.ItemId) || !Guid.TryParse(library.ItemId, out var libraryId))
throw new Exception($"Unable to parse library id for library \"{library.Name}\" to use for media folder \"{mediaFolder.Path}\". This is not a plugin bug, but the media folder is missing from the default view in Jellyfin.");

if (ShouldGenerateAllConfigurations)
{
ShouldGenerateAllConfigurations = false;
Expand All @@ -302,10 +305,16 @@ private async Task GenerateAllConfigurations(List<VirtualFolderInfo> allVirtualF
{
var filteredVirtualFolders = allVirtualFolders
.Where(virtualFolder =>
virtualFolder is { ItemId: not null, LibraryOptions: { } } &&
virtualFolder.CollectionType.ConvertToCollectionType() is null or CollectionType.movies or CollectionType.tvshows &&
Lookup.IsEnabledForLibraryOptions(virtualFolder.LibraryOptions, out _)
)
{
if (virtualFolder is not { ItemId: not null, LibraryOptions: { } })
{
Logger.LogWarning("Skipping virtual folder {Name} because it has no ItemId or LibraryOptions.", virtualFolder.Name);
return false;
}

return virtualFolder.CollectionType.ConvertToCollectionType() is null or CollectionType.movies or CollectionType.tvshows &&
Lookup.IsEnabledForLibraryOptions(virtualFolder.LibraryOptions, out _);
})
.ToList();
Logger.LogDebug("Found {Count} out of {TotalCount} libraries to check media folder configurations for.", filteredVirtualFolders.Count, allVirtualFolders.Count);
var config = Plugin.Instance.Configuration;
Expand Down

0 comments on commit 52ee4c4

Please sign in to comment.