From 3a868e28b3e3d9f0a13fc38c680047010d627b0f Mon Sep 17 00:00:00 2001 From: softworkz Date: Wed, 23 Sep 2015 06:12:46 +0200 Subject: Auto-Organize: Added feature to remember/persist series matching in manual organization dialog #2 When a filename cannot be auto-matched to an existing series name, the organization must be performed manually. Unfortunately not just once, but again and again for each episode coming in. This change proposes a simple but solid method to optionally persist the matching condition from within the manual organization dialog. This approach will make Emby "learn" how to organize files in the future without user interaction. --- .../FileOrganization/AutoOrganizeOptions.cs | 8 ++++++++ MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs (limited to 'MediaBrowser.Model/FileOrganization') diff --git a/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs b/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs index ae701ea68d..071897b51b 100644 --- a/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs +++ b/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs @@ -1,4 +1,5 @@  +using System.Collections.Generic; namespace MediaBrowser.Model.FileOrganization { public class AutoOrganizeOptions @@ -9,9 +10,16 @@ namespace MediaBrowser.Model.FileOrganization /// The tv options. public TvFileOrganizationOptions TvOptions { get; set; } + /// + /// Gets or sets a list of smart match entries. + /// + /// The smart match entries. + public List SmartMatchInfos { get; set; } + public AutoOrganizeOptions() { TvOptions = new TvFileOrganizationOptions(); + SmartMatchInfos = new List(); } } } diff --git a/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs b/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs new file mode 100644 index 0000000000..808c0b006e --- /dev/null +++ b/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs @@ -0,0 +1,19 @@ + +using System; +using System.Collections.Generic; + +namespace MediaBrowser.Model.FileOrganization +{ + public class SmartMatchInfo + { + public Guid Id { get; set; } + public string Name { get; set; } + public FileOrganizerType OrganizerType { get; set; } + public List MatchStrings { get; set; } + + public SmartMatchInfo() + { + MatchStrings = new List(); + } + } +} -- cgit v1.2.3 From 0e49ccfd077bf114a2a663249d81a2891c46639d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 7 Feb 2016 00:15:26 -0500 Subject: update smart match feature --- .../FileOrganization/AutoOrganizeOptions.cs | 5 ++--- .../FileOrganization/SmartMatchInfo.cs | 9 +++------ .../FileOrganization/EpisodeFileOrganizer.cs | 21 +++++++++++++-------- .../FileOrganization/FileOrganizationService.cs | 19 ++++++++++++------- 4 files changed, 30 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Model/FileOrganization') diff --git a/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs b/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs index 071897b51b..830d55bf54 100644 --- a/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs +++ b/MediaBrowser.Model/FileOrganization/AutoOrganizeOptions.cs @@ -1,5 +1,4 @@  -using System.Collections.Generic; namespace MediaBrowser.Model.FileOrganization { public class AutoOrganizeOptions @@ -14,12 +13,12 @@ namespace MediaBrowser.Model.FileOrganization /// Gets or sets a list of smart match entries. /// /// The smart match entries. - public List SmartMatchInfos { get; set; } + public SmartMatchInfo[] SmartMatchInfos { get; set; } public AutoOrganizeOptions() { TvOptions = new TvFileOrganizationOptions(); - SmartMatchInfos = new List(); + SmartMatchInfos = new SmartMatchInfo[]{}; } } } diff --git a/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs b/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs index 808c0b006e..a6bc66e499 100644 --- a/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs +++ b/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs @@ -1,19 +1,16 @@  -using System; -using System.Collections.Generic; - namespace MediaBrowser.Model.FileOrganization { public class SmartMatchInfo { - public Guid Id { get; set; } + public string Id { get; set; } public string Name { get; set; } public FileOrganizerType OrganizerType { get; set; } - public List MatchStrings { get; set; } + public string[] MatchStrings { get; set; } public SmartMatchInfo() { - MatchStrings = new List(); + MatchStrings = new string[] { }; } } } diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs index a952b60d58..dcce91c313 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs @@ -301,20 +301,25 @@ namespace MediaBrowser.Server.Implementations.FileOrganization private void SaveSmartMatchString(string matchString, Series series, AutoOrganizeOptions options) { - SmartMatchInfo info = options.SmartMatchInfos.Find(i => i.Id == series.Id); + var seriesIdString = series.Id.ToString("N"); + SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(i => string.Equals(i.Id, seriesIdString)); if (info == null) { info = new SmartMatchInfo(); - info.Id = series.Id; + info.Id = series.Id.ToString("N"); info.OrganizerType = FileOrganizerType.Episode; info.Name = series.Name; - options.SmartMatchInfos.Add(info); + var list = options.SmartMatchInfos.ToList(); + list.Add(info); + options.SmartMatchInfos = list.ToArray(); } if (!info.MatchStrings.Contains(matchString, StringComparer.OrdinalIgnoreCase)) { - info.MatchStrings.Add(matchString); + var list = info.MatchStrings.ToList(); + list.Add(matchString); + info.MatchStrings = list.ToArray(); _config.SaveAutoOrganizeOptions(options); } } @@ -487,14 +492,14 @@ namespace MediaBrowser.Server.Implementations.FileOrganization if (series == null) { - SmartMatchInfo info = options.SmartMatchInfos.Where(e => e.MatchStrings.Contains(seriesName, StringComparer.OrdinalIgnoreCase)).FirstOrDefault(); + SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(e => e.MatchStrings.Contains(seriesName, StringComparer.OrdinalIgnoreCase)); if (info != null) { - series = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Series) + series = _libraryManager.RootFolder + .GetRecursiveChildren(i => i is Series) .Cast() - .Where(i => i.Id == info.Id) - .FirstOrDefault(); + .FirstOrDefault(i => string.Equals(i.Id.ToString("N"), info.Id)); } } diff --git a/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs b/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs index 3dd6a9be09..ce388bd8e1 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs @@ -140,12 +140,12 @@ namespace MediaBrowser.Server.Implementations.FileOrganization var options = GetAutoOrganizeptions(); - var items = options.SmartMatchInfos.Skip(query.StartIndex ?? 0).Take(query.Limit ?? Int32.MaxValue); + var items = options.SmartMatchInfos.Skip(query.StartIndex ?? 0).Take(query.Limit ?? Int32.MaxValue).ToArray(); return new QueryResult() { - Items = items.ToArray(), - TotalRecordCount = items.Count() + Items = items, + TotalRecordCount = options.SmartMatchInfos.Length }; } @@ -165,14 +165,19 @@ namespace MediaBrowser.Server.Implementations.FileOrganization var options = GetAutoOrganizeptions(); - SmartMatchInfo info = options.SmartMatchInfos.Find(i => i.Id == Id); + SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(i => string.Equals(i.Id, IdString)); if (info != null && info.MatchStrings.Contains(matchString)) { - info.MatchStrings.Remove(matchString); - if (info.MatchStrings.Count == 0) + var list = info.MatchStrings.ToList(); + list.Remove(matchString); + info.MatchStrings = list.ToArray(); + + if (info.MatchStrings.Length == 0) { - options.SmartMatchInfos.Remove(info); + var infos = options.SmartMatchInfos.ToList(); + infos.Remove(info); + options.SmartMatchInfos = infos.ToArray(); } _config.SaveAutoOrganizeOptions(options); -- cgit v1.2.3 From 59c9081f4b25b96f7cc9203a319ad19328651772 Mon Sep 17 00:00:00 2001 From: softworkz Date: Mon, 8 Feb 2016 02:25:10 +0100 Subject: Auto-Organize - Feature to remember/persist series matching in manual organization dialog: Changed to match against plain library name inste --- .../FileOrganization/IFileOrganizationService.cs | 4 ++-- MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs | 4 ++-- .../FileOrganization/EpisodeFileOrganizer.cs | 9 ++++----- .../FileOrganization/FileOrganizationService.cs | 10 ++++------ 4 files changed, 12 insertions(+), 15 deletions(-) (limited to 'MediaBrowser.Model/FileOrganization') diff --git a/MediaBrowser.Controller/FileOrganization/IFileOrganizationService.cs b/MediaBrowser.Controller/FileOrganization/IFileOrganizationService.cs index 8d7f4e1173..daa670d836 100644 --- a/MediaBrowser.Controller/FileOrganization/IFileOrganizationService.cs +++ b/MediaBrowser.Controller/FileOrganization/IFileOrganizationService.cs @@ -78,8 +78,8 @@ namespace MediaBrowser.Controller.FileOrganization /// /// Deletes a smart match entry. /// - /// Item Id. + /// Item name. /// The match string to delete. - void DeleteSmartMatchEntry(string Id, string matchString); + void DeleteSmartMatchEntry(string ItemName, string matchString); } } diff --git a/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs b/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs index a6bc66e499..28c99b89bb 100644 --- a/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs +++ b/MediaBrowser.Model/FileOrganization/SmartMatchInfo.cs @@ -3,8 +3,8 @@ namespace MediaBrowser.Model.FileOrganization { public class SmartMatchInfo { - public string Id { get; set; } - public string Name { get; set; } + public string ItemName { get; set; } + public string DisplayName { get; set; } public FileOrganizerType OrganizerType { get; set; } public string[] MatchStrings { get; set; } diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs index 6509b016a4..bbbdcd4b33 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs @@ -301,15 +301,14 @@ namespace MediaBrowser.Server.Implementations.FileOrganization private void SaveSmartMatchString(string matchString, Series series, AutoOrganizeOptions options) { - var seriesIdString = series.Id.ToString("N"); - SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(i => string.Equals(i.Id, seriesIdString)); + SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(i => string.Equals(i.ItemName, series.Name)); if (info == null) { info = new SmartMatchInfo(); - info.Id = series.Id.ToString("N"); + info.ItemName = series.Name; info.OrganizerType = FileOrganizerType.Episode; - info.Name = series.Name; + info.DisplayName = series.Name; var list = options.SmartMatchInfos.ToList(); list.Add(info); options.SmartMatchInfos = list.ToArray(); @@ -499,7 +498,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization series = _libraryManager.RootFolder .GetRecursiveChildren(i => i is Series) .Cast() - .FirstOrDefault(i => string.Equals(i.Id.ToString("N"), info.Id)); + .FirstOrDefault(i => string.Equals(i.Name, info.ItemName)); } } diff --git a/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs b/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs index ce388bd8e1..cf1387b0eb 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs @@ -149,13 +149,11 @@ namespace MediaBrowser.Server.Implementations.FileOrganization }; } - public void DeleteSmartMatchEntry(string IdString, string matchString) + public void DeleteSmartMatchEntry(string itemName, string matchString) { - Guid Id; - - if (!Guid.TryParse(IdString, out Id)) + if (string.IsNullOrEmpty(itemName)) { - throw new ArgumentNullException("Id"); + throw new ArgumentNullException("itemName"); } if (string.IsNullOrEmpty(matchString)) @@ -165,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization var options = GetAutoOrganizeptions(); - SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(i => string.Equals(i.Id, IdString)); + SmartMatchInfo info = options.SmartMatchInfos.FirstOrDefault(i => string.Equals(i.ItemName, itemName)); if (info != null && info.MatchStrings.Contains(matchString)) { -- cgit v1.2.3