Pārlūkot izejas kodu

Merge pull request #5985 from Bond-009/minor11

Bond-009 4 gadi atpakaļ
vecāks
revīzija
95b1cf532b

+ 6 - 6
Emby.Server.Implementations/Library/Resolvers/ItemResolver.cs

@@ -11,6 +11,12 @@ namespace Emby.Server.Implementations.Library.Resolvers
     public abstract class ItemResolver<T> : IItemResolver
         where T : BaseItem, new()
     {
+        /// <summary>
+        /// Gets the priority.
+        /// </summary>
+        /// <value>The priority.</value>
+        public virtual ResolverPriority Priority => ResolverPriority.First;
+
         /// <summary>
         /// Resolves the specified args.
         /// </summary>
@@ -21,12 +27,6 @@ namespace Emby.Server.Implementations.Library.Resolvers
             return null;
         }
 
-        /// <summary>
-        /// Gets the priority.
-        /// </summary>
-        /// <value>The priority.</value>
-        public virtual ResolverPriority Priority => ResolverPriority.First;
-
         /// <summary>
         /// Sets initial values on the newly resolved item.
         /// </summary>

+ 1 - 1
Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs

@@ -376,7 +376,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
         {
             var multiDiscFolders = new List<FileSystemMetadata>();
 
-            var libraryOptions = args.GetLibraryOptions();
+            var libraryOptions = args.LibraryOptions;
             var supportPhotos = string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && libraryOptions.EnablePhotos;
             var photos = new List<FileSystemMetadata>();
 

+ 6 - 6
Emby.Server.Implementations/Library/Resolvers/PhotoAlbumResolver.cs

@@ -13,7 +13,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
     public class PhotoAlbumResolver : FolderResolver<PhotoAlbum>
     {
         private readonly IImageProcessor _imageProcessor;
-        private ILibraryManager _libraryManager;
+        private readonly ILibraryManager _libraryManager;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="PhotoAlbumResolver"/> class.
@@ -26,6 +26,9 @@ namespace Emby.Server.Implementations.Library.Resolvers
             _libraryManager = libraryManager;
         }
 
+        /// <inheritdoc />
+        public override ResolverPriority Priority => ResolverPriority.Second;
+
         /// <summary>
         /// Resolves the specified args.
         /// </summary>
@@ -39,8 +42,8 @@ namespace Emby.Server.Implementations.Library.Resolvers
                 // Must be an image file within a photo collection
                 var collectionType = args.GetCollectionType();
 
-                if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase) ||
-                    (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
+                if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)
+                    || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.LibraryOptions.EnablePhotos))
                 {
                     if (HasPhotos(args))
                     {
@@ -84,8 +87,5 @@ namespace Emby.Server.Implementations.Library.Resolvers
 
             return false;
         }
-
-        /// <inheritdoc />
-        public override ResolverPriority Priority => ResolverPriority.Second;
     }
 }

+ 1 - 1
Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs

@@ -47,7 +47,7 @@ namespace Emby.Server.Implementations.Library.Resolvers
                 var collectionType = args.CollectionType;
 
                 if (string.Equals(collectionType, CollectionType.Photos, StringComparison.OrdinalIgnoreCase)
-                    || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.GetLibraryOptions().EnablePhotos))
+                    || (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase) && args.LibraryOptions.EnablePhotos))
                 {
                     if (IsImageFile(args.Path, _imageProcessor))
                     {

+ 1 - 1
Emby.Server.Implementations/Library/Resolvers/TV/SeasonResolver.cs

@@ -88,7 +88,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
                             CultureInfo.InvariantCulture,
                             _localization.GetLocalizedString("NameSeasonNumber"),
                             seasonNumber,
-                            args.GetLibraryOptions().PreferredMetadataLanguage);
+                            args.LibraryOptions.PreferredMetadataLanguage);
                 }
 
                 return season;

+ 2 - 16
Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs

@@ -19,19 +19,16 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
     /// </summary>
     public class SeriesResolver : FolderResolver<Series>
     {
-        private readonly IFileSystem _fileSystem;
         private readonly ILogger<SeriesResolver> _logger;
         private readonly ILibraryManager _libraryManager;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="SeriesResolver"/> class.
         /// </summary>
-        /// <param name="fileSystem">The file system.</param>
         /// <param name="logger">The logger.</param>
         /// <param name="libraryManager">The library manager.</param>
-        public SeriesResolver(IFileSystem fileSystem, ILogger<SeriesResolver> logger, ILibraryManager libraryManager)
+        public SeriesResolver(ILogger<SeriesResolver> logger, ILibraryManager libraryManager)
         {
-            _fileSystem = fileSystem;
             _logger = logger;
             _libraryManager = libraryManager;
         }
@@ -59,15 +56,6 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
                 var collectionType = args.GetCollectionType();
                 if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                 {
-                    // if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
-                    //{
-                    //    return new Series
-                    //    {
-                    //        Path = args.Path,
-                    //        Name = Path.GetFileName(args.Path)
-                    //    };
-                    //}
-
                     var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path);
                     if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                     {
@@ -100,7 +88,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
                         return null;
                     }
 
-                    if (IsSeriesFolder(args.Path, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger, _libraryManager, false))
+                    if (IsSeriesFolder(args.Path, args.FileSystemChildren, _logger, _libraryManager, false))
                     {
                         return new Series
                         {
@@ -117,8 +105,6 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
         public static bool IsSeriesFolder(
             string path,
             IEnumerable<FileSystemMetadata> fileSystemChildren,
-            IDirectoryService directoryService,
-            IFileSystem fileSystem,
             ILogger<SeriesResolver> logger,
             ILibraryManager libraryManager,
             bool isTvContentType)

+ 0 - 1
MediaBrowser.Controller/Entities/CollectionFolder.cs

@@ -61,7 +61,6 @@ namespace MediaBrowser.Controller.Entities
             try
             {
                 var result = XmlSerializer.DeserializeFromFile(typeof(LibraryOptions), GetLibraryOptionsPath(path)) as LibraryOptions;
-
                 if (result == null)
                 {
                     return new LibraryOptions();

+ 0 - 18
MediaBrowser.Controller/Entities/PeopleHelper.cs

@@ -100,23 +100,5 @@ namespace MediaBrowser.Controller.Entities
                 existing.SetProviderId(id.Key, id.Value);
             }
         }
-
-        public static bool ContainsPerson(List<PersonInfo> people, string name)
-        {
-            if (string.IsNullOrEmpty(name))
-            {
-                throw new ArgumentNullException(nameof(name));
-            }
-
-            foreach (var i in people)
-            {
-                if (string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase))
-                {
-                    return true;
-                }
-            }
-
-            return false;
-        }
     }
 }

+ 9 - 9
MediaBrowser.Controller/Library/ItemResolveArgs.cs

@@ -14,14 +14,14 @@ namespace MediaBrowser.Controller.Library
     /// These are arguments relating to the file system that are collected once and then referred to
     /// whenever needed.  Primarily for entity resolution.
     /// </summary>
-    public class ItemResolveArgs : EventArgs
+    public class ItemResolveArgs
     {
         /// <summary>
         /// The _app paths.
         /// </summary>
         private readonly IServerApplicationPaths _appPaths;
 
-        public IDirectoryService DirectoryService { get; private set; }
+        private LibraryOptions _libraryOptions;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ItemResolveArgs" /> class.
@@ -34,17 +34,18 @@ namespace MediaBrowser.Controller.Library
             DirectoryService = directoryService;
         }
 
+        public IDirectoryService DirectoryService { get; }
+
         /// <summary>
         /// Gets the file system children.
         /// </summary>
         /// <value>The file system children.</value>
         public FileSystemMetadata[] FileSystemChildren { get; set; }
 
-        public LibraryOptions LibraryOptions { get; set; }
-
-        public LibraryOptions GetLibraryOptions()
+        public LibraryOptions LibraryOptions
         {
-            return LibraryOptions ?? (LibraryOptions = Parent == null ? new LibraryOptions() : BaseItem.LibraryManager.GetLibraryOptions(Parent));
+            get => _libraryOptions ??= Parent == null ? new LibraryOptions() : BaseItem.LibraryManager.GetLibraryOptions(Parent);
+            set => _libraryOptions = value;
         }
 
         /// <summary>
@@ -139,7 +140,7 @@ namespace MediaBrowser.Controller.Library
         /// Adds the additional location.
         /// </summary>
         /// <param name="path">The path.</param>
-        /// <exception cref="ArgumentNullException"></exception>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/> is <c>null</c> or empty.</exception>
         public void AddAdditionalLocation(string path)
         {
             if (string.IsNullOrEmpty(path))
@@ -148,7 +149,6 @@ namespace MediaBrowser.Controller.Library
             }
 
             AdditionalLocations ??= new List<string>();
-
             AdditionalLocations.Add(path);
         }
 
@@ -172,7 +172,7 @@ namespace MediaBrowser.Controller.Library
         /// </summary>
         /// <param name="name">The name.</param>
         /// <returns>FileSystemInfo.</returns>
-        /// <exception cref="ArgumentNullException"></exception>
+        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c> or empty.</exception>
         public FileSystemMetadata GetFileSystemEntryByName(string name)
         {
             if (string.IsNullOrEmpty(name))

+ 6 - 6
MediaBrowser.Controller/Resolvers/BaseItemResolver.cs

@@ -10,6 +10,12 @@ namespace MediaBrowser.Controller.Resolvers
     public abstract class ItemResolver<T> : IItemResolver
         where T : BaseItem, new()
     {
+        /// <summary>
+        /// Gets the priority.
+        /// </summary>
+        /// <value>The priority.</value>
+        public virtual ResolverPriority Priority => ResolverPriority.First;
+
         /// <summary>
         /// Resolves the specified args.
         /// </summary>
@@ -20,12 +26,6 @@ namespace MediaBrowser.Controller.Resolvers
             return null;
         }
 
-        /// <summary>
-        /// Gets the priority.
-        /// </summary>
-        /// <value>The priority.</value>
-        public virtual ResolverPriority Priority => ResolverPriority.First;
-
         /// <summary>
         /// Sets initial values on the newly resolved item.
         /// </summary>

+ 4 - 7
MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs

@@ -29,7 +29,7 @@ namespace MediaBrowser.MediaEncoding.Probing
         private readonly ILogger _logger;
         private readonly ILocalizationManager _localization;
 
-        private List<string> _splitWhiteList = null;
+        private string[] _splitWhiteList;
 
         public ProbeResultNormalizer(ILogger logger, ILocalizationManager localization)
         {
@@ -37,6 +37,8 @@ namespace MediaBrowser.MediaEncoding.Probing
             _localization = localization;
         }
 
+        private IReadOnlyList<string> SplitWhitelist => _splitWhiteList ??= new string[] { "AC/DC" };
+
         public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol)
         {
             var info = new MediaInfo
@@ -1254,7 +1256,7 @@ namespace MediaBrowser.MediaEncoding.Probing
 
             var artistsFound = new List<string>();
 
-            foreach (var whitelistArtist in GetSplitWhitelist())
+            foreach (var whitelistArtist in SplitWhitelist)
             {
                 var originalVal = val;
                 val = val.Replace(whitelistArtist, "|", StringComparison.OrdinalIgnoreCase);
@@ -1273,11 +1275,6 @@ namespace MediaBrowser.MediaEncoding.Probing
             return artistsFound;
         }
 
-        private IEnumerable<string> GetSplitWhitelist()
-        {
-            return _splitWhiteList ??= new List<string> { "AC/DC" };
-        }
-
         /// <summary>
         /// Gets the studios from the tags collection.
         /// </summary>

+ 5 - 5
MediaBrowser.Model/Entities/MediaStream.cs

@@ -163,7 +163,7 @@ namespace MediaBrowser.Model.Entities
                             foreach (var tag in attributes)
                             {
                                 // Keep Tags that are not already in Title.
-                                if (Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
+                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
                                 {
                                     result.Append(" - ").Append(tag);
                                 }
@@ -202,7 +202,7 @@ namespace MediaBrowser.Model.Entities
                             foreach (var tag in attributes)
                             {
                                 // Keep Tags that are not already in Title.
-                                if (Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
+                                if (!Title.Contains(tag, StringComparison.OrdinalIgnoreCase))
                                 {
                                     result.Append(" - ").Append(tag);
                                 }
@@ -522,9 +522,9 @@ namespace MediaBrowser.Model.Entities
 
             // sub = external .sub file
 
-            return codec.IndexOf("pgs", StringComparison.OrdinalIgnoreCase) == -1 &&
-                   codec.IndexOf("dvd", StringComparison.OrdinalIgnoreCase) == -1 &&
-                   codec.IndexOf("dvbsub", StringComparison.OrdinalIgnoreCase) == -1 &&
+            return !codec.Contains("pgs", StringComparison.OrdinalIgnoreCase) &&
+                   !codec.Contains("dvd", StringComparison.OrdinalIgnoreCase) &&
+                   !codec.Contains("dvbsub", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(codec, "sub", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(codec, "dvb_subtitle", StringComparison.OrdinalIgnoreCase);
         }

+ 6 - 6
MediaBrowser.Providers/Subtitles/SubtitleManager.cs

@@ -207,7 +207,7 @@ namespace MediaBrowser.Providers.Subtitles
                 {
                     var mediaFolderPath = Path.GetFullPath(Path.Combine(video.ContainingFolderPath, saveFileName));
                     // TODO: Add some error handling to the API user: return BadRequest("Could not save subtitle, bad path.");
-                    if (mediaFolderPath.StartsWith(video.ContainingFolderPath))
+                    if (mediaFolderPath.StartsWith(video.ContainingFolderPath, StringComparison.Ordinal))
                     {
                         savePaths.Add(mediaFolderPath);
                     }
@@ -216,7 +216,7 @@ namespace MediaBrowser.Providers.Subtitles
                 var internalPath = Path.GetFullPath(Path.Combine(video.GetInternalMetadataPath(), saveFileName));
 
                 // TODO: Add some error to the user: return BadRequest("Could not save subtitle, bad path.");
-                if (internalPath.StartsWith(video.GetInternalMetadataPath()))
+                if (internalPath.StartsWith(video.GetInternalMetadataPath(), StringComparison.Ordinal))
                 {
                     savePaths.Add(internalPath);
                 }
@@ -234,7 +234,7 @@ namespace MediaBrowser.Providers.Subtitles
 
         private async Task TrySaveToFiles(Stream stream, List<string> savePaths)
         {
-            Exception exceptionToThrow = null;
+            List<Exception> exs = null;
 
             foreach (var savePath in savePaths)
             {
@@ -256,7 +256,7 @@ namespace MediaBrowser.Providers.Subtitles
                 }
                 catch (Exception ex)
                 {
-                    exceptionToThrow ??= ex;
+                    (exs ??= new List<Exception>()).Add(ex);
                 }
                 finally
                 {
@@ -266,9 +266,9 @@ namespace MediaBrowser.Providers.Subtitles
                 stream.Position = 0;
             }
 
-            if (exceptionToThrow != null)
+            if (exs != null)
             {
-                throw exceptionToThrow;
+                throw new AggregateException(exs);
             }
         }