diff --git a/changelog.en_US.md b/changelog.en_US.md
index e81a93b..298564b 100644
--- a/changelog.en_US.md
+++ b/changelog.en_US.md
@@ -3,6 +3,10 @@
# Change Logs
+## v3.0.3 2023-04-07
+
+1. Optimize title matching logic
+
## v3.0.2 2023-04-07
1. Optimize Radarr title matching logic
diff --git a/changelog.md b/changelog.md
index 3564050..a299b2a 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,6 +3,10 @@
# 变更日志
+## v3.0.3 2023-04-07
+
+1. 优化标题匹配逻辑
+
## v3.0.2 2023-04-07
1. 优化 Radarr 标题匹配逻辑
diff --git a/src/main/java/com/lckp/jproxy/model/FormatResult.java b/src/main/java/com/lckp/jproxy/model/FormatResult.java
deleted file mode 100644
index b3d1485..0000000
--- a/src/main/java/com/lckp/jproxy/model/FormatResult.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.lckp.jproxy.model;
-
-import java.io.Serializable;
-
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- *
- * 格式化结果
- *
- *
- * @author LuckyPuppy514
- * @date 2023-04-07
- */
-@Getter
-@Setter
-public class FormatResult implements Serializable {
- private static final long serialVersionUID = 1L;
-
- /*
- * 格式化结果
- */
- private String formatText;
-
- /*
- * 剩余信息
- */
- private String restText;
-}
diff --git a/src/main/java/com/lckp/jproxy/service/ISonarrTitleService.java b/src/main/java/com/lckp/jproxy/service/ISonarrTitleService.java
index 15a9ab5..f7e1e28 100644
--- a/src/main/java/com/lckp/jproxy/service/ISonarrTitleService.java
+++ b/src/main/java/com/lckp/jproxy/service/ISonarrTitleService.java
@@ -7,7 +7,6 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.lckp.jproxy.entity.SonarrRule;
import com.lckp.jproxy.entity.SonarrTitle;
-import com.lckp.jproxy.model.FormatResult;
import com.lckp.jproxy.model.request.SonarrTitleQueryRequest;
/**
@@ -61,9 +60,9 @@ public interface ISonarrTitleService extends IService {
* @param cleanTitleRegex
* @param sonarrRuleList
* @param sonarrTitleList
- * @return FormatResult
+ * @return String
*/
- public FormatResult formatTitle(String text, String format, String cleanTitleRegex,
+ public String formatTitle(String text, String format, String cleanTitleRegex,
List sonarrRuleList, List sonarrTitleList);
/**
diff --git a/src/main/java/com/lckp/jproxy/service/impl/SonarrExampleServiceImpl.java b/src/main/java/com/lckp/jproxy/service/impl/SonarrExampleServiceImpl.java
index b537caa..3e921bd 100644
--- a/src/main/java/com/lckp/jproxy/service/impl/SonarrExampleServiceImpl.java
+++ b/src/main/java/com/lckp/jproxy/service/impl/SonarrExampleServiceImpl.java
@@ -25,7 +25,6 @@
import com.lckp.jproxy.entity.SonarrRule;
import com.lckp.jproxy.entity.SonarrTitle;
import com.lckp.jproxy.mapper.SonarrExampleMapper;
-import com.lckp.jproxy.model.FormatResult;
import com.lckp.jproxy.model.request.SonarrExampleQueryRequest;
import com.lckp.jproxy.service.ISonarrExampleService;
import com.lckp.jproxy.service.ISonarrRuleService;
@@ -93,15 +92,15 @@ public IPage query(SonarrExampleQueryRequest request, Locale loca
for (SonarrExample sonarrExample : resultList) {
sonarrExample.setFormatText(sonarrExample.getOriginalText());
sonarrExample.setValidStatus(ValidStatus.INVALID.getCode());
- FormatResult formatResult = sonarrTitleService.formatTitle(sonarrExample.getOriginalText(),
- format, cleanTitleRegex, tokenRuleMap.get(Token.TITLE), sonarrTitleList);
- String formatText = formatResult.getFormatText();
+ String formatText = sonarrTitleService.formatTitle(sonarrExample.getOriginalText(), format,
+ cleanTitleRegex, tokenRuleMap.get(Token.TITLE), sonarrTitleList);
if (formatText.contains("{" + Token.TITLE + "}")) {
formatText = FormatUtil.replaceToken(Token.TITLE,
messageSource.getMessage(Messages.EXAMPLE_MATCH_TITLE_FAIL, null, locale),
formatText);
}
- formatText = sonarrTitleService.format(formatResult.getRestText(), formatText, tokenRuleMap);
+ formatText = sonarrTitleService.format(sonarrExample.getOriginalText(), formatText,
+ tokenRuleMap);
sonarrExample.setFormatText(formatText);
if (!sonarrExample.getOriginalText().equals(sonarrExample.getFormatText())) {
sonarrExample.setValidStatus(ValidStatus.VALID.getCode());
diff --git a/src/main/java/com/lckp/jproxy/service/impl/SonarrIndexerServiceImpl.java b/src/main/java/com/lckp/jproxy/service/impl/SonarrIndexerServiceImpl.java
index c2b14b1..9bbfb13 100644
--- a/src/main/java/com/lckp/jproxy/service/impl/SonarrIndexerServiceImpl.java
+++ b/src/main/java/com/lckp/jproxy/service/impl/SonarrIndexerServiceImpl.java
@@ -24,7 +24,6 @@
import com.lckp.jproxy.entity.SonarrRule;
import com.lckp.jproxy.entity.SonarrTitle;
import com.lckp.jproxy.entity.TmdbTitle;
-import com.lckp.jproxy.model.FormatResult;
import com.lckp.jproxy.service.ISonarrIndexerService;
import com.lckp.jproxy.service.ISonarrRuleService;
import com.lckp.jproxy.service.ISonarrTitleService;
@@ -111,14 +110,13 @@ public String executeFormatRule(String xml) {
Element item = items.next();
Element titleElement = item.element(ApiField.INDEXER_TITLE);
String text = titleElement.getText();
- FormatResult formatResult = sonarrTitleService.formatTitle(text, format, cleanTitleRegex,
+ String formatText = sonarrTitleService.formatTitle(text, format, cleanTitleRegex,
tokenRuleMap.get(Token.TITLE), sonarrTitleList);
- String formatText = formatResult.getFormatText();
if (formatText.contains("{" + Token.TITLE + "}")) {
log.debug("索引器格式化失败:{} ==> 未匹配到标题", text);
continue;
}
- formatText = sonarrTitleService.format(formatResult.getRestText(), formatText, tokenRuleMap);
+ formatText = sonarrTitleService.format(text, formatText, tokenRuleMap);
titleElement.setText(formatText);
log.debug("索引器格式化:{} ==> {}", text, formatText);
}
diff --git a/src/main/java/com/lckp/jproxy/service/impl/SonarrTitleServiceImpl.java b/src/main/java/com/lckp/jproxy/service/impl/SonarrTitleServiceImpl.java
index 6e3efc4..dd634be 100644
--- a/src/main/java/com/lckp/jproxy/service/impl/SonarrTitleServiceImpl.java
+++ b/src/main/java/com/lckp/jproxy/service/impl/SonarrTitleServiceImpl.java
@@ -33,7 +33,6 @@
import com.lckp.jproxy.entity.SonarrRule;
import com.lckp.jproxy.entity.SonarrTitle;
import com.lckp.jproxy.mapper.SonarrTitleMapper;
-import com.lckp.jproxy.model.FormatResult;
import com.lckp.jproxy.model.request.SonarrTitleQueryRequest;
import com.lckp.jproxy.service.ISonarrTitleService;
import com.lckp.jproxy.service.ISystemConfigService;
@@ -206,10 +205,8 @@ public List queryAll() {
* java.lang.String, java.lang.String, java.util.List, java.util.List)
*/
@Override
- public FormatResult formatTitle(String text, String format, String cleanTitleRegex,
+ public String formatTitle(String text, String format, String cleanTitleRegex,
List sonarrRuleList, List sonarrTitleList) {
- FormatResult result = new FormatResult();
- result.setRestText(text);
for (SonarrRule sonarrRule : sonarrRuleList) {
if (sonarrRule.getRegex().contains("{" + Token.CLEAN_TITLE + "}")) {
for (SonarrTitle sonarrTitle : sonarrTitleList) {
@@ -218,8 +215,6 @@ public FormatResult formatTitle(String text, String format, String cleanTitleReg
String cleanText = FormatUtil.cleanTitle(text, cleanTitleRegex);
String regex = sonarrRule.getRegex().replace("{" + Token.CLEAN_TITLE + "}", cleanTitle);
if (cleanText.matches(regex)) {
- result.setRestText(text.replaceAll(
- "((?i)" + cleanTitle.replaceAll(FormatUtil.PLACEHOLDER, ".{0,3}") + ")", ""));
format = FormatUtil.replaceToken(Token.TITLE, sonarrTitle.getMainTitle(), format);
Integer seasonNumber = sonarrTitle.getSeasonNumber();
if (!Integer.valueOf(-1).equals(seasonNumber)
@@ -242,8 +237,7 @@ public FormatResult formatTitle(String text, String format, String cleanTitleReg
}
}
}
- result.setFormatText(format.trim());
- return result;
+ return format.trim();
}
/**