1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-29 23:12:39 +01:00

New: Added parser support for common Chinese release formats

This commit is contained in:
Wu Haotian 2019-01-31 11:31:49 +08:00 committed by Taloth
parent 7ae906863d
commit 8e486da928
3 changed files with 79 additions and 1 deletions

View File

@ -346,6 +346,7 @@
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheYearFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\TitleTheFixture.cs" />
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
<Compile Include="ParserTests\UnicodeReleaseParserFixture.cs" />
<Compile Include="ParserTests\ValidateParsedEpisodeInfoFixture.cs" />
<Compile Include="Profiles\Delay\DelayProfileServiceFixture.cs" />
<Compile Include="Profiles\Qualities\QualityIndexCompareToFixture.cs" />

View File

@ -0,0 +1,70 @@
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Test.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NzbDrone.Core.Test.ParserTests
{
[TestFixture]
public class UnicodeReleaseParserFixture : CoreTest
{
[TestCase("【喵萌奶茶屋】★10月新番★[哥布林杀手/Goblin Slayer][12END][720p][][]", "Goblin Slayer", "", 12)]
[TestCase("[桜都字幕组][/Tate no Yuusha no Nariagari][01][BIG5][720P]", "Tate no Yuusha no Nariagari", "", 1)]
[TestCase("[YMDR][][Kaguya-sama wa Kokurasetai][2019][02][1080p][HEVC][JAP][BIG5][MP4-AAC][]", "Kaguya-sama wa Kokurasetai", "YMDR", 2)]
[TestCase("【DHR百合組】[天使降臨到我身邊_Watashi ni Tenshi ga Maiorita!][05][][1080P10][WebRip][HEVC][MP4]", "Watashi ni Tenshi ga Maiorita!", "DHR百合組", 5)]
[TestCase("【傲娇零&自由字幕组】[刀剑神域III UnderWorld/ Sword Art Online - Alicization ][17][HEVC-10Bit-2160P AAC][GB/BIG5][WEB-Rip][MKV+ass ]", "Sword Art Online - Alicization", "&", 17)]
[TestCase("【悠哈璃羽字幕社&拉斯观测组】[刀剑神域Alicization _ Sword Art Online - Alicization ][17][x264 1080p][CHS]", "Sword Art Online - Alicization", "", 17)]
[TestCase("【极影字幕社】 ★04月新番 【巴哈姆特之怒 Virgin Soul】【Shingeki no Bahamut Virgin Soul】【24】 【END】GB MP4_720P", "Shingeki no Bahamut Virgin Soul", "极影字幕社", 24)]
[TestCase("[愛戀&漫貓字幕组][10][][18][720P][BIG5][MP4]", "", "&", 18)]
[TestCase("【咕咕茶字幕組】★1月新番[天使降臨到了我身邊! / Watashi ni Tenshi ga Maiorita!][04][1080P][][MP4]", "Watashi ni Tenshi ga Maiorita!", "", 4)]
[TestCase("【千夏字幕组】【天使降临到了我身边_Watashi ni Tenshi ga Maiorita!】[第05话][1080p_HEVC][]", "Watashi ni Tenshi ga Maiorita!", "", 5)]
[TestCase("【DHR动研字幕组】[多田君不恋爱_Tada-kun wa Koi wo Shinai][13][][720P][MP4]", "Tada-kun wa Koi wo Shinai", "DHR动研字幕组", 13)]
[TestCase("【动漫国字幕组】★01月新番[Endro][01][1080P][][MP4]", "Endro", "", 1)]
public void should_parse_chinese_anime_releases(string postTitle, string title, string subgroup, int absoluteEpisodeNumber)
{
postTitle = XmlCleaner.ReplaceUnicode(postTitle);
var result = Parser.Parser.ParseTitle(postTitle);
result.Should().NotBeNull();
result.ReleaseGroup.Should().Be(subgroup);
result.AbsoluteEpisodeNumbers.Single().Should().Be(absoluteEpisodeNumber);
result.SeriesTitle.Should().Be(title);
result.FullSeason.Should().BeFalse();
}
[TestCase("[喵萌奶茶屋&LoliHouse]/Manaria Friends - 03 [WebRip 1080p HEVC-10bit AAC][]", "Manaria Friends", "&LoliHouse", 3)]
[TestCase("[悠哈璃羽字幕社&拉斯观测组&LoliHouse] : Alicization / Sword Art Online: Alicization - 17 [WebRip 1080p HEVC-10bit AAC][]", "Sword Art Online Alicization", "&&LoliHouse", 17)]
[TestCase("[ZERO字幕組]·Jingai-san no Yome[11][BIG5][1080p]", "Jingai-san no Yome", "ZERO字幕組", 11)]
public void should_parse_unbracketed_chinese_anime_releases(string postTitle, string title, string subgroup, int absoluteEpisodeNumber)
{
postTitle = XmlCleaner.ReplaceUnicode(postTitle);
var result = Parser.Parser.ParseTitle(postTitle);
result.Should().NotBeNull();
result.ReleaseGroup.Should().Be(subgroup);
result.AbsoluteEpisodeNumbers.Single().Should().Be(absoluteEpisodeNumber);
result.SeriesTitle.Should().Be(title);
result.FullSeason.Should().BeFalse();
}
[TestCase("[YMDR][ --][Boruto -Naruto Next Generations-][2017][88-91][1080p][AVC][JAP][BIG5][MP4-AAC][]", "Boruto -Naruto Next Generations", "YMDR", new[] { 88, 89, 90, 91 })]
[TestCase("[诸神字幕组][][BANANA FISH][01-24][][720P][MP4]", "BANANA FISH", "", new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 })]
//[TestCase("【漫貓&愛戀字幕組】[五等分的新娘/五等分的花嫁/五等分の花嫁][Go-Toubun_no_Hanayome][01_03][BIG5][720P][HEVC]", "Go-Toubun no Hanayome", "漫貓&愛戀字幕組", new[] { 1, 2, 3 })]
public void should_parse_chinese_multiepisode_releases(string postTitle, string title, string subgroup, int[] absoluteEpisodeNumbers)
{
postTitle = XmlCleaner.ReplaceUnicode(postTitle);
var result = Parser.Parser.ParseTitle(postTitle);
result.Should().NotBeNull();
result.ReleaseGroup.Should().Be(subgroup);
result.AbsoluteEpisodeNumbers.Should().BeEquivalentTo(absoluteEpisodeNumbers);
result.SeriesTitle.Should().Be(title);
result.FullSeason.Should().BeFalse();
}
}
}

View File

@ -19,9 +19,14 @@ namespace NzbDrone.Core.Parser
private static readonly RegexReplace[] PreSubstitutionRegex = new[]
{
// Korean series without season number, replace with S01Exxx and remove airdate.
// Korean series without season number, replace with S01Exxx and remove airdate
new RegexReplace(@"\.E(\d{2,4})\.\d{6}\.(.*-NEXT)$", ".S01E$1.$2", RegexOptions.Compiled),
// Chinese LoliHouse/ZERO releases don't use the expected brackets, normalize using brackets
new RegexReplace(@"^\[(?<subgroup>[^\]]*?(?:LoliHouse|ZERO)[^\]]*?)\](?<title>[^\[\]]+?)(?: - (?<episode>[0-9-]+)\s*|\[第?(?<episode>[0-9]+(?:-[0-9]+)?)话?(?:END|完)?\])\[", "[${subgroup}][${title}][${episode}][", RegexOptions.Compiled),
// Most Chinese anime releases contain additional brackets/separators for chinese and non-chinese titles, remove junk and replace with normal anime pattern
new RegexReplace(@"^\[(?<subgroup>[^\]]+)\](?:\s?★[^\[ -]+\s?)?\[(?:(?<chinesetitle>[^\]]+?)(?:\]\[|[_/·]\s*))?(?<title>[^\]]+?)\](?:\[\d{4}\])?\[第?(?<episode>[0-9]+(?:-[0-9]+)?)话?(?:END|完)?\]", "[${subgroup}] ${title} - ${episode} ", RegexOptions.Compiled)
};
private static readonly Regex[] ReportTitleRegex = new[]
@ -397,6 +402,8 @@ namespace NzbDrone.Core.Parser
var releaseTitle = RemoveFileExtension(title);
releaseTitle = releaseTitle.Replace("【", "[").Replace("】", "]");
foreach (var replace in PreSubstitutionRegex)
{
if (replace.TryReplace(ref releaseTitle))