mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 14:08:44 -04:00
Merge pull request #739 from cvium/change_multi_version_movie
Change multi version logic for movies
This commit is contained in:
commit
b0608d26b4
1 changed files with 9 additions and 57 deletions
|
@ -175,71 +175,23 @@ namespace Emby.Naming.Video
|
||||||
return videos;
|
return videos;
|
||||||
}
|
}
|
||||||
|
|
||||||
var list = new List<VideoInfo>();
|
|
||||||
|
|
||||||
var folderName = Path.GetFileName(Path.GetDirectoryName(videos[0].Files[0].Path));
|
var folderName = Path.GetFileName(Path.GetDirectoryName(videos[0].Files[0].Path));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(folderName) && folderName.Length > 1)
|
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);
|
||||||
|
|
||||||
|
return ordered.GroupBy(v => new {v.Name, v.Year}).Select(group => new VideoInfo
|
||||||
{
|
{
|
||||||
// Enforce the multi-version limit
|
Name = folderName,
|
||||||
if (videos.Count <= 8 && HaveSameYear(videos))
|
Year = group.First().Year,
|
||||||
{
|
Files = group.First().Files,
|
||||||
var ordered = videos.OrderBy(i => i.Name).ToList();
|
AlternateVersions = group.Skip(1).Select(i => i.Files[0]).ToList(),
|
||||||
|
Extras = group.First().Extras.Concat(group.Skip(1).SelectMany(i => i.Extras)).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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return videos;
|
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<VideoInfo> 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<VideoFileInfo> GetExtras(IEnumerable<VideoFileInfo> remainingFiles, List<string> baseNames)
|
private List<VideoFileInfo> GetExtras(IEnumerable<VideoFileInfo> remainingFiles, List<string> baseNames)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue