mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-23 18:44:45 +01:00
added collection type
This commit is contained in:
@@ -64,7 +64,7 @@ namespace MediaBrowser.Server.Implementations.IO
|
||||
public async void RemoveTempIgnore(string path)
|
||||
{
|
||||
// This is an arbitraty amount of time, but delay it because file system writes often trigger events after RemoveTempIgnore has been called.
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
await Task.Delay(1000).ConfigureAwait(false);
|
||||
|
||||
string val;
|
||||
_tempIgnoredPaths.TryRemove(path, out val);
|
||||
|
||||
@@ -487,7 +487,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
// When resolving the root, we need it's grandchildren (children of user views)
|
||||
var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
|
||||
|
||||
args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf);
|
||||
args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, args, flattenFolderDepth: flattenFolderDepth, resolveShortcuts: isPhysicalRoot || args.IsVf);
|
||||
|
||||
// Need to remove subpaths that may have been resolved from shortcuts
|
||||
// Example: if \\server\movies exists, then strip out \\server\movies\action
|
||||
@@ -1168,10 +1168,23 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
.Select(dir => new VirtualFolderInfo
|
||||
{
|
||||
Name = Path.GetFileName(dir),
|
||||
Locations = Directory.EnumerateFiles(dir, "*.lnk", SearchOption.TopDirectoryOnly).Select(FileSystem.ResolveShortcut).OrderBy(i => i).ToList()
|
||||
|
||||
Locations = Directory.EnumerateFiles(dir, "*.lnk", SearchOption.TopDirectoryOnly)
|
||||
.Select(FileSystem.ResolveShortcut)
|
||||
.OrderBy(i => i)
|
||||
.ToList(),
|
||||
|
||||
CollectionType = GetCollectionType(dir)
|
||||
});
|
||||
}
|
||||
|
||||
private string GetCollectionType(string path)
|
||||
{
|
||||
return new DirectoryInfo(path).EnumerateFiles("*.collection", SearchOption.TopDirectoryOnly)
|
||||
.Select(i => Path.GetFileNameWithoutExtension(i.FullName))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the item by id.
|
||||
/// </summary>
|
||||
@@ -1405,5 +1418,47 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the type of the collection.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public string FindCollectionType(BaseItem item)
|
||||
{
|
||||
while (!(item.Parent is AggregateFolder) && item.Parent != null)
|
||||
{
|
||||
item = item.Parent;
|
||||
}
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var collectionTypes = _userManager.Users
|
||||
.Select(i => i.RootFolder)
|
||||
.Distinct()
|
||||
.SelectMany(i => i.Children)
|
||||
.OfType<CollectionFolder>()
|
||||
.Where(i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return i.LocationType != LocationType.Remote && i.LocationType != LocationType.Virtual &&
|
||||
i.ResolveArgs.PhysicalLocations.Contains(item.Path);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
_logger.ErrorException("Error getting resolve args for {0}", ex, i.Path);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.Select(i => i.CollectionType)
|
||||
.Where(i => !string.IsNullOrEmpty(i))
|
||||
.Distinct();
|
||||
|
||||
return collectionTypes.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
{
|
||||
@@ -37,7 +40,10 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
}
|
||||
if (args.IsVf)
|
||||
{
|
||||
return new CollectionFolder();
|
||||
return new CollectionFolder
|
||||
{
|
||||
CollectionType = GetCollectionType(args)
|
||||
};
|
||||
}
|
||||
|
||||
return new Folder();
|
||||
@@ -45,6 +51,14 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetCollectionType(ItemResolveArgs args)
|
||||
{
|
||||
return args.FileSystemChildren
|
||||
.Where(i => (i.Attributes & FileAttributes.Directory) != FileAttributes.Directory && string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(i => Path.GetFileNameWithoutExtension(i.FullName))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -18,10 +18,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
public class MovieResolver : BaseVideoResolver<Video>
|
||||
{
|
||||
private IServerApplicationPaths ApplicationPaths { get; set; }
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
|
||||
public MovieResolver(IServerApplicationPaths appPaths)
|
||||
public MovieResolver(IServerApplicationPaths appPaths, ILibraryManager libraryManager)
|
||||
{
|
||||
ApplicationPaths = appPaths;
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,19 +75,27 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
return null;
|
||||
}
|
||||
|
||||
// A shortcut to help us resolve faster in some cases
|
||||
var isKnownMovie = args.ContainsMetaFileByName("movie.xml");
|
||||
var collectionType = args.Parent == null ? null : _libraryManager.FindCollectionType(args.Parent);
|
||||
|
||||
if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
if (args.Path.IndexOf("[trailers]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return FindMovie<Trailer>(args.Path, args.FileSystemChildren, isKnownMovie);
|
||||
}
|
||||
if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
return FindMovie<MusicVideo>(args.Path, args.FileSystemChildren, isKnownMovie);
|
||||
return FindMovie<Trailer>(args.Path, args.FileSystemChildren);
|
||||
}
|
||||
|
||||
return FindMovie<Movie>(args.Path, args.FileSystemChildren, isKnownMovie);
|
||||
if (args.Path.IndexOf("[musicvideos]", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return FindMovie<MusicVideo>(args.Path, args.FileSystemChildren);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(collectionType) &&
|
||||
!string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return FindMovie<Movie>(args.Path, args.FileSystemChildren);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -126,9 +136,8 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="fileSystemEntries">The file system entries.</param>
|
||||
/// <param name="isKnownMovie">if set to <c>true</c> [is known movie].</param>
|
||||
/// <returns>Movie.</returns>
|
||||
private T FindMovie<T>(string path, IEnumerable<FileSystemInfo> fileSystemEntries, bool isKnownMovie)
|
||||
private T FindMovie<T>(string path, IEnumerable<FileSystemInfo> fileSystemEntries)
|
||||
where T : Video, new()
|
||||
{
|
||||
var movies = new List<T>();
|
||||
|
||||
Reference in New Issue
Block a user