Merge pull request #6383 from sushilicious/master
Made default parser a tiny bit mroe robust
This commit is contained in:
commit
dc72d90703
|
@ -137,8 +137,11 @@ namespace Emby.Naming.Common
|
||||||
|
|
||||||
CleanStrings = new[]
|
CleanStrings = new[]
|
||||||
{
|
{
|
||||||
@"[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|HDR|HDC|UHD|UltraHD|4k|ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|bd|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|blu-ray|x264|x265|h264|h265|xvid|xvidvd|xxx|www.www|AAC|DTS|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
|
@"^\s*(?<cleaned>.+?)[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|HDR|HDC|UHD|UltraHD|4k|ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|bd|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|blu-ray|x264|x265|h264|h265|xvid|xvidvd|xxx|www.www|AAC|DTS|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
|
||||||
@"(\[.*\])"
|
@"^(?<cleaned>.+?)(\[.*\])",
|
||||||
|
@"^\s*(?<cleaned>.+?)\WE[0-9]+(-|~)E?[0-9]+(\W|$)",
|
||||||
|
@"^\s*\[[^\]]+\](?!\.\w+$)\s*(?<cleaned>.+)",
|
||||||
|
@"^\s*(?<cleaned>.+?)\s+-\s+[0-9]+\s*$"
|
||||||
};
|
};
|
||||||
|
|
||||||
SubtitleFileExtensions = new[]
|
SubtitleFileExtensions = new[]
|
||||||
|
|
|
@ -25,26 +25,35 @@ namespace Emby.Naming.Video
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var len = expressions.Count;
|
// Iteratively apply the regexps to clean the string.
|
||||||
for (int i = 0; i < len; i++)
|
bool cleaned = false;
|
||||||
|
for (int i = 0; i < expressions.Count; i++)
|
||||||
{
|
{
|
||||||
if (TryClean(name, expressions[i], out newName))
|
if (TryClean(name, expressions[i], out newName))
|
||||||
{
|
{
|
||||||
return true;
|
cleaned = true;
|
||||||
|
name = newName.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newName = ReadOnlySpan<char>.Empty;
|
newName = cleaned ? name.AsSpan() : ReadOnlySpan<char>.Empty;
|
||||||
return false;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
|
private static bool TryClean(string name, Regex expression, out ReadOnlySpan<char> newName)
|
||||||
{
|
{
|
||||||
var match = expression.Match(name);
|
var match = expression.Match(name);
|
||||||
int index = match.Index;
|
int index = match.Index;
|
||||||
if (match.Success && index != 0)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
newName = name.AsSpan().Slice(0, match.Index);
|
var found = match.Groups.TryGetValue("cleaned", out var cleaned);
|
||||||
|
if (!found || cleaned == null)
|
||||||
|
{
|
||||||
|
newName = ReadOnlySpan<char>.Empty;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
newName = name.AsSpan().Slice(cleaned.Index, cleaned.Length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using Emby.Naming.Common;
|
using Emby.Naming.Common;
|
||||||
using Emby.Naming.Video;
|
using Emby.Naming.Video;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
@ -23,6 +23,12 @@ namespace Jellyfin.Naming.Tests.Video
|
||||||
[InlineData("Crouching.Tiger.Hidden.Dragon.BDrip.mkv", "Crouching.Tiger.Hidden.Dragon")]
|
[InlineData("Crouching.Tiger.Hidden.Dragon.BDrip.mkv", "Crouching.Tiger.Hidden.Dragon")]
|
||||||
[InlineData("Crouching.Tiger.Hidden.Dragon.BDrip-HDC.mkv", "Crouching.Tiger.Hidden.Dragon")]
|
[InlineData("Crouching.Tiger.Hidden.Dragon.BDrip-HDC.mkv", "Crouching.Tiger.Hidden.Dragon")]
|
||||||
[InlineData("Crouching.Tiger.Hidden.Dragon.4K.UltraHD.HDR.BDrip-HDC.mkv", "Crouching.Tiger.Hidden.Dragon")]
|
[InlineData("Crouching.Tiger.Hidden.Dragon.4K.UltraHD.HDR.BDrip-HDC.mkv", "Crouching.Tiger.Hidden.Dragon")]
|
||||||
|
[InlineData("[HorribleSubs] Made in Abyss - 13 [720p].mkv", "Made in Abyss")]
|
||||||
|
[InlineData("[Tsundere] Kore wa Zombie Desu ka of the Dead [BDRip h264 1920x1080 FLAC]", "Kore wa Zombie Desu ka of the Dead")]
|
||||||
|
[InlineData("[Erai-raws] Jujutsu Kaisen - 03 [720p][Multiple Subtitle].mkv", "Jujutsu Kaisen")]
|
||||||
|
[InlineData("[OCN] 애타는 로맨스 720p-NEXT", "애타는 로맨스")]
|
||||||
|
[InlineData("[tvN] 혼술남녀.E01-E16.720p-NEXT", "혼술남녀")]
|
||||||
|
[InlineData("[tvN] 연애말고 결혼 E01~E16 END HDTV.H264.720p-WITH", "연애말고 결혼")]
|
||||||
// FIXME: [InlineData("After The Sunset - [0004].mkv", "After The Sunset")]
|
// FIXME: [InlineData("After The Sunset - [0004].mkv", "After The Sunset")]
|
||||||
public void CleanStringTest_NeedsCleaning_Success(string input, string expectedName)
|
public void CleanStringTest_NeedsCleaning_Success(string input, string expectedName)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user