From a4055779f6c824cc0289dfb4f77dc094f2de850a Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 27 Jan 2019 16:27:18 +0100 Subject: [PATCH 1/3] Change multi version logic for movies --- Emby.Naming/Video/VideoListResolver.cs | 65 ++++---------------------- 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index 0506d0734..156739c0a 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -175,71 +175,22 @@ namespace Emby.Naming.Video return videos; } - var list = new List(); - var folderName = Path.GetFileName(Path.GetDirectoryName(videos[0].Files[0].Path)); if (!string.IsNullOrEmpty(folderName) && folderName.Length > 1) { - if (videos.All(i => i.Files.Count == 1 && IsEligibleForMultiVersion(folderName, i.Files[0].Path))) + var ordered = videos.OrderBy(i => i.Name).ToList(); + + return ordered.GroupBy(v => new {v.Name, v.Year}).Select(group => new VideoInfo { - // Enforce the multi-version limit - if (videos.Count <= 8 && HaveSameYear(videos)) - { - var ordered = videos.OrderBy(i => i.Name).ToList(); - - list.Add(ordered[0]); - - list[0].AlternateVersions = ordered.Skip(1).Select(i => i.Files[0]).ToList(); - list[0].Name = folderName; - list[0].Extras.AddRange(ordered.Skip(1).SelectMany(i => i.Extras)); - - return list; - } - } + Name = folderName, + Files = group.First().Files, + AlternateVersions = group.Skip(1).Select(i => i.Files[0]).ToList(), + Extras = group.First().Extras.Concat(group.Skip(1).SelectMany(i => i.Extras)).ToList() + }); } return videos; - //foreach (var video in videos.OrderBy(i => i.Name)) - //{ - // var match = list - // .FirstOrDefault(i => string.Equals(i.Name, video.Name, StringComparison.OrdinalIgnoreCase)); - - // if (match != null && video.Files.Count == 1 && match.Files.Count == 1) - // { - // match.AlternateVersions.Add(video.Files[0]); - // match.Extras.AddRange(video.Extras); - // } - // else - // { - // list.Add(video); - // } - //} - - //return list; - } - - private bool HaveSameYear(List videos) - { - return videos.Select(i => i.Year ?? -1).Distinct().Count() < 2; - } - - private bool IsEligibleForMultiVersion(string folderName, string testFilename) - { - testFilename = Path.GetFileNameWithoutExtension(testFilename); - - if (string.Equals(folderName, testFilename, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - if (testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase)) - { - testFilename = testFilename.Substring(folderName.Length).Trim(); - return testFilename.StartsWith("-", StringComparison.OrdinalIgnoreCase) || Regex.Replace(testFilename, @"\[([^]]*)\]", "").Trim() == string.Empty; - } - - return false; } private List GetExtras(IEnumerable remainingFiles, List baseNames) From 42abb5a9931806a2ae1cedd433144ebf82768a0d Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 27 Jan 2019 16:37:12 +0100 Subject: [PATCH 2/3] Remove unnecessary ToList --- Emby.Naming/Video/VideoListResolver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index 156739c0a..db8ebb56a 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -179,7 +179,7 @@ namespace Emby.Naming.Video if (!string.IsNullOrEmpty(folderName) && folderName.Length > 1) { - var ordered = videos.OrderBy(i => i.Name).ToList(); + var ordered = videos.OrderBy(i => i.Name); return ordered.GroupBy(v => new {v.Name, v.Year}).Select(group => new VideoInfo { From 05ad2e9b3f5209d9e7ff9949d8c20cd8ef7062b6 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Sun, 27 Jan 2019 16:50:17 +0100 Subject: [PATCH 3/3] Add Year to the new VideoInfo --- Emby.Naming/Video/VideoListResolver.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index db8ebb56a..ef97b8739 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -184,6 +184,7 @@ namespace Emby.Naming.Video return ordered.GroupBy(v => new {v.Name, v.Year}).Select(group => new VideoInfo { Name = folderName, + Year = group.First().Year, Files = group.First().Files, AlternateVersions = group.Skip(1).Select(i => i.Files[0]).ToList(), Extras = group.First().Extras.Concat(group.Skip(1).SelectMany(i => i.Extras)).ToList()