Inject IDirectoryService where needed instead of passing it through ItemResolveArgs

This commit is contained in:
Joe Rogers 2023-03-06 23:00:55 -05:00
parent 160baa02fd
commit 1c3a97bf6a
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4
14 changed files with 66 additions and 47 deletions

View File

@ -113,6 +113,7 @@ namespace Emby.Server.Implementations.Library
/// <param name="imageProcessor">The image processor.</param> /// <param name="imageProcessor">The image processor.</param>
/// <param name="memoryCache">The memory cache.</param> /// <param name="memoryCache">The memory cache.</param>
/// <param name="namingOptions">The naming options.</param> /// <param name="namingOptions">The naming options.</param>
/// <param name="directoryService">The directory service.</param>
public LibraryManager( public LibraryManager(
IServerApplicationHost appHost, IServerApplicationHost appHost,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
@ -128,7 +129,8 @@ namespace Emby.Server.Implementations.Library
IItemRepository itemRepository, IItemRepository itemRepository,
IImageProcessor imageProcessor, IImageProcessor imageProcessor,
IMemoryCache memoryCache, IMemoryCache memoryCache,
NamingOptions namingOptions) NamingOptions namingOptions,
IDirectoryService directoryService)
{ {
_appHost = appHost; _appHost = appHost;
_logger = loggerFactory.CreateLogger<LibraryManager>(); _logger = loggerFactory.CreateLogger<LibraryManager>();
@ -146,7 +148,7 @@ namespace Emby.Server.Implementations.Library
_memoryCache = memoryCache; _memoryCache = memoryCache;
_namingOptions = namingOptions; _namingOptions = namingOptions;
_extraResolver = new ExtraResolver(loggerFactory.CreateLogger<ExtraResolver>(), namingOptions); _extraResolver = new ExtraResolver(loggerFactory.CreateLogger<ExtraResolver>(), namingOptions, directoryService);
_configurationManager.ConfigurationUpdated += ConfigurationUpdated; _configurationManager.ConfigurationUpdated += ConfigurationUpdated;
@ -537,7 +539,7 @@ namespace Emby.Server.Implementations.Library
collectionType = GetContentTypeOverride(fullPath, true); collectionType = GetContentTypeOverride(fullPath, true);
} }
var args = new ItemResolveArgs(_configurationManager.ApplicationPaths, directoryService, this) var args = new ItemResolveArgs(_configurationManager.ApplicationPaths, this)
{ {
Parent = parent, Parent = parent,
FileInfo = fileInfo, FileInfo = fileInfo,

View File

@ -25,16 +25,19 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
{ {
private readonly ILogger<MusicAlbumResolver> _logger; private readonly ILogger<MusicAlbumResolver> _logger;
private readonly NamingOptions _namingOptions; private readonly NamingOptions _namingOptions;
private readonly IDirectoryService _directoryService;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="MusicAlbumResolver"/> class. /// Initializes a new instance of the <see cref="MusicAlbumResolver"/> class.
/// </summary> /// </summary>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="namingOptions">The naming options.</param> /// <param name="namingOptions">The naming options.</param>
public MusicAlbumResolver(ILogger<MusicAlbumResolver> logger, NamingOptions namingOptions) /// <param name="directoryService">The directory service.</param>
public MusicAlbumResolver(ILogger<MusicAlbumResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService)
{ {
_logger = logger; _logger = logger;
_namingOptions = namingOptions; _namingOptions = namingOptions;
_directoryService = directoryService;
} }
/// <summary> /// <summary>
@ -109,7 +112,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
} }
// If args contains music it's a music album // If args contains music it's a music album
if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService)) if (ContainsMusic(args.FileSystemChildren, true, _directoryService))
{ {
return true; return true;
} }

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Emby.Naming.Common; using Emby.Naming.Common;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -18,19 +19,23 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
public class MusicArtistResolver : ItemResolver<MusicArtist> public class MusicArtistResolver : ItemResolver<MusicArtist>
{ {
private readonly ILogger<MusicAlbumResolver> _logger; private readonly ILogger<MusicAlbumResolver> _logger;
private NamingOptions _namingOptions; private readonly NamingOptions _namingOptions;
private readonly IDirectoryService _directoryService;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="MusicArtistResolver"/> class. /// Initializes a new instance of the <see cref="MusicArtistResolver"/> class.
/// </summary> /// </summary>
/// <param name="logger">Instance of the <see cref="MusicAlbumResolver"/> interface.</param> /// <param name="logger">Instance of the <see cref="MusicAlbumResolver"/> interface.</param>
/// <param name="namingOptions">The <see cref="NamingOptions"/>.</param> /// <param name="namingOptions">The <see cref="NamingOptions"/>.</param>
/// <param name="directoryService">The directory service.</param>
public MusicArtistResolver( public MusicArtistResolver(
ILogger<MusicAlbumResolver> logger, ILogger<MusicAlbumResolver> logger,
NamingOptions namingOptions) NamingOptions namingOptions,
IDirectoryService directoryService)
{ {
_logger = logger; _logger = logger;
_namingOptions = namingOptions; _namingOptions = namingOptions;
_directoryService = directoryService;
} }
/// <summary> /// <summary>
@ -78,9 +83,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
return null; return null;
} }
var directoryService = args.DirectoryService; var albumResolver = new MusicAlbumResolver(_logger, _namingOptions, _directoryService);
var albumResolver = new MusicAlbumResolver(_logger, _namingOptions);
var directories = args.FileSystemChildren.Where(i => i.IsDirectory); var directories = args.FileSystemChildren.Where(i => i.IsDirectory);
@ -97,7 +100,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
} }
// If we contain a music album assume we are an artist folder // If we contain a music album assume we are an artist folder
if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, directoryService)) if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, _directoryService))
{ {
// Stop once we see a music album // Stop once we see a music album
state.Stop(); state.Stop();

View File

@ -25,14 +25,17 @@ namespace Emby.Server.Implementations.Library.Resolvers
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
protected BaseVideoResolver(ILogger logger, NamingOptions namingOptions) protected BaseVideoResolver(ILogger logger, NamingOptions namingOptions, IDirectoryService directoryService)
{ {
_logger = logger; _logger = logger;
NamingOptions = namingOptions; NamingOptions = namingOptions;
DirectoryService = directoryService;
} }
protected NamingOptions NamingOptions { get; } protected NamingOptions NamingOptions { get; }
protected IDirectoryService DirectoryService { get; }
/// <summary> /// <summary>
/// Resolves the specified args. /// Resolves the specified args.
/// </summary> /// </summary>
@ -65,7 +68,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
var filename = child.Name; var filename = child.Name;
if (child.IsDirectory) if (child.IsDirectory)
{ {
if (IsDvdDirectory(child.FullName, filename, args.DirectoryService)) if (IsDvdDirectory(child.FullName, filename, DirectoryService))
{ {
videoType = VideoType.Dvd; videoType = VideoType.Dvd;
} }

View File

@ -4,6 +4,7 @@ using System.IO;
using Emby.Naming.Common; using Emby.Naming.Common;
using Emby.Naming.Video; using Emby.Naming.Video;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -25,11 +26,12 @@ namespace Emby.Server.Implementations.Library.Resolvers
/// </summary> /// </summary>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="namingOptions">An instance of <see cref="NamingOptions"/>.</param> /// <param name="namingOptions">An instance of <see cref="NamingOptions"/>.</param>
public ExtraResolver(ILogger<ExtraResolver> logger, NamingOptions namingOptions) /// <param name="directoryService">The directory service.</param>
public ExtraResolver(ILogger<ExtraResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService)
{ {
_namingOptions = namingOptions; _namingOptions = namingOptions;
_trailerResolvers = new IItemResolver[] { new GenericVideoResolver<Trailer>(logger, namingOptions) }; _trailerResolvers = new IItemResolver[] { new GenericVideoResolver<Trailer>(logger, namingOptions, directoryService) };
_videoResolvers = new IItemResolver[] { new GenericVideoResolver<Video>(logger, namingOptions) }; _videoResolvers = new IItemResolver[] { new GenericVideoResolver<Video>(logger, namingOptions, directoryService) };
} }
/// <summary> /// <summary>

View File

@ -2,6 +2,7 @@
using Emby.Naming.Common; using Emby.Naming.Common;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Library.Resolvers namespace Emby.Server.Implementations.Library.Resolvers
@ -18,8 +19,9 @@ namespace Emby.Server.Implementations.Library.Resolvers
/// </summary> /// </summary>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="namingOptions">The naming options.</param> /// <param name="namingOptions">The naming options.</param>
public GenericVideoResolver(ILogger logger, NamingOptions namingOptions) /// <param name="directoryService">The directory service.</param>
: base(logger, namingOptions) public GenericVideoResolver(ILogger logger, NamingOptions namingOptions, IDirectoryService directoryService)
: base(logger, namingOptions, directoryService)
{ {
} }
} }

View File

@ -43,8 +43,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
/// <param name="imageProcessor">The image processor.</param> /// <param name="imageProcessor">The image processor.</param>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="namingOptions">The naming options.</param> /// <param name="namingOptions">The naming options.</param>
public MovieResolver(IImageProcessor imageProcessor, ILogger<MovieResolver> logger, NamingOptions namingOptions) /// <param name="directoryService">The directory service.</param>
: base(logger, namingOptions) public MovieResolver(IImageProcessor imageProcessor, ILogger<MovieResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService)
: base(logger, namingOptions, directoryService)
{ {
_imageProcessor = imageProcessor; _imageProcessor = imageProcessor;
} }
@ -97,12 +98,12 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{ {
movie = FindMovie<MusicVideo>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false); movie = FindMovie<MusicVideo>(args, args.Path, args.Parent, files, DirectoryService, collectionType, false);
} }
if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{ {
movie = FindMovie<Video>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, false); movie = FindMovie<Video>(args, args.Path, args.Parent, files, DirectoryService, collectionType, false);
} }
if (string.IsNullOrEmpty(collectionType)) if (string.IsNullOrEmpty(collectionType))
@ -118,12 +119,12 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
return null; return null;
} }
movie = FindMovie<Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true); movie = FindMovie<Movie>(args, args.Path, args.Parent, files, DirectoryService, collectionType, true);
} }
if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase)) if (string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase))
{ {
movie = FindMovie<Movie>(args, args.Path, args.Parent, files, args.DirectoryService, collectionType, true); movie = FindMovie<Movie>(args, args.Path, args.Parent, files, DirectoryService, collectionType, true);
} }
// ignore extras // ignore extras

View File

@ -1,7 +1,5 @@
#nullable disable #nullable disable
#pragma warning disable CS1591
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -12,15 +10,20 @@ using Jellyfin.Extensions;
using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
namespace Emby.Server.Implementations.Library.Resolvers namespace Emby.Server.Implementations.Library.Resolvers
{ {
/// <summary>
/// Class PhotoResolver.
/// </summary>
public class PhotoResolver : ItemResolver<Photo> public class PhotoResolver : ItemResolver<Photo>
{ {
private readonly IImageProcessor _imageProcessor; private readonly IImageProcessor _imageProcessor;
private readonly NamingOptions _namingOptions; private readonly NamingOptions _namingOptions;
private readonly IDirectoryService _directoryService;
private static readonly HashSet<string> _ignoreFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase) private static readonly HashSet<string> _ignoreFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{ {
@ -35,10 +38,17 @@ namespace Emby.Server.Implementations.Library.Resolvers
"default" "default"
}; };
public PhotoResolver(IImageProcessor imageProcessor, NamingOptions namingOptions) /// <summary>
/// Initializes a new instance of the <see cref="PhotoResolver"/> class.
/// </summary>
/// <param name="imageProcessor">The image processor.</param>
/// <param name="namingOptions">The naming options.</param>
/// <param name="directoryService">The directory service.</param>
public PhotoResolver(IImageProcessor imageProcessor, NamingOptions namingOptions, IDirectoryService directoryService)
{ {
_imageProcessor = imageProcessor; _imageProcessor = imageProcessor;
_namingOptions = namingOptions; _namingOptions = namingOptions;
_directoryService = directoryService;
} }
/// <summary> /// <summary>
@ -61,7 +71,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
var filename = Path.GetFileNameWithoutExtension(args.Path); var filename = Path.GetFileNameWithoutExtension(args.Path);
// Make sure the image doesn't belong to a video file // Make sure the image doesn't belong to a video file
var files = args.DirectoryService.GetFiles(Path.GetDirectoryName(args.Path)); var files = _directoryService.GetFiles(Path.GetDirectoryName(args.Path));
foreach (var file in files) foreach (var file in files)
{ {

View File

@ -5,6 +5,7 @@ using System.Linq;
using Emby.Naming.Common; using Emby.Naming.Common;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -20,8 +21,9 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
/// </summary> /// </summary>
/// <param name="logger">The logger.</param> /// <param name="logger">The logger.</param>
/// <param name="namingOptions">The naming options.</param> /// <param name="namingOptions">The naming options.</param>
public EpisodeResolver(ILogger<EpisodeResolver> logger, NamingOptions namingOptions) /// <param name="directoryService">The directory service.</param>
: base(logger, namingOptions) public EpisodeResolver(ILogger<EpisodeResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService)
: base(logger, namingOptions, directoryService)
{ {
} }

View File

@ -120,7 +120,7 @@ namespace MediaBrowser.Controller.Entities
var path = ContainingFolderPath; var path = ContainingFolderPath;
var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, directoryService, LibraryManager) var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager)
{ {
FileInfo = FileSystem.GetDirectoryInfo(path) FileInfo = FileSystem.GetDirectoryInfo(path)
}; };

View File

@ -288,7 +288,7 @@ namespace MediaBrowser.Controller.Entities
{ {
var path = ContainingFolderPath; var path = ContainingFolderPath;
var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, directoryService, LibraryManager) var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths, LibraryManager)
{ {
FileInfo = FileSystem.GetDirectoryInfo(path), FileInfo = FileSystem.GetDirectoryInfo(path),
Parent = GetParent() as Folder, Parent = GetParent() as Folder,

View File

@ -1,12 +1,11 @@
#nullable disable #nullable disable
#pragma warning disable CA1721, CA1819, CS1591 #pragma warning disable CS1591
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
@ -30,18 +29,13 @@ namespace MediaBrowser.Controller.Library
/// Initializes a new instance of the <see cref="ItemResolveArgs" /> class. /// Initializes a new instance of the <see cref="ItemResolveArgs" /> class.
/// </summary> /// </summary>
/// <param name="appPaths">The app paths.</param> /// <param name="appPaths">The app paths.</param>
/// <param name="directoryService">The directory service.</param>
/// <param name="libraryManager">The library manager.</param> /// <param name="libraryManager">The library manager.</param>
public ItemResolveArgs(IServerApplicationPaths appPaths, IDirectoryService directoryService, ILibraryManager libraryManager) public ItemResolveArgs(IServerApplicationPaths appPaths, ILibraryManager libraryManager)
{ {
_appPaths = appPaths; _appPaths = appPaths;
DirectoryService = directoryService;
_libraryManager = libraryManager; _libraryManager = libraryManager;
} }
// TODO remove dependencies as properties, they should be injected where it makes sense
public IDirectoryService DirectoryService { get; }
/// <summary> /// <summary>
/// Gets or sets the file system children. /// Gets or sets the file system children.
/// </summary> /// </summary>

View File

@ -22,10 +22,9 @@ namespace Jellyfin.Server.Implementations.Tests.Library
{ {
var parent = new Folder { Name = "extras" }; var parent = new Folder { Name = "extras" };
var episodeResolver = new EpisodeResolver(Mock.Of<ILogger<EpisodeResolver>>(), _namingOptions); var episodeResolver = new EpisodeResolver(Mock.Of<ILogger<EpisodeResolver>>(), _namingOptions, Mock.Of<IDirectoryService>());
var itemResolveArgs = new ItemResolveArgs( var itemResolveArgs = new ItemResolveArgs(
Mock.Of<IServerApplicationPaths>(), Mock.Of<IServerApplicationPaths>(),
Mock.Of<IDirectoryService>(),
null) null)
{ {
Parent = parent, Parent = parent,
@ -46,10 +45,9 @@ namespace Jellyfin.Server.Implementations.Tests.Library
// Have to create a mock because of moq proxies not being castable to a concrete implementation // Have to create a mock because of moq proxies not being castable to a concrete implementation
// https://github.com/jellyfin/jellyfin/blob/ab0cff8556403e123642dc9717ba778329554634/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs#L48 // https://github.com/jellyfin/jellyfin/blob/ab0cff8556403e123642dc9717ba778329554634/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs#L48
var episodeResolver = new EpisodeResolverMock(Mock.Of<ILogger<EpisodeResolver>>(), _namingOptions); var episodeResolver = new EpisodeResolverMock(Mock.Of<ILogger<EpisodeResolver>>(), _namingOptions, Mock.Of<IDirectoryService>());
var itemResolveArgs = new ItemResolveArgs( var itemResolveArgs = new ItemResolveArgs(
Mock.Of<IServerApplicationPaths>(), Mock.Of<IServerApplicationPaths>(),
Mock.Of<IDirectoryService>(),
null) null)
{ {
Parent = series, Parent = series,
@ -64,7 +62,7 @@ namespace Jellyfin.Server.Implementations.Tests.Library
private sealed class EpisodeResolverMock : EpisodeResolver private sealed class EpisodeResolverMock : EpisodeResolver
{ {
public EpisodeResolverMock(ILogger<EpisodeResolver> logger, NamingOptions namingOptions) : base(logger, namingOptions) public EpisodeResolverMock(ILogger<EpisodeResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService) : base(logger, namingOptions, directoryService)
{ {
} }

View File

@ -18,10 +18,9 @@ public class MovieResolverTests
[Fact] [Fact]
public void Resolve_GivenLocalAlternateVersion_ResolvesToVideo() public void Resolve_GivenLocalAlternateVersion_ResolvesToVideo()
{ {
var movieResolver = new MovieResolver(Mock.Of<IImageProcessor>(), Mock.Of<ILogger<MovieResolver>>(), _namingOptions); var movieResolver = new MovieResolver(Mock.Of<IImageProcessor>(), Mock.Of<ILogger<MovieResolver>>(), _namingOptions, Mock.Of<IDirectoryService>());
var itemResolveArgs = new ItemResolveArgs( var itemResolveArgs = new ItemResolveArgs(
Mock.Of<IServerApplicationPaths>(), Mock.Of<IServerApplicationPaths>(),
Mock.Of<IDirectoryService>(),
null) null)
{ {
Parent = null, Parent = null,