Skip to content

Commit

Permalink
v3.3.0 优化文件重命名逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyPuppy514 committed Jun 27, 2023
1 parent 51c3968 commit f5c821b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 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.3.0 2023-06-27

1. Optimize file rename logic

## v3.2.9 2023-06-22

1. Optimize file rename 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.3.0 2023-06-27

1. 优化文件重命名逻辑

## v3.2.9 2023-06-22

1. 优化文件重命名逻辑
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- 项目信息 -->
<groupId>com.lckp</groupId>
<artifactId>jproxy</artifactId>
<version>3.2.9</version>
<version>3.3.0</version>
<name>JProxy</name>
<description>介于 Sonarr/Radarr 和 Jackett/Prowlarr 之间的代理,主要用于优化查询和提升识别率</description>
<!-- 依赖版本 -->
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/lckp/jproxy/task/RadarrRenameTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ public synchronized void run() {
boolean renamed = false;
List<String> files = qbittorrentService.files(torrentInfoHash);
for (String oldFilePath : files) {
int startIndex = oldFilePath.lastIndexOf("/") + 1;
if (startIndex > 0 && sourceTitle
.equals(oldFilePath.substring(0, startIndex - 1))) {
int lastIndex = oldFilePath.lastIndexOf("/") + 1;
if (lastIndex > 0 && sourceTitle
.equals(oldFilePath.substring(0, lastIndex - 1))) {
log.debug("qBittorrent 文件已经重命名: {}", oldFilePath);
renamed = true;
break;
}
String oldFileName = oldFilePath.substring(startIndex);
String oldFileName = oldFilePath.substring(lastIndex);
String newFileName = oldFileName;
Matcher extensionMatcher = Pattern
.compile(Common.VIDEO_AND_SUBTITLE_EXTENSION_REGEX)
Expand All @@ -124,7 +124,15 @@ public synchronized void run() {
}
newFileName = newFileName + extension;
}
String newFilePath = sourceTitle + "/" + newFileName;
String newFilePath;
int index = oldFilePath.indexOf("/");
if (index + 1 == lastIndex) {
newFilePath = sourceTitle + "/" + newFileName;
} else {
newFilePath = sourceTitle
+ oldFilePath.substring(index, lastIndex)
+ newFileName;
}
qbittorrentService.renameFile(torrentInfoHash, oldFilePath,
newFilePath);
log.info("qBittorrent 文件重命名成功:{} => {}", oldFileName,
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/lckp/jproxy/task/SonarrRenameTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ public synchronized void run() {
newFileNameFormat = newFileNameFormat + "{" + Token.EPISODE + "}";
List<String> files = qbittorrentService.files(torrentInfoHash);
for (String oldFilePath : files) {
int startIndex = oldFilePath.lastIndexOf("/") + 1;
if (startIndex > 0 && sourceTitle
.equals(oldFilePath.substring(0, startIndex - 1))) {
int lastIndex = oldFilePath.lastIndexOf("/") + 1;
if (lastIndex > 0 && sourceTitle
.equals(oldFilePath.substring(0, lastIndex - 1))) {
log.debug("qBittorrent 文件已经重命名: {}", oldFilePath);
renamed = true;
break;
}
String oldFileName = oldFilePath.substring(startIndex);
String oldFileName = oldFilePath.substring(lastIndex);
String newFileName = oldFileName;
Matcher extensionMatcher = Pattern
.compile(Common.VIDEO_AND_SUBTITLE_EXTENSION_REGEX)
Expand All @@ -152,7 +152,15 @@ public synchronized void run() {
newFileName = newFileName + extension;
}
}
String newFilePath = sourceTitle + "/" + newFileName;
String newFilePath;
int index = oldFilePath.indexOf("/");
if (index + 1 == lastIndex) {
newFilePath = sourceTitle + "/" + newFileName;
} else {
newFilePath = sourceTitle
+ oldFilePath.substring(index, lastIndex)
+ newFileName;
}
qbittorrentService.renameFile(torrentInfoHash, oldFilePath,
newFilePath);
log.info("qBittorrent 文件重命名成功:{} => {}", oldFileName,
Expand Down

0 comments on commit f5c821b

Please sign in to comment.