From 2e1ec2858a5bd2a03d8dd5fd0ae9f9c11487ed7f Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Wed, 1 Apr 2020 18:53:19 +0200 Subject: Match using directory names in ExtraResolver --- Emby.Naming/Common/NamingOptions.cs | 10 +++++++++- Emby.Naming/Video/ExtraResolver.cs | 9 +++++++++ Emby.Naming/Video/ExtraRuleType.cs | 13 +++++++++---- 3 files changed, 27 insertions(+), 5 deletions(-) (limited to 'Emby.Naming') diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs index 793847f84..8ac33d3f5 100644 --- a/Emby.Naming/Common/NamingOptions.cs +++ b/Emby.Naming/Common/NamingOptions.cs @@ -505,7 +505,15 @@ namespace Emby.Naming.Common RuleType = ExtraRuleType.Suffix, Token = "-short", MediaType = MediaType.Video - } + }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.BehindTheScenes, Token = "behind the scenes" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.DeletedScene, Token = "deleted scenes" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Interview, Token = "interviews" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Scene, Token = "scenes" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Sample, Token = "samples" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Clip, Token = "shorts" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Clip, Token = "featurettes" }, + new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Unknown, Token = "extras" }, }; Format3DRules = new[] diff --git a/Emby.Naming/Video/ExtraResolver.cs b/Emby.Naming/Video/ExtraResolver.cs index 42a5c88b3..fc0424faa 100644 --- a/Emby.Naming/Video/ExtraResolver.cs +++ b/Emby.Naming/Video/ExtraResolver.cs @@ -80,6 +80,15 @@ namespace Emby.Naming.Video result.Rule = rule; } } + else if (rule.RuleType == ExtraRuleType.DirectoryName) + { + var directoryName = Path.GetFileName(Path.GetDirectoryName(path)); + if (string.Equals(directoryName, rule.Token, StringComparison.OrdinalIgnoreCase)) + { + result.ExtraType = rule.ExtraType; + result.Rule = rule; + } + } return result; } diff --git a/Emby.Naming/Video/ExtraRuleType.cs b/Emby.Naming/Video/ExtraRuleType.cs index b021a04a3..0a304874d 100644 --- a/Emby.Naming/Video/ExtraRuleType.cs +++ b/Emby.Naming/Video/ExtraRuleType.cs @@ -5,18 +5,23 @@ namespace Emby.Naming.Video public enum ExtraRuleType { /// - /// The suffix + /// Match against a suffix in the file name. /// Suffix = 0, /// - /// The filename + /// Match against the file name. /// Filename = 1, /// - /// The regex + /// Match against the a regex. /// - Regex = 2 + Regex = 2, + + /// + /// Match against the directory name of the file. + /// + DirectoryName = 3, } } -- cgit v1.2.3 From 4ff8d30e410de6de54b73663c801fa10233e2a82 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Wed, 1 Apr 2020 18:54:06 +0200 Subject: Document ExtraRule properly --- Emby.Naming/Video/ExtraRule.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Emby.Naming') diff --git a/Emby.Naming/Video/ExtraRule.cs b/Emby.Naming/Video/ExtraRule.cs index cb58a3934..7c9702e24 100644 --- a/Emby.Naming/Video/ExtraRule.cs +++ b/Emby.Naming/Video/ExtraRule.cs @@ -5,30 +5,29 @@ using MediaType = Emby.Naming.Common.MediaType; namespace Emby.Naming.Video { + /// + /// A rule used to match a file path with an . + /// public class ExtraRule { /// - /// Gets or sets the token. + /// Gets or sets the token to use for matching against the file path. /// - /// The token. public string Token { get; set; } /// - /// Gets or sets the type of the extra. + /// Gets or sets the type of the extra to return when matched. /// - /// The type of the extra. public ExtraType ExtraType { get; set; } /// /// Gets or sets the type of the rule. /// - /// The type of the rule. public ExtraRuleType RuleType { get; set; } /// - /// Gets or sets the type of the media. + /// Gets or sets the type of the media to return when matched. /// - /// The type of the media. public MediaType MediaType { get; set; } } } -- cgit v1.2.3 From 377f9896ce65d4a29fe9d2198607ced2771b9abb Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Wed, 1 Apr 2020 19:04:00 +0200 Subject: Small fixes --- Emby.Naming/Video/ExtraRuleType.cs | 2 +- MediaBrowser.Api/UserLibrary/UserLibraryService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Emby.Naming') diff --git a/Emby.Naming/Video/ExtraRuleType.cs b/Emby.Naming/Video/ExtraRuleType.cs index 0a304874d..76872f3bc 100644 --- a/Emby.Naming/Video/ExtraRuleType.cs +++ b/Emby.Naming/Video/ExtraRuleType.cs @@ -20,7 +20,7 @@ namespace Emby.Naming.Video Regex = 2, /// - /// Match against the directory name of the file. + /// Match against the name of the directory containing the file. /// DirectoryName = 3, } diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index 4cd201c3b..7fa750adb 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -381,7 +381,7 @@ namespace MediaBrowser.Api.UserLibrary var dtoOptions = GetDtoOptions(_authContext, request); - var dtosExtras = item.GetExtras(new ExtraType[] { ExtraType.Trailer }) + var dtosExtras = item.GetExtras(new[] { ExtraType.Trailer }) .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)) .ToArray(); -- cgit v1.2.3 From 1a4d9d4c53c11c6a1a775518ce267b5a3bce8781 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Wed, 1 Apr 2020 19:41:52 +0200 Subject: Code review suggestions --- Emby.Naming/Common/NamingOptions.cs | 64 ++++++++++++++++++++++++---- MediaBrowser.Controller/Entities/BaseItem.cs | 2 +- 2 files changed, 57 insertions(+), 9 deletions(-) (limited to 'Emby.Naming') diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs index 8ac33d3f5..c00181c7e 100644 --- a/Emby.Naming/Common/NamingOptions.cs +++ b/Emby.Naming/Common/NamingOptions.cs @@ -506,14 +506,62 @@ namespace Emby.Naming.Common Token = "-short", MediaType = MediaType.Video }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.BehindTheScenes, Token = "behind the scenes" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.DeletedScene, Token = "deleted scenes" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Interview, Token = "interviews" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Scene, Token = "scenes" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Sample, Token = "samples" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Clip, Token = "shorts" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Clip, Token = "featurettes" }, - new ExtraRule { RuleType = ExtraRuleType.DirectoryName, MediaType = MediaType.Video, ExtraType = ExtraType.Unknown, Token = "extras" }, + new ExtraRule + { + ExtraType = ExtraType.BehindTheScenes, + RuleType = ExtraRuleType.DirectoryName, + Token = "behind the scenes", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.DeletedScene, + RuleType = ExtraRuleType.DirectoryName, + Token = "deleted scenes", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.Interview, + RuleType = ExtraRuleType.DirectoryName, + Token = "interviews", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.Scene, + RuleType = ExtraRuleType.DirectoryName, + Token = "scenes", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.Sample, + RuleType = ExtraRuleType.DirectoryName, + Token = "samples", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.Clip, + RuleType = ExtraRuleType.DirectoryName, + Token = "shorts", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.Clip, + RuleType = ExtraRuleType.DirectoryName, + Token = "featurettes", + MediaType = MediaType.Video, + }, + new ExtraRule + { + ExtraType = ExtraType.Unknown, + RuleType = ExtraRuleType.DirectoryName, + Token = "extras", + MediaType = MediaType.Video, + }, }; Format3DRules = new[] diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index cfc80ac09..a52ac3671 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1327,7 +1327,7 @@ namespace MediaBrowser.Controller.Entities } // Use some hackery to get the extra type based on foldername - item.ExtraType = Enum.TryParse(extraFolderName.Replace(" ", ""), true, out ExtraType extraType) + item.ExtraType = Enum.TryParse(extraFolderName.Replace(" ", string.Empty), true, out ExtraType extraType) ? extraType : Model.Entities.ExtraType.Unknown; -- cgit v1.2.3 From 7be4b57fe7c1f5c7a84a6a8ed91cb49f388f2169 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Sun, 5 Apr 2020 09:47:20 -0400 Subject: Fix documentation for ExtraRuleType enum values --- Emby.Naming/Video/ExtraRuleType.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Emby.Naming') diff --git a/Emby.Naming/Video/ExtraRuleType.cs b/Emby.Naming/Video/ExtraRuleType.cs index 76872f3bc..e89876f4a 100644 --- a/Emby.Naming/Video/ExtraRuleType.cs +++ b/Emby.Naming/Video/ExtraRuleType.cs @@ -10,12 +10,12 @@ namespace Emby.Naming.Video Suffix = 0, /// - /// Match against the file name. + /// Match against the file name, excluding the file extension. /// Filename = 1, /// - /// Match against the a regex. + /// Match against the file name, including the file extension. /// Regex = 2, -- cgit v1.2.3