aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/LibraryManager.cs
diff options
context:
space:
mode:
authorCody Robibero <cody@robibe.ro>2023-11-09 22:03:55 -0700
committerGitHub <noreply@github.com>2023-11-09 22:03:55 -0700
commit892973a9e372000ad7babe2381e4e83b39591951 (patch)
treefc408136c09e6377309629ad6b2d4b2b26ff3c3f /Emby.Server.Implementations/Library/LibraryManager.cs
parent35bd0c00c965176d6ddb167605ed3a3eba9a4524 (diff)
parent44b771bfb4b6412360b18c80621c90902c0a43a7 (diff)
Merge branch 'master' into media-type
Diffstat (limited to 'Emby.Server.Implementations/Library/LibraryManager.cs')
-rw-r--r--Emby.Server.Implementations/Library/LibraryManager.cs79
1 files changed, 42 insertions, 37 deletions
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs
index ce8b1f918..f40177fa7 100644
--- a/Emby.Server.Implementations/Library/LibraryManager.cs
+++ b/Emby.Server.Implementations/Library/LibraryManager.cs
@@ -525,14 +525,14 @@ namespace Emby.Server.Implementations.Library
IDirectoryService directoryService,
IItemResolver[] resolvers,
Folder parent = null,
- string collectionType = null,
+ CollectionType? collectionType = null,
LibraryOptions libraryOptions = null)
{
ArgumentNullException.ThrowIfNull(fileInfo);
var fullPath = fileInfo.FullName;
- if (string.IsNullOrEmpty(collectionType) && parent is not null)
+ if (collectionType is null && parent is not null)
{
collectionType = GetContentTypeOverride(fullPath, true);
}
@@ -635,7 +635,7 @@ namespace Emby.Server.Implementations.Library
return !args.ContainsFileSystemEntryByName(".ignore");
}
- public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files, IDirectoryService directoryService, Folder parent, LibraryOptions libraryOptions, string collectionType = null)
+ public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files, IDirectoryService directoryService, Folder parent, LibraryOptions libraryOptions, CollectionType? collectionType = null)
{
return ResolvePaths(files, directoryService, parent, libraryOptions, collectionType, EntityResolvers);
}
@@ -645,7 +645,7 @@ namespace Emby.Server.Implementations.Library
IDirectoryService directoryService,
Folder parent,
LibraryOptions libraryOptions,
- string collectionType,
+ CollectionType? collectionType,
IItemResolver[] resolvers)
{
var fileList = files.Where(i => !IgnoreFile(i, parent)).ToList();
@@ -675,7 +675,7 @@ namespace Emby.Server.Implementations.Library
IReadOnlyList<FileSystemMetadata> fileList,
IDirectoryService directoryService,
Folder parent,
- string collectionType,
+ CollectionType? collectionType,
IItemResolver[] resolvers,
LibraryOptions libraryOptions)
{
@@ -1514,7 +1514,7 @@ namespace Emby.Server.Implementations.Library
{
if (item is UserView view)
{
- if (string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.Ordinal))
+ if (view.ViewType == CollectionType.LiveTv)
{
return new[] { view.Id };
}
@@ -1543,13 +1543,13 @@ namespace Emby.Server.Implementations.Library
}
// Handle grouping
- if (user is not null && !string.IsNullOrEmpty(view.ViewType) && UserView.IsEligibleForGrouping(view.ViewType)
+ if (user is not null && view.ViewType != CollectionType.Unknown && UserView.IsEligibleForGrouping(view.ViewType)
&& user.GetPreference(PreferenceKind.GroupedFolders).Length > 0)
{
return GetUserRootFolder()
.GetChildren(user, true)
.OfType<CollectionFolder>()
- .Where(i => string.IsNullOrEmpty(i.CollectionType) || string.Equals(i.CollectionType, view.ViewType, StringComparison.OrdinalIgnoreCase))
+ .Where(i => i.CollectionType is null || i.CollectionType == view.ViewType)
.Where(i => user.IsFolderGrouped(i.Id))
.SelectMany(i => GetTopParentIdsForQuery(i, user));
}
@@ -1678,7 +1678,7 @@ namespace Emby.Server.Implementations.Library
/// <param name="sortBy">The sort by.</param>
/// <param name="sortOrder">The sort order.</param>
/// <returns>IEnumerable{BaseItem}.</returns>
- public IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<string> sortBy, SortOrder sortOrder)
+ public IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<ItemSortBy> sortBy, SortOrder sortOrder)
{
var isFirst = true;
@@ -1701,7 +1701,7 @@ namespace Emby.Server.Implementations.Library
return orderedItems ?? items;
}
- public IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<(string OrderBy, SortOrder SortOrder)> orderBy)
+ public IEnumerable<BaseItem> Sort(IEnumerable<BaseItem> items, User user, IEnumerable<(ItemSortBy OrderBy, SortOrder SortOrder)> orderBy)
{
var isFirst = true;
@@ -1736,9 +1736,9 @@ namespace Emby.Server.Implementations.Library
/// <param name="name">The name.</param>
/// <param name="user">The user.</param>
/// <returns>IBaseItemComparer.</returns>
- private IBaseItemComparer GetComparer(string name, User user)
+ private IBaseItemComparer GetComparer(ItemSortBy name, User user)
{
- var comparer = Comparers.FirstOrDefault(c => string.Equals(name, c.Name, StringComparison.OrdinalIgnoreCase));
+ var comparer = Comparers.FirstOrDefault(c => name == c.Type);
// If it requires a user, create a new one, and assign the user
if (comparer is IUserBaseItemComparer)
@@ -2065,16 +2065,16 @@ namespace Emby.Server.Implementations.Library
: collectionFolder.GetLibraryOptions();
}
- public string GetContentType(BaseItem item)
+ public CollectionType? GetContentType(BaseItem item)
{
- string configuredContentType = GetConfiguredContentType(item, false);
- if (!string.IsNullOrEmpty(configuredContentType))
+ var configuredContentType = GetConfiguredContentType(item, false);
+ if (configuredContentType is not null)
{
return configuredContentType;
}
configuredContentType = GetConfiguredContentType(item, true);
- if (!string.IsNullOrEmpty(configuredContentType))
+ if (configuredContentType is not null)
{
return configuredContentType;
}
@@ -2082,31 +2082,31 @@ namespace Emby.Server.Implementations.Library
return GetInheritedContentType(item);
}
- public string GetInheritedContentType(BaseItem item)
+ public CollectionType? GetInheritedContentType(BaseItem item)
{
var type = GetTopFolderContentType(item);
- if (!string.IsNullOrEmpty(type))
+ if (type is not null)
{
return type;
}
return item.GetParents()
.Select(GetConfiguredContentType)
- .LastOrDefault(i => !string.IsNullOrEmpty(i));
+ .LastOrDefault(i => i is not null);
}
- public string GetConfiguredContentType(BaseItem item)
+ public CollectionType? GetConfiguredContentType(BaseItem item)
{
return GetConfiguredContentType(item, false);
}
- public string GetConfiguredContentType(string path)
+ public CollectionType? GetConfiguredContentType(string path)
{
return GetContentTypeOverride(path, false);
}
- public string GetConfiguredContentType(BaseItem item, bool inheritConfiguredPath)
+ public CollectionType? GetConfiguredContentType(BaseItem item, bool inheritConfiguredPath)
{
if (item is ICollectionFolder collectionFolder)
{
@@ -2116,16 +2116,21 @@ namespace Emby.Server.Implementations.Library
return GetContentTypeOverride(item.ContainingFolderPath, inheritConfiguredPath);
}
- private string GetContentTypeOverride(string path, bool inherit)
+ private CollectionType? GetContentTypeOverride(string path, bool inherit)
{
var nameValuePair = _configurationManager.Configuration.ContentTypes
.FirstOrDefault(i => _fileSystem.AreEqual(i.Name, path)
|| (inherit && !string.IsNullOrEmpty(i.Name)
&& _fileSystem.ContainsSubPath(i.Name, path)));
- return nameValuePair?.Value;
+ if (Enum.TryParse<CollectionType>(nameValuePair?.Value, out var collectionType))
+ {
+ return collectionType;
+ }
+
+ return null;
}
- private string GetTopFolderContentType(BaseItem item)
+ private CollectionType? GetTopFolderContentType(BaseItem item)
{
if (item is null)
{
@@ -2147,13 +2152,13 @@ namespace Emby.Server.Implementations.Library
.OfType<ICollectionFolder>()
.Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path))
.Select(i => i.CollectionType)
- .FirstOrDefault(i => !string.IsNullOrEmpty(i));
+ .FirstOrDefault(i => i is not null);
}
public UserView GetNamedView(
User user,
string name,
- string viewType,
+ CollectionType? viewType,
string sortName)
{
return GetNamedView(user, name, Guid.Empty, viewType, sortName);
@@ -2161,13 +2166,13 @@ namespace Emby.Server.Implementations.Library
public UserView GetNamedView(
string name,
- string viewType,
+ CollectionType viewType,
string sortName)
{
var path = Path.Combine(
_configurationManager.ApplicationPaths.InternalMetadataPath,
"views",
- _fileSystem.GetValidFilename(viewType));
+ _fileSystem.GetValidFilename(viewType.ToString()));
var id = GetNewItemId(path + "_namedview_" + name, typeof(UserView));
@@ -2207,13 +2212,13 @@ namespace Emby.Server.Implementations.Library
User user,
string name,
Guid parentId,
- string viewType,
+ CollectionType? viewType,
string sortName)
{
var parentIdString = parentId.Equals(default)
? null
: parentId.ToString("N", CultureInfo.InvariantCulture);
- var idValues = "38_namedview_" + name + user.Id.ToString("N", CultureInfo.InvariantCulture) + (parentIdString ?? string.Empty) + (viewType ?? string.Empty);
+ var idValues = "38_namedview_" + name + user.Id.ToString("N", CultureInfo.InvariantCulture) + (parentIdString ?? string.Empty) + (viewType?.ToString() ?? string.Empty);
var id = GetNewItemId(idValues, typeof(UserView));
@@ -2269,7 +2274,7 @@ namespace Emby.Server.Implementations.Library
public UserView GetShadowView(
BaseItem parent,
- string viewType,
+ CollectionType? viewType,
string sortName)
{
ArgumentNullException.ThrowIfNull(parent);
@@ -2277,7 +2282,7 @@ namespace Emby.Server.Implementations.Library
var name = parent.Name;
var parentId = parent.Id;
- var idValues = "38_namedview_" + name + parentId + (viewType ?? string.Empty);
+ var idValues = "38_namedview_" + name + parentId + (viewType?.ToString() ?? string.Empty);
var id = GetNewItemId(idValues, typeof(UserView));
@@ -2334,7 +2339,7 @@ namespace Emby.Server.Implementations.Library
public UserView GetNamedView(
string name,
Guid parentId,
- string viewType,
+ CollectionType? viewType,
string sortName,
string uniqueId)
{
@@ -2343,7 +2348,7 @@ namespace Emby.Server.Implementations.Library
var parentIdString = parentId.Equals(default)
? null
: parentId.ToString("N", CultureInfo.InvariantCulture);
- var idValues = "37_namedview_" + name + (parentIdString ?? string.Empty) + (viewType ?? string.Empty);
+ var idValues = "37_namedview_" + name + (parentIdString ?? string.Empty) + (viewType?.ToString() ?? string.Empty);
if (!string.IsNullOrEmpty(uniqueId))
{
idValues += uniqueId;
@@ -2378,7 +2383,7 @@ namespace Emby.Server.Implementations.Library
isNew = true;
}
- if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
+ if (viewType != item.ViewType)
{
item.ViewType = viewType;
item.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).GetAwaiter().GetResult();
@@ -2850,7 +2855,7 @@ namespace Emby.Server.Implementations.Library
{
var path = Path.Combine(virtualFolderPath, collectionType.ToString().ToLowerInvariant() + ".collection");
- File.WriteAllBytes(path, Array.Empty<byte>());
+ await File.WriteAllBytesAsync(path, Array.Empty<byte>()).ConfigureAwait(false);
}
CollectionFolder.SaveLibraryOptions(virtualFolderPath, options);