Fix extra folder type resolving.

This commit is contained in:
Dixin 2021-09-19 16:54:00 -07:00
parent a3a8e058bc
commit dc8420c7a2
4 changed files with 34 additions and 52 deletions

View File

@ -54,7 +54,7 @@ namespace Emby.Server.Implementations.Library
if (parent != null) if (parent != null)
{ {
// Ignore trailer folders but allow it at the collection level // Ignore trailer folders but allow it at the collection level
if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase) if (string.Equals(filename, BaseItem.TrailersFolderName, StringComparison.OrdinalIgnoreCase)
&& !(parent is AggregateFolder) && !(parent is AggregateFolder)
&& !(parent is UserRootFolder)) && !(parent is UserRootFolder))
{ {
@ -77,7 +77,7 @@ namespace Emby.Server.Implementations.Library
if (parent != null) if (parent != null)
{ {
// Don't resolve these into audio files // Don't resolve these into audio files
if (Path.GetFileNameWithoutExtension(filename.AsSpan()).Equals(BaseItem.ThemeSongFilename, StringComparison.Ordinal) if (Path.GetFileNameWithoutExtension(filename.AsSpan()).Equals(BaseItem.ThemeSongFileName, StringComparison.Ordinal)
&& _libraryManager.IsAudioFile(filename)) && _libraryManager.IsAudioFile(filename))
{ {
return true; return true;

View File

@ -2714,7 +2714,7 @@ namespace Emby.Server.Implementations.Library
var namingOptions = GetNamingOptions(); var namingOptions = GetNamingOptions();
var files = owner.IsInMixedFolder ? new List<FileSystemMetadata>() : fileSystemChildren.Where(i => i.IsDirectory) var files = owner.IsInMixedFolder ? new List<FileSystemMetadata>() : fileSystemChildren.Where(i => i.IsDirectory)
.Where(i => string.Equals(i.Name, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase)) .Where(i => string.Equals(i.Name, BaseItem.TrailersFolderName, StringComparison.OrdinalIgnoreCase))
.SelectMany(i => _fileSystem.GetFiles(i.FullName, _videoFileExtensions, false, false)) .SelectMany(i => _fileSystem.GetFiles(i.FullName, _videoFileExtensions, false, false))
.ToList(); .ToList();
@ -2758,7 +2758,7 @@ namespace Emby.Server.Implementations.Library
var namingOptions = GetNamingOptions(); var namingOptions = GetNamingOptions();
var files = owner.IsInMixedFolder ? new List<FileSystemMetadata>() : fileSystemChildren.Where(i => i.IsDirectory) var files = owner.IsInMixedFolder ? new List<FileSystemMetadata>() : fileSystemChildren.Where(i => i.IsDirectory)
.Where(i => BaseItem.AllExtrasTypesFolderNames.Contains(i.Name ?? string.Empty, StringComparer.OrdinalIgnoreCase)) .Where(i => BaseItem.AllExtrasTypesFolderNames.ContainsKey(i.Name ?? string.Empty))
.SelectMany(i => _fileSystem.GetFiles(i.FullName, _videoFileExtensions, false, false)) .SelectMany(i => _fileSystem.GetFiles(i.FullName, _videoFileExtensions, false, false))
.ToList(); .ToList();

View File

@ -47,7 +47,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
if ((season != null || if ((season != null ||
string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) ||
args.HasParent<Series>()) args.HasParent<Series>())
&& (parent is Series || !BaseItem.AllExtrasTypesFolderNames.Contains(parent.Name, StringComparer.OrdinalIgnoreCase))) && (parent is Series || !BaseItem.AllExtrasTypesFolderNames.ContainsKey(parent.Name)))
{ {
var episode = ResolveVideo<Episode>(args, false); var episode = ResolveVideo<Episode>(args, false);

View File

@ -44,18 +44,10 @@ namespace MediaBrowser.Controller.Entities
/// <summary> /// <summary>
/// The trailer folder name. /// The trailer folder name.
/// </summary> /// </summary>
public const string TrailerFolderName = "trailers"; public const string TrailersFolderName = "trailers";
public const string ThemeSongsFolderName = "theme-music"; public const string ThemeSongsFolderName = "theme-music";
public const string ThemeSongFilename = "theme"; public const string ThemeSongFileName = "theme";
public const string ThemeVideosFolderName = "backdrops"; public const string ThemeVideosFolderName = "backdrops";
public const string ExtrasFolderName = "extras";
public const string BehindTheScenesFolderName = "behind the scenes";
public const string DeletedScenesFolderName = "deleted scenes";
public const string InterviewFolderName = "interviews";
public const string SceneFolderName = "scenes";
public const string SampleFolderName = "samples";
public const string ShortsFolderName = "shorts";
public const string FeaturettesFolderName = "featurettes";
/// <summary> /// <summary>
/// The supported image extensions. /// The supported image extensions.
@ -93,16 +85,20 @@ namespace MediaBrowser.Controller.Entities
}; };
public static readonly char[] SlugReplaceChars = { '?', '/', '&' }; public static readonly char[] SlugReplaceChars = { '?', '/', '&' };
public static readonly string[] AllExtrasTypesFolderNames =
/// <summary>
/// The supported extra folder names and types. See <see cref="Emby.Naming.Common.NamingOptions" />.
/// </summary>
public static readonly Dictionary<string, ExtraType> AllExtrasTypesFolderNames = new Dictionary<string, ExtraType>(StringComparer.OrdinalIgnoreCase)
{ {
ExtrasFolderName, ["extras"] = MediaBrowser.Model.Entities.ExtraType.Unknown,
BehindTheScenesFolderName, ["behind the scenes"] = MediaBrowser.Model.Entities.ExtraType.BehindTheScenes,
DeletedScenesFolderName, ["deleted scenes"] = MediaBrowser.Model.Entities.ExtraType.DeletedScene,
InterviewFolderName, ["interviews"] = MediaBrowser.Model.Entities.ExtraType.Interview,
SceneFolderName, ["scenes"] = MediaBrowser.Model.Entities.ExtraType.Scene,
SampleFolderName, ["samples"] = MediaBrowser.Model.Entities.ExtraType.Sample,
ShortsFolderName, ["shorts"] = MediaBrowser.Model.Entities.ExtraType.Clip,
FeaturettesFolderName ["featurettes"] = MediaBrowser.Model.Entities.ExtraType.Clip
}; };
private string _sortName; private string _sortName;
@ -1358,7 +1354,7 @@ namespace MediaBrowser.Controller.Entities
// Support plex/xbmc convention // Support plex/xbmc convention
files.AddRange(fileSystemChildren files.AddRange(fileSystemChildren
.Where(i => !i.IsDirectory && System.IO.Path.GetFileNameWithoutExtension(i.FullName.AsSpan()).Equals(ThemeSongFilename, StringComparison.OrdinalIgnoreCase))); .Where(i => !i.IsDirectory && System.IO.Path.GetFileNameWithoutExtension(i.FullName.AsSpan()).Equals(ThemeSongFileName, StringComparison.OrdinalIgnoreCase)));
return LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions()) return LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions())
.OfType<Audio.Audio>() .OfType<Audio.Audio>()
@ -1417,39 +1413,25 @@ namespace MediaBrowser.Controller.Entities
protected virtual BaseItem[] LoadExtras(List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService) protected virtual BaseItem[] LoadExtras(List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService)
{ {
var extras = new List<Video>(); return fileSystemChildren
.Where(child => child.IsDirectory)
var libraryOptions = new LibraryOptions(); .Where(folder => AllExtrasTypesFolderNames.ContainsKey(folder.Name))
var folders = fileSystemChildren.Where(i => i.IsDirectory).ToList(); .SelectMany(folder => LibraryManager
foreach (var extraFolderName in AllExtrasTypesFolderNames) .ResolvePaths(FileSystem.GetFiles(folder.FullName), directoryService, null, new LibraryOptions())
{
var files = folders
.Where(i => string.Equals(i.Name, extraFolderName, StringComparison.OrdinalIgnoreCase))
.SelectMany(i => FileSystem.GetFiles(i.FullName));
// Re-using the same instance of LibraryOptions since it looks like it's never being altered.
extras.AddRange(LibraryManager.ResolvePaths(files, directoryService, null, libraryOptions)
.OfType<Video>() .OfType<Video>()
.Select(item => .Select(video =>
{ {
// Try to retrieve it from the db. If we don't find it, use the resolved version // Try to retrieve it from the db. If we don't find it, use the resolved version
if (LibraryManager.GetItemById(item.Id) is Video dbItem) if (LibraryManager.GetItemById(video.Id) is Video dbItem)
{ {
item = dbItem; video = dbItem;
} }
// Use some hackery to get the extra type based on foldername video.ExtraType = AllExtrasTypesFolderNames[folder.Name];
item.ExtraType = Enum.TryParse(extraFolderName.Replace(" ", string.Empty, StringComparison.Ordinal), true, out ExtraType extraType) return video;
? extraType })
: Model.Entities.ExtraType.Unknown; .OrderBy(video => video.Path)) // Sort them so that the list can be easily compared for changes
.ToArray();
return item;
// Sort them so that the list can be easily compared for changes
}).OrderBy(i => i.Path));
}
return extras.ToArray();
} }
public Task RefreshMetadata(CancellationToken cancellationToken) public Task RefreshMetadata(CancellationToken cancellationToken)