From 4a700778e3e76d53a89c824ff53eb4e83f03a7c8 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 18 Feb 2019 21:56:08 +0100 Subject: [PATCH 1/2] Semi-revert to prefer old movie grouping behaviour --- Emby.Naming/Video/VideoListResolver.cs | 50 +++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index 20fa100fa..3e3545831 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -175,7 +175,55 @@ namespace Emby.Naming.Video return videos; } - return videos.GroupBy(v => new {v.Name, v.Year}).Select(group => new VideoInfo + var folderName = Path.GetFileName(Path.GetDirectoryName(videos.First().Files.First().Path)); + if (!string.IsNullOrEmpty(folderName)) + { + var videosMatchingFolder = new List(); + foreach (VideoInfo video in videos) + { + // Only interested in single files + if (video.Files.Count != 1) + { + continue; + } + + if (string.Equals(folderName, video.Name, StringComparison.OrdinalIgnoreCase)) + { + videosMatchingFolder.Add(video); + } + // Eg. My Movie == My Movie - Some Other Info, TODO doesn't seem like a robust test + else if (video.Name.StartsWith(folderName, StringComparison.OrdinalIgnoreCase) && + video.Name.Substring(folderName.Length).TrimStart().StartsWith("-")) + { + videosMatchingFolder.Add(video); + } + } + + // It is assumed that any non-matching files are random samples, trailers, extras etc. + // So if there's at least one video file matching the folder name, skip the rest. + if (videosMatchingFolder.Count > 0) + { + var primary = videosMatchingFolder.First(); + var remainingVideos = videosMatchingFolder.Skip(1); + var videoInfo = new VideoInfo + { + Name = folderName, + Year = videosMatchingFolder.First().Year, + Files = videosMatchingFolder.First().Files, + AlternateVersions = new List(), + Extras = primary.Extras + }; + foreach (VideoInfo video in remainingVideos) + { + videoInfo.AlternateVersions.Add(video.Files.First()); + videoInfo.Extras.AddRange(video.Extras); + } + + return new[] { videoInfo }; + } + } + + return videos.GroupBy(v => new { v.Name, v.Year }).Select(group => new VideoInfo { // Because of the grouping, we can grab the information from the first movie and make it primary // The remaining movie matches are 'alternate versions' From 29ff80d69cbc518e730bcb62da839ee31e19c977 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Mon, 18 Feb 2019 22:02:16 +0100 Subject: [PATCH 2/2] Minor style fixes --- Emby.Naming/Video/VideoListResolver.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs index 3e3545831..3348ec2fb 100644 --- a/Emby.Naming/Video/VideoListResolver.cs +++ b/Emby.Naming/Video/VideoListResolver.cs @@ -175,7 +175,7 @@ namespace Emby.Naming.Video return videos; } - var folderName = Path.GetFileName(Path.GetDirectoryName(videos.First().Files.First().Path)); + var folderName = Path.GetFileName(Path.GetDirectoryName(videos[0].Files[0].Path)); if (!string.IsNullOrEmpty(folderName)) { var videosMatchingFolder = new List(); @@ -203,13 +203,13 @@ namespace Emby.Naming.Video // So if there's at least one video file matching the folder name, skip the rest. if (videosMatchingFolder.Count > 0) { - var primary = videosMatchingFolder.First(); + var primary = videosMatchingFolder[0]; var remainingVideos = videosMatchingFolder.Skip(1); var videoInfo = new VideoInfo { Name = folderName, - Year = videosMatchingFolder.First().Year, - Files = videosMatchingFolder.First().Files, + Year = primary.Year, + Files = primary.Files, AlternateVersions = new List(), Extras = primary.Extras };