Skip to content

Commit

Permalink
v3.0.3 优化标题匹配逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyPuppy514 committed Apr 7, 2023
1 parent 2f7fcbc commit 9f55106
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 50 deletions.
4 changes: 4 additions & 0 deletions changelog.en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

# 变更日志

## v3.0.3 2023-04-07

1. 优化标题匹配逻辑

## v3.0.2 2023-04-07

1. 优化 Radarr 标题匹配逻辑
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/com/lckp/jproxy/model/FormatResult.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -61,9 +60,9 @@ public interface ISonarrTitleService extends IService<SonarrTitle> {
* @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<SonarrRule> sonarrRuleList, List<SonarrTitle> sonarrTitleList);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,15 +92,15 @@ public IPage<SonarrExample> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,10 +205,8 @@ public List<SonarrTitle> 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<SonarrRule> sonarrRuleList, List<SonarrTitle> sonarrTitleList) {
FormatResult result = new FormatResult();
result.setRestText(text);
for (SonarrRule sonarrRule : sonarrRuleList) {
if (sonarrRule.getRegex().contains("{" + Token.CLEAN_TITLE + "}")) {
for (SonarrTitle sonarrTitle : sonarrTitleList) {
Expand All @@ -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)
Expand All @@ -242,8 +237,7 @@ public FormatResult formatTitle(String text, String format, String cleanTitleReg
}
}
}
result.setFormatText(format.trim());
return result;
return format.trim();
}

/**
Expand Down

0 comments on commit 9f55106

Please sign in to comment.