mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-06-29 10:23:36 +02:00
Make exact match primary video
This commit is contained in:
parent
87b2bc5dc4
commit
59920b4052
|
@ -106,6 +106,7 @@ namespace Emby.Naming.Video
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cannot use Span inside local functions and delegates thus we cannot use LINQ here nor merge with the above [if]
|
// Cannot use Span inside local functions and delegates thus we cannot use LINQ here nor merge with the above [if]
|
||||||
|
VideoInfo? primary = null;
|
||||||
for (var i = 0; i < videos.Count; i++)
|
for (var i = 0; i < videos.Count; i++)
|
||||||
{
|
{
|
||||||
var video = videos[i];
|
var video = videos[i];
|
||||||
|
@ -118,25 +119,24 @@ namespace Emby.Naming.Video
|
||||||
{
|
{
|
||||||
return videos;
|
return videos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (folderName.Equals(Path.GetFileNameWithoutExtension(video.Files[0].Path.AsSpan()), StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
primary = video;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The list is created and overwritten in the caller, so we are allowed to do in-place sorting
|
// The list is created and overwritten in the caller, so we are allowed to do in-place sorting
|
||||||
videos.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));
|
videos.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));
|
||||||
|
primary ??= videos[0];
|
||||||
|
videos.Remove(primary);
|
||||||
|
|
||||||
var list = new List<VideoInfo>
|
var list = new List<VideoInfo>
|
||||||
{
|
{
|
||||||
videos[0]
|
primary
|
||||||
};
|
};
|
||||||
|
|
||||||
var alternateVersionsLen = videos.Count - 1;
|
list[0].AlternateVersions = videos.Select(x => x.Files[0]).ToArray();
|
||||||
var alternateVersions = new VideoFileInfo[alternateVersionsLen];
|
|
||||||
for (int i = 0; i < alternateVersionsLen; i++)
|
|
||||||
{
|
|
||||||
var video = videos[i + 1];
|
|
||||||
alternateVersions[i] = video.Files[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
list[0].AlternateVersions = alternateVersions;
|
|
||||||
list[0].Name = folderName.ToString();
|
list[0].Name = folderName.ToString();
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -323,6 +323,25 @@ namespace Jellyfin.Naming.Tests.Video
|
||||||
Assert.Single(result[0].AlternateVersions);
|
Assert.Single(result[0].AlternateVersions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestMultiVersion12()
|
||||||
|
{
|
||||||
|
var files = new[]
|
||||||
|
{
|
||||||
|
@"/movies/X-Men Apocalypse (2016)/X-Men Apocalypse (2016) - 1080p.mkv",
|
||||||
|
@"/movies/X-Men Apocalypse (2016)/X-Men Apocalypse (2016).mkv"
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = VideoListResolver.Resolve(
|
||||||
|
files.Select(i => VideoResolver.Resolve(i, false, _namingOptions)).OfType<VideoFileInfo>().ToList(),
|
||||||
|
_namingOptions).ToList();
|
||||||
|
|
||||||
|
Assert.Single(result);
|
||||||
|
Assert.Equal("/movies/X-Men Apocalypse (2016)/X-Men Apocalypse (2016).mkv", result[0].Files[0].Path);
|
||||||
|
Assert.Single(result[0].AlternateVersions);
|
||||||
|
Assert.Equal("/movies/X-Men Apocalypse (2016)/X-Men Apocalypse (2016) - 1080p.mkv", result[0].AlternateVersions[0].Path);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Resolve_GivenFolderNameWithBracketsAndHyphens_GroupsBasedOnFolderName()
|
public void Resolve_GivenFolderNameWithBracketsAndHyphens_GroupsBasedOnFolderName()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue