diff options
18 files changed, 251 insertions, 244 deletions
diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index d9d2a345a..f2a0548c2 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -83,8 +83,7 @@ namespace Emby.Dlna { lock (_profiles) { - var list = _profiles.Values.ToList(); - return list + return _profiles.Values .OrderBy(i => i.Item1.Info.Type == DeviceProfileType.User ? 0 : 1) .ThenBy(i => i.Item1.Info.Name) .Select(i => i.Item2) @@ -226,11 +225,8 @@ namespace Emby.Dlna { try { - var xmlFies = _fileSystem.GetFilePaths(path) + return _fileSystem.GetFilePaths(path) .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase)) - .ToList(); - - return xmlFies .Select(i => ParseProfileFile(i, type)) .Where(i => i != null) .ToList()!; // We just filtered out all the nulls @@ -252,11 +248,8 @@ namespace Emby.Dlna try { - DeviceProfile profile; - var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path); - - profile = ReserializeProfile(tempProfile); + var profile = ReserializeProfile(tempProfile); profile.Id = path.ToLowerInvariant().GetMD5().ToString("N", CultureInfo.InvariantCulture); @@ -295,8 +288,7 @@ namespace Emby.Dlna { lock (_profiles) { - var list = _profiles.Values.ToList(); - return list + return _profiles.Values .Select(i => i.Item1) .OrderBy(i => i.Info.Type == DeviceProfileType.User ? 0 : 1) .ThenBy(i => i.Info.Name); diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index b530c6942..18b413964 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Net.Mime; using System.Text; using System.Threading.Tasks; using Jellyfin.Data.Entities; @@ -129,17 +130,19 @@ namespace Emby.Drawing originalImageSize = new ImageDimensions(originalImage.Width, originalImage.Height); } + var mimeType = MimeTypes.GetMimeType(originalImagePath); if (!_imageEncoder.SupportsImageEncoding) { - return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, mimeType, dateModified); } var supportedImageInfo = await GetSupportedImage(originalImagePath, dateModified).ConfigureAwait(false); originalImagePath = supportedImageInfo.Path; - if (!File.Exists(originalImagePath)) + // Original file doesn't exist, or original file is gif. + if (!File.Exists(originalImagePath) || string.Equals(mimeType, MediaTypeNames.Image.Gif, StringComparison.OrdinalIgnoreCase)) { - return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified); + return (originalImagePath, mimeType, dateModified); } dateModified = supportedImageInfo.DateModified; diff --git a/Emby.Naming/Video/ExtraResolver.cs b/Emby.Naming/Video/ExtraRuleResolver.cs index fbdca859f..0970e509a 100644 --- a/Emby.Naming/Video/ExtraResolver.cs +++ b/Emby.Naming/Video/ExtraRuleResolver.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text.RegularExpressions; using Emby.Naming.Audio; using Emby.Naming.Common; @@ -11,7 +9,7 @@ namespace Emby.Naming.Video /// <summary> /// Resolve if file is extra for video. /// </summary> - public static class ExtraResolver + public static class ExtraRuleResolver { private static readonly char[] _digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; @@ -86,66 +84,5 @@ namespace Emby.Naming.Video return result; } - - /// <summary> - /// Finds extras matching the video info. - /// </summary> - /// <param name="files">The list of file video infos.</param> - /// <param name="videoInfo">The video to compare against.</param> - /// <param name="videoFlagDelimiters">The video flag delimiters.</param> - /// <returns>A list of video extras for [videoInfo].</returns> - public static IReadOnlyList<VideoFileInfo> GetExtras(IReadOnlyList<VideoInfo> files, VideoFileInfo videoInfo, ReadOnlySpan<char> videoFlagDelimiters) - { - var parentDir = videoInfo.IsDirectory ? videoInfo.Path : Path.GetDirectoryName(videoInfo.Path.AsSpan()); - - var trimmedFileNameWithoutExtension = TrimFilenameDelimiters(videoInfo.FileNameWithoutExtension, videoFlagDelimiters); - var trimmedVideoInfoName = TrimFilenameDelimiters(videoInfo.Name, videoFlagDelimiters); - - var result = new List<VideoFileInfo>(); - for (var pos = files.Count - 1; pos >= 0; pos--) - { - var current = files[pos]; - // ignore non-extras and multi-file (can this happen?) - if (current.ExtraType == null || current.Files.Count > 1) - { - continue; - } - - var currentFile = current.Files[0]; - var trimmedCurrentFileName = TrimFilenameDelimiters(currentFile.Name, videoFlagDelimiters); - - // first check filenames - bool isValid = StartsWith(trimmedCurrentFileName, trimmedFileNameWithoutExtension) - || (StartsWith(trimmedCurrentFileName, trimmedVideoInfoName) && currentFile.Year == videoInfo.Year); - - // then by directory - if (!isValid) - { - // When the extra rule type is DirectoryName we must go one level higher to get the "real" dir name - var currentParentDir = currentFile.ExtraRule?.RuleType == ExtraRuleType.DirectoryName - ? Path.GetDirectoryName(Path.GetDirectoryName(currentFile.Path.AsSpan())) - : Path.GetDirectoryName(currentFile.Path.AsSpan()); - - isValid = !currentParentDir.IsEmpty && !parentDir.IsEmpty && currentParentDir.Equals(parentDir, StringComparison.OrdinalIgnoreCase); - } - - if (isValid) - { - result.Add(currentFile); - } - } - - return result.OrderBy(r => r.Path).ToArray(); - } - - private static ReadOnlySpan<char> TrimFilenameDelimiters(ReadOnlySpan<char> name, ReadOnlySpan<char> videoFlagDelimiters) - { - return name.IsEmpty ? name : name.TrimEnd().TrimEnd(videoFlagDelimiters).TrimEnd(); - } - - private static bool StartsWith(ReadOnlySpan<char> fileName, ReadOnlySpan<char> baseName) - { - return !baseName.IsEmpty && fileName.StartsWith(baseName, StringComparison.OrdinalIgnoreCase); - } } } diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index 4fc849256..11f82525f 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -42,11 +42,14 @@ namespace Emby.Naming.Video continue; } - remainingFiles.Add(current); if (current.ExtraType == null) { standaloneMedia.Add(current); } + else + { + remainingFiles.Add(current); + } } var list = new List<VideoInfo>(); @@ -69,8 +72,6 @@ namespace Emby.Naming.Video var info = new VideoInfo(media.Name) { Files = new[] { media } }; info.Year = info.Files[0].Year; - - remainingFiles.Remove(media); list.Add(info); } diff --git a/Emby.Naming/Video/VideoResolver.cs b/Emby.Naming/Video/VideoResolver.cs index 9cadc1465..de8e177d8 100644 --- a/Emby.Naming/Video/VideoResolver.cs +++ b/Emby.Naming/Video/VideoResolver.cs @@ -75,7 +75,7 @@ namespace Emby.Naming.Video var format3DResult = Format3DParser.Parse(path, namingOptions); - var extraResult = ExtraResolver.GetExtraInfo(path, namingOptions); + var extraResult = ExtraRuleResolver.GetExtraInfo(path, namingOptions); var name = Path.GetFileNameWithoutExtension(path); diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index d5c0b7107..41f29b835 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -3026,40 +3026,40 @@ namespace Emby.Server.Implementations.Data if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase)) { // TODO - return ("SortName", SortOrder.Descending); + return ("SortName", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.Runtime, StringComparison.OrdinalIgnoreCase)) { - return ("RuntimeTicks", SortOrder.Descending); + return ("RuntimeTicks", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.Random, StringComparison.OrdinalIgnoreCase)) { - return ("RANDOM()", SortOrder.Descending); + return ("RANDOM()", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.DatePlayed, StringComparison.OrdinalIgnoreCase)) { if (query.GroupBySeriesPresentationUniqueKey) { - return ("MAX(LastPlayedDate)", SortOrder.Descending); + return ("MAX(LastPlayedDate)", SortOrder.Ascending); } - return ("LastPlayedDate", SortOrder.Descending); + return ("LastPlayedDate", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.PlayCount, StringComparison.OrdinalIgnoreCase)) { - return ("PlayCount", SortOrder.Descending); + return ("PlayCount", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.IsFavoriteOrLiked, StringComparison.OrdinalIgnoreCase)) { - return ("(Select Case When IsFavorite is null Then 0 Else IsFavorite End )", SortOrder.Ascending); + return ("(Select Case When IsFavorite is null Then 0 Else IsFavorite End )", SortOrder.Descending); } else if (string.Equals(name, ItemSortBy.IsFolder, StringComparison.OrdinalIgnoreCase)) { - return ("IsFolder", SortOrder.Ascending); + return ("IsFolder", SortOrder.Descending); } else if (string.Equals(name, ItemSortBy.IsPlayed, StringComparison.OrdinalIgnoreCase)) { - return ("played", SortOrder.Ascending); + return ("played", SortOrder.Descending); } else if (string.Equals(name, ItemSortBy.IsUnplayed, StringComparison.OrdinalIgnoreCase)) { @@ -3067,34 +3067,34 @@ namespace Emby.Server.Implementations.Data } else if (string.Equals(name, ItemSortBy.DateLastContentAdded, StringComparison.OrdinalIgnoreCase)) { - return ("DateLastMediaAdded", SortOrder.Descending); + return ("DateLastMediaAdded", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.Artist, StringComparison.OrdinalIgnoreCase)) { - return ("(select CleanValue from itemvalues where ItemId=Guid and Type=0 LIMIT 1)", SortOrder.Descending); + return ("(select CleanValue from itemvalues where ItemId=Guid and Type=0 LIMIT 1)", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.AlbumArtist, StringComparison.OrdinalIgnoreCase)) { - return ("(select CleanValue from itemvalues where ItemId=Guid and Type=1 LIMIT 1)", SortOrder.Descending); + return ("(select CleanValue from itemvalues where ItemId=Guid and Type=1 LIMIT 1)", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.OfficialRating, StringComparison.OrdinalIgnoreCase)) { - return ("InheritedParentalRatingValue", SortOrder.Descending); + return ("InheritedParentalRatingValue", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.Studio, StringComparison.OrdinalIgnoreCase)) { - return ("(select CleanValue from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", SortOrder.Descending); + return ("(select CleanValue from itemvalues where ItemId=Guid and Type=3 LIMIT 1)", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.SeriesDatePlayed, StringComparison.OrdinalIgnoreCase)) { - return ("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)", SortOrder.Descending); + return ("(Select MAX(LastPlayedDate) from TypedBaseItems B" + GetJoinUserDataText(query) + " where Played=1 and B.SeriesPresentationUniqueKey=A.PresentationUniqueKey)", SortOrder.Ascending); } else if (string.Equals(name, ItemSortBy.SeriesSortName, StringComparison.OrdinalIgnoreCase)) { - return ("SeriesName", SortOrder.Descending); + return ("SeriesName", SortOrder.Ascending); } - return (name, SortOrder.Descending); + return (name, SortOrder.Ascending); } public List<Guid> GetItemIdsList(InternalItemsQuery query) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 0fa779a0a..db2836a70 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -13,7 +13,7 @@ using System.Threading; using System.Threading.Tasks; using Emby.Naming.Common; using Emby.Naming.TV; -using Emby.Naming.Video; +using Emby.Server.Implementations.Library.Resolvers; using Emby.Server.Implementations.Library.Validators; using Emby.Server.Implementations.Playlists; using Emby.Server.Implementations.ScheduledTasks.Tasks; @@ -78,6 +78,7 @@ namespace Emby.Server.Implementations.Library private readonly IItemRepository _itemRepository; private readonly IImageProcessor _imageProcessor; private readonly NamingOptions _namingOptions; + private readonly ExtraResolver _extraResolver; /// <summary> /// The _root folder sync lock. @@ -146,6 +147,8 @@ namespace Emby.Server.Implementations.Library _memoryCache = memoryCache; _namingOptions = namingOptions; + _extraResolver = new ExtraResolver(namingOptions); + _configurationManager.ConfigurationUpdated += ConfigurationUpdated; RecordConfigurationValues(configurationManager.Configuration); @@ -2692,95 +2695,55 @@ namespace Emby.Server.Implementations.Library } var count = fileSystemChildren.Count; - var files = new List<VideoFileInfo>(); - var nonVideoFiles = new List<FileSystemMetadata>(); for (var i = 0; i < count; i++) { var current = fileSystemChildren[i]; if (current.IsDirectory && _namingOptions.AllExtrasTypesFolderNames.ContainsKey(current.Name)) { - var filesInSubFolder = _fileSystem.GetFiles(current.FullName, _namingOptions.VideoFileExtensions, false, false); + var filesInSubFolder = _fileSystem.GetFiles(current.FullName, null, false, false); foreach (var file in filesInSubFolder) { - var videoInfo = VideoResolver.Resolve(file.FullName, file.IsDirectory, _namingOptions); - if (videoInfo == null) + if (!_extraResolver.TryGetExtraTypeForOwner(file.FullName, ownerVideoInfo, out var extraType)) { - nonVideoFiles.Add(file); continue; } - files.Add(videoInfo); + var extra = GetExtra(file, extraType.Value); + if (extra != null) + { + yield return extra; + } } } - else if (!current.IsDirectory) + else if (!current.IsDirectory && _extraResolver.TryGetExtraTypeForOwner(current.FullName, ownerVideoInfo, out var extraType)) { - var videoInfo = VideoResolver.Resolve(current.FullName, current.IsDirectory, _namingOptions); - if (videoInfo == null) + var extra = GetExtra(current, extraType.Value); + if (extra != null) { - nonVideoFiles.Add(current); - continue; + yield return extra; } - - files.Add(videoInfo); } } - if (files.Count == 0) - { - yield break; - } - - var videos = VideoListResolver.Resolve(files, _namingOptions); - // owner video info cannot be null as that implies it has no path - var extras = ExtraResolver.GetExtras(videos, ownerVideoInfo, _namingOptions.VideoFlagDelimiters); - for (var i = 0; i < extras.Count; i++) + BaseItem GetExtra(FileSystemMetadata file, ExtraType extraType) { - var currentExtra = extras[i]; - var resolved = ResolvePath(_fileSystem.GetFileInfo(currentExtra.Path), null, directoryService); - if (resolved is not Video video) - { - continue; - } - - // Try to retrieve it from the db. If we don't find it, use the resolved version - if (GetItemById(resolved.Id) is Video dbItem) + var extra = ResolvePath(_fileSystem.GetFileInfo(file.FullName), directoryService, _extraResolver.GetResolversForExtraType(extraType)); + if (extra is not Video && extra is not Audio) { - video = dbItem; - } - - video.ExtraType = currentExtra.ExtraType; - video.ParentId = Guid.Empty; - video.OwnerId = owner.Id; - yield return video; - } - - // TODO: theme songs must be handled "manually" (but should we?) since they aren't video files - for (var i = 0; i < nonVideoFiles.Count; i++) - { - var current = nonVideoFiles[i]; - var extraInfo = ExtraResolver.GetExtraInfo(current.FullName, _namingOptions); - if (extraInfo.ExtraType != ExtraType.ThemeSong) - { - continue; - } - - var resolved = ResolvePath(current, null, directoryService); - if (resolved is not Audio themeSong) - { - continue; + return null; } // Try to retrieve it from the db. If we don't find it, use the resolved version - if (GetItemById(themeSong.Id) is Audio dbItem) + var itemById = GetItemById(extra.Id); + if (itemById != null) { - themeSong = dbItem; + extra = itemById; } - themeSong.ExtraType = ExtraType.ThemeSong; - themeSong.OwnerId = owner.Id; - themeSong.ParentId = Guid.Empty; - - yield return themeSong; + extra.ExtraType = extraType; + extra.ParentId = Guid.Empty; + extra.OwnerId = owner.Id; + return extra; } } diff --git a/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs b/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs new file mode 100644 index 000000000..3d06ceb5e --- /dev/null +++ b/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs @@ -0,0 +1,93 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using Emby.Naming.Common; +using Emby.Naming.Video; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Resolvers; +using MediaBrowser.Model.Entities; +using static Emby.Naming.Video.ExtraRuleResolver; + +namespace Emby.Server.Implementations.Library.Resolvers +{ + /// <summary> + /// Resolves a Path into a Video or Video subclass. + /// </summary> + internal class ExtraResolver + { + private readonly NamingOptions _namingOptions; + private readonly IItemResolver[] _trailerResolvers; + private readonly IItemResolver[] _videoResolvers; + + /// <summary> + /// Initializes an new instance of the <see cref="ExtraResolver"/> class. + /// </summary> + /// <param name="namingOptions">An instance of <see cref="NamingOptions"/>.</param> + public ExtraResolver(NamingOptions namingOptions) + { + _namingOptions = namingOptions; + _trailerResolvers = new IItemResolver[] { new GenericVideoResolver<Trailer>(namingOptions) }; + _videoResolvers = new IItemResolver[] { new GenericVideoResolver<Video>(namingOptions) }; + } + + /// <summary> + /// Gets the resolvers for the extra type. + /// </summary> + /// <param name="extraType">The extra type.</param> + /// <returns>The resolvers for the extra type.</returns> + public IItemResolver[]? GetResolversForExtraType(ExtraType extraType) => extraType switch + { + ExtraType.Trailer => _trailerResolvers, + // For audio we'll have to rely on the AudioResolver, which is a "built-in" + ExtraType.ThemeSong => null, + _ => _videoResolvers + }; + + public bool TryGetExtraTypeForOwner(string path, VideoFileInfo ownerVideoFileInfo, [NotNullWhen(true)] out ExtraType? extraType) + { + var extraResult = GetExtraInfo(path, _namingOptions); + if (extraResult.ExtraType == null) + { + extraType = null; + return false; + } + + var cleanDateTimeResult = CleanDateTimeParser.Clean(Path.GetFileNameWithoutExtension(path), _namingOptions.CleanDateTimeRegexes); + var name = cleanDateTimeResult.Name; + var year = cleanDateTimeResult.Year; + + var parentDir = ownerVideoFileInfo.IsDirectory ? ownerVideoFileInfo.Path : Path.GetDirectoryName(ownerVideoFileInfo.Path.AsSpan()); + + var trimmedFileNameWithoutExtension = TrimFilenameDelimiters(ownerVideoFileInfo.FileNameWithoutExtension, _namingOptions.VideoFlagDelimiters); + var trimmedVideoInfoName = TrimFilenameDelimiters(ownerVideoFileInfo.Name, _namingOptions.VideoFlagDelimiters); + var trimmedExtraFileName = TrimFilenameDelimiters(name, _namingOptions.VideoFlagDelimiters); + + // first check filenames + bool isValid = StartsWith(trimmedExtraFileName, trimmedFileNameWithoutExtension) + || (StartsWith(trimmedExtraFileName, trimmedVideoInfoName) && year == ownerVideoFileInfo.Year); + + if (!isValid) + { + // When the extra rule type is DirectoryName we must go one level higher to get the "real" dir name + var currentParentDir = extraResult.Rule?.RuleType == ExtraRuleType.DirectoryName + ? Path.GetDirectoryName(Path.GetDirectoryName(path.AsSpan())) + : Path.GetDirectoryName(path.AsSpan()); + + isValid = !currentParentDir.IsEmpty && !parentDir.IsEmpty && currentParentDir.Equals(parentDir, StringComparison.OrdinalIgnoreCase); + } + + extraType = extraResult.ExtraType; + return isValid; + } + + private static ReadOnlySpan<char> TrimFilenameDelimiters(ReadOnlySpan<char> name, ReadOnlySpan<char> videoFlagDelimiters) + { + return name.IsEmpty ? name : name.TrimEnd().TrimEnd(videoFlagDelimiters).TrimEnd(); + } + + private static bool StartsWith(ReadOnlySpan<char> fileName, ReadOnlySpan<char> baseName) + { + return !baseName.IsEmpty && fileName.StartsWith(baseName, StringComparison.OrdinalIgnoreCase); + } + } +} diff --git a/Emby.Server.Implementations/Library/Resolvers/GenericVideoResolver.cs b/Emby.Server.Implementations/Library/Resolvers/GenericVideoResolver.cs new file mode 100644 index 000000000..b8554bd51 --- /dev/null +++ b/Emby.Server.Implementations/Library/Resolvers/GenericVideoResolver.cs @@ -0,0 +1,24 @@ +#nullable disable + +using Emby.Naming.Common; +using MediaBrowser.Controller.Entities; + +namespace Emby.Server.Implementations.Library.Resolvers +{ + /// <summary> + /// Resolves a Path into an instance of the <see cref="Video"/> class. + /// </summary> + /// <typeparam name="T">The type of item to resolve.</typeparam> + public class GenericVideoResolver<T> : BaseVideoResolver<T> + where T : Video, new() + { + /// <summary> + /// Initializes a new instance of the <see cref="GenericVideoResolver{T}"/> class. + /// </summary> + /// <param name="namingOptions">The naming options.</param> + public GenericVideoResolver(NamingOptions namingOptions) + : base(namingOptions) + { + } + } +} diff --git a/Emby.Server.Implementations/Library/Resolvers/VideoExtraResolver.cs b/Emby.Server.Implementations/Library/Resolvers/VideoExtraResolver.cs deleted file mode 100644 index 9aadce88c..000000000 --- a/Emby.Server.Implementations/Library/Resolvers/VideoExtraResolver.cs +++ /dev/null @@ -1,55 +0,0 @@ -#nullable disable - -using Emby.Naming.Common; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Entities; - -namespace Emby.Server.Implementations.Library.Resolvers -{ - /// <summary> - /// Resolves a Path into a Video or Video subclass. - /// </summary> - public class VideoExtraResolver : BaseVideoResolver<Video> - { - /// <summary> - /// Initializes a new instance of the <see cref="VideoExtraResolver"/> class. - /// </summary> - /// <param name="namingOptions">The naming options.</param> - public VideoExtraResolver(NamingOptions namingOptions) - : base(namingOptions) - { - } - - /// <summary> - /// Gets the priority. - /// </summary> - /// <value>The priority.</value> - public override ResolverPriority Priority => ResolverPriority.Last; - - /// <summary> - /// Resolves the specified args. - /// </summary> - /// <param name="args">The args.</param> - /// <returns>The video extra or null if not handled by this resolver.</returns> - public override Video Resolve(ItemResolveArgs args) - { - // Only handle owned items - if (args.Parent != null) - { - return null; - } - - var ownedItem = base.Resolve(args); - - // Re-resolve items that have their own type - if (ownedItem.ExtraType == ExtraType.Trailer) - { - ownedItem = ResolveVideo<Trailer>(args, false); - } - - return ownedItem; - } - } -} diff --git a/Emby.Server.Implementations/Localization/Core/de.json b/Emby.Server.Implementations/Localization/Core/de.json index c924e5c15..115f36e7c 100644 --- a/Emby.Server.Implementations/Localization/Core/de.json +++ b/Emby.Server.Implementations/Localization/Core/de.json @@ -71,7 +71,7 @@ "ScheduledTaskStartedWithName": "{0} wurde gestartet", "ServerNameNeedsToBeRestarted": "{0} muss neu gestartet werden", "Shows": "Serien", - "Songs": "Songs", + "Songs": "Lieder", "StartupEmbyServerIsLoading": "Jellyfin-Server startet, bitte versuche es gleich noch einmal.", "SubtitleDownloadFailureForItem": "Download der Untertitel fehlgeschlagen für {0}", "SubtitleDownloadFailureFromForItem": "Untertitel von {0} für {1} konnten nicht heruntergeladen werden", @@ -92,25 +92,25 @@ "ValueHasBeenAddedToLibrary": "{0} wurde deiner Bibliothek hinzugefügt", "ValueSpecialEpisodeName": "Extra - {0}", "VersionNumber": "Version {0}", - "TaskDownloadMissingSubtitlesDescription": "Durchsucht das Internet nach fehlenden Untertiteln, basierend auf den Meta Einstellungen.", + "TaskDownloadMissingSubtitlesDescription": "Suche im Internet basierend auf den Metadaten-Einstellungen nach fehlenden Untertiteln.", "TaskDownloadMissingSubtitles": "Lade fehlende Untertitel herunter", - "TaskRefreshChannelsDescription": "Aktualisiere Internet Kanal Informationen.", + "TaskRefreshChannelsDescription": "Aktualisiere Internet-Kanal-Informationen.", "TaskRefreshChannels": "Aktualisiere Kanäle", - "TaskCleanTranscodeDescription": "Löscht Transkodierdateien, welche älter als einen Tag sind.", - "TaskCleanTranscode": "Lösche Transkodier-Pfad", + "TaskCleanTranscodeDescription": "Löscht Transkodierdateien, die älter als einen Tag sind.", + "TaskCleanTranscode": "Räume Transkodierungs-Verzeichnis auf", "TaskUpdatePluginsDescription": "Lädt Updates für Plugins herunter, welche für automatische Updates konfiguriert sind und installiert diese.", "TaskUpdatePlugins": "Aktualisiere Plugins", "TaskRefreshPeopleDescription": "Aktualisiert Metadaten für Schauspieler und Regisseure in deinen Bibliotheken.", - "TaskRefreshPeople": "Aktualisiere Schauspieler", - "TaskCleanLogsDescription": "Lösche Log Dateien, die älter als {0} Tage sind.", - "TaskCleanLogs": "Lösche Log-Verzeichnis", - "TaskRefreshLibraryDescription": "Scanne alle Bibliotheken nach neu hinzugefügten Dateien und aktualisiere Metadaten.", + "TaskRefreshPeople": "Aktualisiere Personen", + "TaskCleanLogsDescription": "Lösche Log-Dateien, die älter als {0} Tage sind.", + "TaskCleanLogs": "Räumt Log-Verzeichnis auf", + "TaskRefreshLibraryDescription": "Scannt alle Bibliotheken nach neu hinzugefügten Dateien und aktualisiere Metadaten.", "TaskRefreshLibrary": "Scanne Medien-Bibliothek", - "TaskRefreshChapterImagesDescription": "Erstellt Vorschaubilder für Videos, welche Kapitel besitzen.", - "TaskRefreshChapterImages": "Extrahiert Kapitel-Bilder", + "TaskRefreshChapterImagesDescription": "Erstellt Vorschaubilder für Videos, die Kapitel besitzen.", + "TaskRefreshChapterImages": "Extrahiere Kapitel-Bilder", "TaskCleanCacheDescription": "Löscht nicht mehr benötigte Zwischenspeicherdateien.", "TaskCleanCache": "Leere Zwischenspeicher", - "TasksChannelsCategory": "Internet Kanäle", + "TasksChannelsCategory": "Internet-Kanäle", "TasksApplicationCategory": "Anwendung", "TasksLibraryCategory": "Bibliothek", "TasksMaintenanceCategory": "Wartung", diff --git a/Emby.Server.Implementations/Localization/Core/ru.json b/Emby.Server.Implementations/Localization/Core/ru.json index 2d7163275..dc3793f1b 100644 --- a/Emby.Server.Implementations/Localization/Core/ru.json +++ b/Emby.Server.Implementations/Localization/Core/ru.json @@ -96,7 +96,7 @@ "TaskRefreshChannels": "Обновление каналов", "TaskCleanTranscode": "Очистка каталога перекодировки", "TaskUpdatePlugins": "Обновление плагинов", - "TaskRefreshPeople": "Подновить людей", + "TaskRefreshPeople": "Подновление людей", "TaskCleanLogs": "Очистка каталога журналов", "TaskRefreshLibrary": "Сканирование медиатеки", "TaskRefreshChapterImages": "Извлечение изображений сцен", @@ -115,10 +115,10 @@ "TaskRefreshChapterImagesDescription": "Создаются эскизы для видео, которые содержат сцены.", "TaskCleanCacheDescription": "Удаляются файлы кэша, которые больше не нужны системе.", "TaskCleanActivityLogDescription": "Удаляет записи журнала активности старше установленного возраста.", - "TaskCleanActivityLog": "Очистить журнал активности", + "TaskCleanActivityLog": "Очистка журнала активности", "Undefined": "Не определено", "Forced": "Форсир-ые", "Default": "По умолчанию", "TaskOptimizeDatabaseDescription": "Сжимает базу данных и вырезает свободные места. Выполнение этой задачи после сканирования библиотеки или внесения других изменений, предполагающих модификации базы данных, может повысить производительность.", - "TaskOptimizeDatabase": "Оптимизировать базу данных" + "TaskOptimizeDatabase": "Оптимизация базы данных" } diff --git a/Emby.Server.Implementations/Localization/Core/sv.json b/Emby.Server.Implementations/Localization/Core/sv.json index f3f601661..5d05361b0 100644 --- a/Emby.Server.Implementations/Localization/Core/sv.json +++ b/Emby.Server.Implementations/Localization/Core/sv.json @@ -16,7 +16,7 @@ "Folders": "Mappar", "Genres": "Genrer", "HeaderAlbumArtists": "Albumsartister", - "HeaderContinueWatching": "Fortsätt kolla", + "HeaderContinueWatching": "Fortsätt kolla på", "HeaderFavoriteAlbums": "Favoritalbum", "HeaderFavoriteArtists": "Favoritartister", "HeaderFavoriteEpisodes": "Favoritavsnitt", diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj index eb82a9d2b..12efa15dd 100644 --- a/Jellyfin.Server/Jellyfin.Server.csproj +++ b/Jellyfin.Server/Jellyfin.Server.csproj @@ -47,7 +47,7 @@ <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" /> <PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" /> <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> - <PackageReference Include="Serilog.Sinks.Graylog" Version="2.2.2" /> + <PackageReference Include="Serilog.Sinks.Graylog" Version="2.3.0" /> <PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" /> </ItemGroup> diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs index 3b03466e9..ee8451853 100644 --- a/MediaBrowser.Model/Net/MimeTypes.cs +++ b/MediaBrowser.Model/Net/MimeTypes.cs @@ -116,6 +116,7 @@ namespace MediaBrowser.Model.Net { "audio/x-wavpack", ".wv" }, // Type image + { "image/jpg", ".jpg" }, { "image/jpeg", ".jpg" }, { "image/x-png", ".png" }, diff --git a/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs b/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs index cbab455f0..7b50c54b0 100644 --- a/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs +++ b/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs @@ -124,6 +124,7 @@ namespace Jellyfin.Model.Tests.Net [InlineData("font/woff2", ".woff2")] [InlineData("image/bmp", ".bmp")] [InlineData("image/gif", ".gif")] + [InlineData("image/jpg", ".jpg")] [InlineData("image/jpeg", ".jpg")] [InlineData("image/png", ".png")] [InlineData("image/svg+xml", ".svg")] diff --git a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs index 24f9bf98d..731580e0c 100644 --- a/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs +++ b/tests/Jellyfin.Naming.Tests/Video/ExtraTests.cs @@ -82,7 +82,7 @@ namespace Jellyfin.Naming.Tests.Video private void Test(string input, ExtraType? expectedType) { - var extraType = ExtraResolver.GetExtraInfo(input, _videoOptions).ExtraType; + var extraType = ExtraRuleResolver.GetExtraInfo(input, _videoOptions).ExtraType; Assert.Equal(expectedType, extraType); } @@ -92,7 +92,7 @@ namespace Jellyfin.Naming.Tests.Video { var rule = new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, @"([eE]x(tra)?\.\w+)", MediaType.Video); var options = new NamingOptions { VideoExtraRules = new[] { rule } }; - var res = ExtraResolver.GetExtraInfo("extra.mp4", options); + var res = ExtraRuleResolver.GetExtraInfo("extra.mp4", options); Assert.Equal(rule, res.Rule); } diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs index 3ce29f28c..de4421320 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/LibraryManager/FindExtrasTests.cs @@ -1,16 +1,18 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using AutoFixture; using AutoFixture.AutoMoq; using Emby.Naming.Common; -using Emby.Server.Implementations.Library.Resolvers; using Emby.Server.Implementations.Library.Resolvers.Audio; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Sorting; @@ -32,11 +34,13 @@ public class FindExtrasTests fixture.Register(() => new NamingOptions()); var configMock = fixture.Freeze<Mock<IServerConfigurationManager>>(); configMock.Setup(c => c.ApplicationPaths.ProgramDataPath).Returns("/data"); + var itemRepository = fixture.Freeze<Mock<IItemRepository>>(); + itemRepository.Setup(i => i.RetrieveItem(It.IsAny<Guid>())).Returns<BaseItem>(null); _fileSystemMock = fixture.Freeze<Mock<IFileSystem>>(); _fileSystemMock.Setup(f => f.GetFileInfo(It.IsAny<string>())).Returns<string>(path => new FileSystemMetadata { FullName = path }); _libraryManager = fixture.Build<Emby.Server.Implementations.Library.LibraryManager>().Do(s => s.AddParts( fixture.Create<IEnumerable<IResolverIgnoreRule>>(), - new List<IItemResolver> { new VideoExtraResolver(fixture.Create<NamingOptions>()), new AudioResolver(fixture.Create<NamingOptions>()) }, + new List<IItemResolver> { new AudioResolver(fixture.Create<NamingOptions>()) }, fixture.Create<IEnumerable<IIntroProvider>>(), fixture.Create<IEnumerable<IBaseItemComparer>>(), fixture.Create<IEnumerable<ILibraryPostScanTask>>())) @@ -104,7 +108,7 @@ public class FindExtrasTests Name = "some trailer.mkv", IsDirectory = false } - }); + }).Verifiable(); _fileSystemMock.Setup(f => f.GetFiles( "/movies/Up/behind the scenes", @@ -119,7 +123,7 @@ public class FindExtrasTests Name = "the making of Up.mkv", IsDirectory = false } - }); + }).Verifiable(); _fileSystemMock.Setup(f => f.GetFiles( "/movies/Up/theme-music", @@ -134,17 +138,18 @@ public class FindExtrasTests Name = "theme2.mp3", IsDirectory = false } - }); + }).Verifiable(); var files = paths.Select(p => new FileSystemMetadata { FullName = p, Name = Path.GetFileName(p), - IsDirectory = string.IsNullOrEmpty(Path.GetExtension(p)) + IsDirectory = !Path.HasExtension(p) }).ToList(); var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList(); + _fileSystemMock.Verify(); Assert.Equal(6, extras.Count); Assert.Equal(ExtraType.Trailer, extras[0].ExtraType); Assert.Equal(typeof(Trailer), extras[0].GetType()); @@ -153,7 +158,9 @@ public class FindExtrasTests Assert.Equal(ExtraType.BehindTheScenes, extras[2].ExtraType); Assert.Equal(ExtraType.Sample, extras[3].ExtraType); Assert.Equal(ExtraType.ThemeSong, extras[4].ExtraType); + Assert.Equal(typeof(Audio), extras[4].GetType()); Assert.Equal(ExtraType.ThemeSong, extras[5].ExtraType); + Assert.Equal(typeof(Audio), extras[5].GetType()); } [Fact] @@ -210,6 +217,46 @@ public class FindExtrasTests } [Fact] + public void FindExtras_WrongExtensions_FindsNoExtras() + { + var owner = new Movie { Name = "Up", Path = "/movies/Up/Up.mkv" }; + var paths = new List<string> + { + "/movies/Up/Up.mkv", + "/movies/Up/trailer.noext", + "/movies/Up/theme.png", + "/movies/Up/trailers" + }; + + var files = paths.Select(p => new FileSystemMetadata + { + FullName = p, + Name = Path.GetFileName(p), + IsDirectory = !Path.HasExtension(p) + }).ToList(); + + _fileSystemMock.Setup(f => f.GetFiles( + "/movies/Up/trailers", + It.IsAny<string[]>(), + false, + false)) + .Returns(new List<FileSystemMetadata> + { + new() + { + FullName = "/movies/Up/trailers/trailer.jpg", + Name = "trailer.jpg", + IsDirectory = false + } + }).Verifiable(); + + var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList(); + + _fileSystemMock.Verify(); + Assert.Empty(extras); + } + + [Fact] public void FindExtras_SeriesWithTrailers_FindsCorrectExtras() { var owner = new Series { Name = "Dexter", Path = "/series/Dexter" }; |
