Merge pull request #9403 from SenorSmartyPants/ExtraCleanAndNFO

Co-authored-by: Cody Robibero <cody@robibe.ro>
This commit is contained in:
Cody Robibero 2023-03-20 07:16:03 -06:00 committed by GitHub
commit dd491ce8ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 14 deletions

View File

@ -156,7 +156,8 @@ namespace Emby.Naming.Common
@"^(?<cleaned>.+?)(\[.*\])",
@"^\s*(?<cleaned>.+?)\WE[0-9]+(-|~)E?[0-9]+(\W|$)",
@"^\s*\[[^\]]+\](?!\.\w+$)\s*(?<cleaned>.+)",
@"^\s*(?<cleaned>.+?)\s+-\s+[0-9]+\s*$"
@"^\s*(?<cleaned>.+?)\s+-\s+[0-9]+\s*$",
@"^\s*(?<cleaned>.+?)(([-._ ](trailer|sample))|-(scene|clip|behindthescenes|deleted|deletedscene|featurette|short|interview|other|extra))$"
};
SubtitleFileExtensions = new[]

View File

@ -87,8 +87,7 @@ namespace Emby.Naming.Video
name = cleanDateTimeResult.Name;
year = cleanDateTimeResult.Year;
if (extraResult.ExtraType is null
&& TryCleanString(name, namingOptions, out var newName))
if (TryCleanString(name, namingOptions, out var newName))
{
name = newName;
}

View File

@ -4,6 +4,7 @@ using System.IO;
using Emby.Naming.Common;
using Emby.Naming.Video;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities;
@ -15,7 +16,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
/// <summary>
/// Resolves a Path into a Video or Video subclass.
/// </summary>
internal class ExtraResolver
internal class ExtraResolver : BaseVideoResolver<Video>
{
private readonly NamingOptions _namingOptions;
private readonly IItemResolver[] _trailerResolvers;
@ -28,10 +29,16 @@ namespace Emby.Server.Implementations.Library.Resolvers
/// <param name="namingOptions">An instance of <see cref="NamingOptions"/>.</param>
/// <param name="directoryService">The directory service.</param>
public ExtraResolver(ILogger<ExtraResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService)
: base(logger, namingOptions, directoryService)
{
_namingOptions = namingOptions;
_trailerResolvers = new IItemResolver[] { new GenericVideoResolver<Trailer>(logger, namingOptions, directoryService) };
_videoResolvers = new IItemResolver[] { new GenericVideoResolver<Video>(logger, namingOptions, directoryService) };
_videoResolvers = new IItemResolver[] { this };
}
protected override Video Resolve(ItemResolveArgs args)
{
return ResolveVideo<Video>(args, true);
}
/// <summary>

View File

@ -404,12 +404,6 @@ namespace MediaBrowser.Providers.Manager
return false;
}
// Prevent owned items from reading the same local metadata file as their owner
if (!item.OwnerId.Equals(default) && provider is ILocalMetadataProvider)
{
return false;
}
if (includeDisabled)
{
return true;

View File

@ -62,7 +62,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
{
yield return Path.ChangeExtension(item.Path, ".nfo");
if (!item.IsInMixedFolder)
// only allow movie object to read movie.nfo, not owned videos (which will be itemtype video, not movie)
if (!item.IsInMixedFolder && item.ItemType == typeof(Movie))
{
yield return Path.Combine(item.ContainingFolderPath, "movie.nfo");
}

View File

@ -368,8 +368,8 @@ namespace Jellyfin.Providers.Tests.Manager
[Theory]
[InlineData(nameof(ICustomMetadataProvider), true)]
[InlineData(nameof(IRemoteMetadataProvider), true)]
[InlineData(nameof(ILocalMetadataProvider), false)]
public void GetMetadataProviders_CanRefreshMetadataOwned_WhenNotLocal(string providerType, bool expected)
[InlineData(nameof(ILocalMetadataProvider), true)]
public void GetMetadataProviders_CanRefreshMetadataOwned(string providerType, bool expected)
{
GetMetadataProviders_CanRefreshMetadata_Tester(providerType, expected, ownedItem: true);
}

View File

@ -79,6 +79,35 @@ public class FindExtrasTests
Assert.Equal(ExtraType.Sample, extras[2].ExtraType);
}
[Fact]
public void FindExtras_SeparateMovieFolder_CleanExtraNames()
{
var owner = new Movie { Name = "Up", Path = "/movies/Up/Up.mkv" };
var paths = new List<string>
{
"/movies/Up/Up.mkv",
"/movies/Up/Recording the audio[Bluray]-behindthescenes.mkv",
"/movies/Up/Interview with the dog-interview.mkv",
"/movies/Up/shorts/Balloons[1080p].mkv"
};
var files = paths.Select(p => new FileSystemMetadata
{
FullName = p,
IsDirectory = false
}).ToList();
var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList();
Assert.Equal(3, extras.Count);
Assert.Equal(ExtraType.BehindTheScenes, extras[0].ExtraType);
Assert.Equal("Recording the audio", extras[0].Name);
Assert.Equal(ExtraType.Interview, extras[1].ExtraType);
Assert.Equal("Interview with the dog", extras[1].Name);
Assert.Equal(ExtraType.Short, extras[2].ExtraType);
Assert.Equal("Balloons", extras[2].Name);
}
[Fact]
public void FindExtras_SeparateMovieFolderWithMixedExtras_FindsCorrectExtras()
{