|
|
|
@ -6,7 +6,10 @@ using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Emby.Naming.Audio;
|
|
|
|
|
using Emby.Naming.AudioBook;
|
|
|
|
|
using Emby.Naming.Common;
|
|
|
|
|
using Emby.Naming.Video;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
@ -21,11 +24,11 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class AudioResolver : ItemResolver<MediaBrowser.Controller.Entities.Audio.Audio>, IMultiItemResolver
|
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
|
private readonly NamingOptions _namingOptions;
|
|
|
|
|
|
|
|
|
|
public AudioResolver(ILibraryManager libraryManager)
|
|
|
|
|
public AudioResolver(NamingOptions namingOptions)
|
|
|
|
|
{
|
|
|
|
|
_libraryManager = libraryManager;
|
|
|
|
|
_namingOptions = namingOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -40,7 +43,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
string collectionType,
|
|
|
|
|
IDirectoryService directoryService)
|
|
|
|
|
{
|
|
|
|
|
var result = ResolveMultipleInternal(parent, files, collectionType, directoryService);
|
|
|
|
|
var result = ResolveMultipleInternal(parent, files, collectionType);
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
@ -56,12 +59,11 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
private MultiItemResolverResult ResolveMultipleInternal(
|
|
|
|
|
Folder parent,
|
|
|
|
|
List<FileSystemMetadata> files,
|
|
|
|
|
string collectionType,
|
|
|
|
|
IDirectoryService directoryService)
|
|
|
|
|
string collectionType)
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return ResolveMultipleAudio<AudioBook>(parent, files, directoryService, false, collectionType, true);
|
|
|
|
|
return ResolveMultipleAudio(parent, files, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
@ -87,14 +89,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var files = args.FileSystemChildren
|
|
|
|
|
.Where(i => !_libraryManager.IgnoreFile(i, args.Parent))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return FindAudio<AudioBook>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false);
|
|
|
|
|
return FindAudioBook(args, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_libraryManager.IsAudioFile(args.Path))
|
|
|
|
|
if (AudioFileParser.IsAudioFile(args.Path, _namingOptions))
|
|
|
|
|
{
|
|
|
|
|
var extension = Path.GetExtension(args.Path);
|
|
|
|
|
|
|
|
|
@ -107,7 +105,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
var isMixedCollectionType = string.IsNullOrEmpty(collectionType);
|
|
|
|
|
|
|
|
|
|
// For conflicting extensions, give priority to videos
|
|
|
|
|
if (isMixedCollectionType && _libraryManager.IsVideoFile(args.Path))
|
|
|
|
|
if (isMixedCollectionType && VideoResolver.IsVideoFile(args.Path, _namingOptions))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -141,29 +139,23 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private T FindAudio<T>(ItemResolveArgs args, string path, Folder parent, List<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, string collectionType, bool parseName)
|
|
|
|
|
where T : MediaBrowser.Controller.Entities.Audio.Audio, new()
|
|
|
|
|
private AudioBook FindAudioBook(ItemResolveArgs args, bool parseName)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Allow GetMultiDiscMovie in here
|
|
|
|
|
const bool supportsMultiVersion = false;
|
|
|
|
|
var result = ResolveMultipleAudio(args.Parent, args.GetActualFileSystemChildren(), parseName);
|
|
|
|
|
|
|
|
|
|
var result = ResolveMultipleAudio<T>(parent, fileSystemEntries, directoryService, supportsMultiVersion, collectionType, parseName) ??
|
|
|
|
|
new MultiItemResolverResult();
|
|
|
|
|
|
|
|
|
|
if (result.Items.Count == 1)
|
|
|
|
|
if (result == null || result.Items.Count != 1 || result.Items[0] is not AudioBook item)
|
|
|
|
|
{
|
|
|
|
|
// If we were supporting this we'd be checking filesFromOtherItems
|
|
|
|
|
var item = (T)result.Items[0];
|
|
|
|
|
item.IsInMixedFolder = false;
|
|
|
|
|
item.Name = Path.GetFileName(item.ContainingFolderPath);
|
|
|
|
|
return item;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
// If we were supporting this we'd be checking filesFromOtherItems
|
|
|
|
|
item.IsInMixedFolder = false;
|
|
|
|
|
item.Name = Path.GetFileName(item.ContainingFolderPath);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MultiItemResolverResult ResolveMultipleAudio<T>(Folder parent, IEnumerable<FileSystemMetadata> fileSystemEntries, IDirectoryService directoryService, bool suppportMultiEditions, string collectionType, bool parseName)
|
|
|
|
|
where T : MediaBrowser.Controller.Entities.Audio.Audio, new()
|
|
|
|
|
private MultiItemResolverResult ResolveMultipleAudio(Folder parent, IEnumerable<FileSystemMetadata> fileSystemEntries, bool parseName)
|
|
|
|
|
{
|
|
|
|
|
var files = new List<FileSystemMetadata>();
|
|
|
|
|
var items = new List<BaseItem>();
|
|
|
|
@ -176,15 +168,13 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
{
|
|
|
|
|
leftOver.Add(child);
|
|
|
|
|
}
|
|
|
|
|
else if (!IsIgnored(child.Name))
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
files.Add(child);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var namingOptions = ((LibraryManager)_libraryManager).GetNamingOptions();
|
|
|
|
|
|
|
|
|
|
var resolver = new AudioBookListResolver(namingOptions);
|
|
|
|
|
var resolver = new AudioBookListResolver(_namingOptions);
|
|
|
|
|
var resolverResult = resolver.Resolve(files).ToList();
|
|
|
|
|
|
|
|
|
|
var result = new MultiItemResolverResult
|
|
|
|
@ -210,7 +200,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
|
|
|
|
|
var firstMedia = resolvedItem.Files[0];
|
|
|
|
|
|
|
|
|
|
var libraryItem = new T
|
|
|
|
|
var libraryItem = new AudioBook
|
|
|
|
|
{
|
|
|
|
|
Path = firstMedia.Path,
|
|
|
|
|
IsInMixedFolder = isInMixedFolder,
|
|
|
|
@ -230,12 +220,12 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ContainsFile(List<AudioBookInfo> result, FileSystemMetadata file)
|
|
|
|
|
private static bool ContainsFile(IEnumerable<AudioBookInfo> result, FileSystemMetadata file)
|
|
|
|
|
{
|
|
|
|
|
return result.Any(i => ContainsFile(i, file));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ContainsFile(AudioBookInfo result, FileSystemMetadata file)
|
|
|
|
|
private static bool ContainsFile(AudioBookInfo result, FileSystemMetadata file)
|
|
|
|
|
{
|
|
|
|
|
return result.Files.Any(i => ContainsFile(i, file)) ||
|
|
|
|
|
result.AlternateVersions.Any(i => ContainsFile(i, file)) ||
|
|
|
|
@ -246,10 +236,5 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
|
|
|
|
{
|
|
|
|
|
return string.Equals(result.Path, file.FullName, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool IsIgnored(string filename)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|