jellyfin/Emby.Server.Implementations/Library/Resolvers/SpecialFolderResolver.cs

87 lines
2.7 KiB
C#
Raw Normal View History

#nullable disable
2019-11-01 18:38:54 +01:00
#pragma warning disable CS1591
using System;
using System.IO;
using System.Linq;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller;
2014-12-20 07:06:27 +01:00
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
2016-10-25 21:02:04 +02:00
using MediaBrowser.Model.IO;
2014-12-20 07:06:27 +01:00
namespace Emby.Server.Implementations.Library.Resolvers
2014-12-20 07:06:27 +01:00
{
public class SpecialFolderResolver : GenericFolderResolver<Folder>
2014-12-20 07:06:27 +01:00
{
private readonly IFileSystem _fileSystem;
2015-01-27 23:45:59 +01:00
private readonly IServerApplicationPaths _appPaths;
2014-12-20 07:06:27 +01:00
2015-01-27 23:45:59 +01:00
public SpecialFolderResolver(IFileSystem fileSystem, IServerApplicationPaths appPaths)
2014-12-20 07:06:27 +01:00
{
_fileSystem = fileSystem;
2015-01-27 23:45:59 +01:00
_appPaths = appPaths;
2014-12-20 07:06:27 +01:00
}
/// <summary>
/// Gets the priority.
/// </summary>
/// <value>The priority.</value>
public override ResolverPriority Priority => ResolverPriority.First;
2014-12-20 07:06:27 +01:00
/// <summary>
/// Resolves the specified args.
/// </summary>
/// <param name="args">The args.</param>
/// <returns>Folder.</returns>
protected override Folder Resolve(ItemResolveArgs args)
{
if (args.IsDirectory)
{
if (args.IsPhysicalRoot)
{
return new AggregateFolder();
}
2020-06-15 23:43:52 +02:00
2015-01-27 23:45:59 +01:00
if (string.Equals(args.Path, _appPaths.DefaultUserViewsPath, StringComparison.OrdinalIgnoreCase))
2014-12-20 07:06:27 +01:00
{
2020-06-14 11:11:11 +02:00
return new UserRootFolder(); // if we got here and still a root - must be user root
2014-12-20 07:06:27 +01:00
}
2020-06-15 23:43:52 +02:00
2014-12-20 07:06:27 +01:00
if (args.IsVf)
{
return new CollectionFolder
{
2016-08-18 17:13:18 +02:00
CollectionType = GetCollectionType(args),
2017-08-24 21:52:19 +02:00
PhysicalLocationsList = args.PhysicalLocations
2014-12-20 07:06:27 +01:00
};
}
}
return null;
}
private CollectionType? GetCollectionType(ItemResolveArgs args)
2014-12-20 07:06:27 +01:00
{
return args.FileSystemChildren
.Where(i =>
{
try
{
2016-10-25 21:02:04 +02:00
return !i.IsDirectory &&
2014-12-20 07:06:27 +01:00
string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase);
}
catch (IOException)
{
return false;
}
})
.Select(i => _fileSystem.GetFileNameWithoutExtension(i))
.Select(i => Enum.TryParse<CollectionType>(i, out var collectionType) ? collectionType : (CollectionType?)null)
.FirstOrDefault(i => i is not null);
2014-12-20 07:06:27 +01:00
}
}
}