Skip to content

Commit

Permalink
v3.1.7 新增文件重命名开关
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyPuppy514 committed Apr 15, 2023
1 parent 279b902 commit 5d10b42
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 243 deletions.
1 change: 1 addition & 0 deletions README.en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ If you want deploy via `docker run` ,see [docker-run.sh](https://github.com/Lu
| CACHE_EXPIRES | 4320 | Cache expiration time (minutes) |
| TOKEN_EXPIRES | 10080 | Login expiration time (minutes) |
| SYNC_INTERVAL | 3 | Synchronization interval (minutes) |
| RENAME_FILE | true | File rename switch (true/false) |

### Windows

Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ services:

如需使用 `docker run` 进行部署,请参考 [docker-run.sh](https://github.com/LuckyPuppy514/jproxy/blob/main/docker/docker-run.sh)

| 参数名 | 默认值 | 说明 |
| :-----------: | :---------------: | :------------------: |
| PUID | 0 | 用户 ID |
| PGID | 0 | 组 ID |
| TZ | Asia/Shanghai | 时区 |
| JAVA_OPTS | -Xms512m -Xmx512m | JVM 运行参数 |
| CACHE_EXPIRES | 4320 | 缓存过期时间(分钟) |
| TOKEN_EXPIRES | 10080 | 登录过期时间(分钟) |
| SYNC_INTERVAL | 3 | 同步间隔(分钟) |
| 参数名 | 默认值 | 说明 |
| :-----------: | :---------------: | :--------------------------: |
| PUID | 0 | 用户 ID |
| PGID | 0 | 组 ID |
| TZ | Asia/Shanghai | 时区 |
| JAVA_OPTS | -Xms512m -Xmx512m | JVM 运行参数 |
| CACHE_EXPIRES | 4320 | 缓存过期时间(分钟) |
| TOKEN_EXPIRES | 10080 | 登录过期时间(分钟) |
| SYNC_INTERVAL | 3 | 同步间隔(分钟) |
| RENAME_FILE | true | 文件重命名开关(true/false) |

### Windows

Expand Down
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.1.7 2023-04-16

1. Add file rename switch

## v3.1.6 2023-04-14

1. Fix downloader rename bug
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.1.7 2023-04-16

1. 新增文件重命名开关

## v3.1.6 2023-04-14

1. 修复下载器重命名BUG
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.1.6</version>
<version>3.1.7</version>
<name>JProxy</name>
<description>介于 Sonarr/Radarr 和 Jackett/Prowlarr 之间的代理,主要用于优化查询和提升识别率</description>
<!-- 依赖版本 -->
Expand Down
56 changes: 33 additions & 23 deletions src/main/java/com/lckp/jproxy/task/RadarrRenameTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class RadarrRenameTask {
@Value("${time.radarr-rename-fall-back}")
private int fallBackTime;

@Value("${rename.file}")
private boolean renameFile;

@Scheduled(cron = "${time.radarr-rename}")
public synchronized void run() {
try {
Expand Down Expand Up @@ -96,31 +99,38 @@ public synchronized void run() {
transmissionService.rename(torrentInfoHash, sourceTitle);
} else {
if (qbittorrentService.rename(torrentInfoHash, sourceTitle)) {
boolean renamed = false;
List<String> files = qbittorrentService.files(torrentInfoHash);
for (String oldFilePath : files) {
int startIndex = oldFilePath.lastIndexOf("/") + 1;
if (sourceTitle.equals(oldFilePath.substring(0, startIndex - 1))) {
log.debug("qBittorrent 文件已经重命名: {}", oldFilePath);
renamed = true;
break;
if (renameFile) {
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))) {
log.debug("qBittorrent 文件已经重命名: {}", oldFilePath);
renamed = true;
break;
}
String oldFileName = oldFilePath.substring(startIndex);
String newFileName = oldFileName;
Matcher extensionMatcher = Pattern
.compile(Common.VIDEO_EXTENSION_REGEX)
.matcher(oldFileName);
if (extensionMatcher.find()) {
String extension = extensionMatcher.group(1);
newFileName = sourceTitle + extension;
}
String newFilePath = sourceTitle + "/" + newFileName;
qbittorrentService.renameFile(torrentInfoHash, oldFilePath,
newFilePath);
log.info("qBittorrent 文件重命名成功:{} => {}", oldFileName,
newFileName);
}
String oldFileName = oldFilePath.substring(startIndex);
String newFileName = oldFileName;
Matcher extensionMatcher = Pattern
.compile(Common.VIDEO_EXTENSION_REGEX).matcher(oldFileName);
if (extensionMatcher.find()) {
String extension = extensionMatcher.group(1);
newFileName = sourceTitle + extension;
if (!renamed) {
log.info("qBittorrent 种子重命名成功:{} => {}", torrentInfoHash,
sourceTitle);
}
String newFilePath = sourceTitle + "/" + newFileName;
qbittorrentService.renameFile(torrentInfoHash, oldFilePath,
newFilePath);
log.info("qBittorrent 文件重命名成功:{} => {}", oldFileName, newFileName);
}
if (!renamed) {
log.info("qBittorrent 种子重命名成功:{} => {}", torrentInfoHash,
sourceTitle);
} else {
log.debug("已关闭文件重命名");
}
} else {
log.debug("qBittorrent 种子重命名失败:{} => {}", torrentInfoHash, sourceTitle);
Expand Down
79 changes: 45 additions & 34 deletions src/main/java/com/lckp/jproxy/task/SonarrRenameTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class SonarrRenameTask {
@Value("${time.sonarr-rename-fall-back}")
private int fallBackTime;

@Value("${rename.file}")
private boolean renameFile;

@Scheduled(cron = "${time.sonarr-rename}")
public synchronized void run() {
try {
Expand Down Expand Up @@ -112,42 +115,50 @@ public synchronized void run() {
transmissionService.rename(torrentInfoHash, sourceTitle);
} else {
if (qbittorrentService.rename(torrentInfoHash, sourceTitle)) {
boolean renamed = false;
// 文件重命名 Exx
String 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))) {
log.debug("qBittorrent 文件已经重命名: {}", oldFilePath);
renamed = true;
break;
}
String oldFileName = oldFilePath.substring(startIndex);
String newFileName = oldFileName;
Matcher extensionMatcher = Pattern
.compile(Common.VIDEO_EXTENSION_REGEX).matcher(oldFileName);
if (extensionMatcher.find()) {
String extension = extensionMatcher.group(1);
newFileName = extensionMatcher.replaceAll("");
newFileName = sonarrTitleService
.format(oldFileName, newFileNameFormat, tokenRuleMap)
.trim();
if (StringUtils.isBlank(newFileName)) {
newFileName = oldFileName;
} else {
newFileName = newFileName + extension;
if (renameFile) {
boolean renamed = false;
// 文件重命名 SxxExx
String newFileNameFormat = sonarrTitleService.format(sourceTitle,
"{" + Token.SEASON + "}", tokenRuleMap);
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))) {
log.debug("qBittorrent 文件已经重命名: {}", oldFilePath);
renamed = true;
break;
}
String oldFileName = oldFilePath.substring(startIndex);
String newFileName = oldFileName;
Matcher extensionMatcher = Pattern
.compile(Common.VIDEO_EXTENSION_REGEX)
.matcher(oldFileName);
if (extensionMatcher.find()) {
String extension = extensionMatcher.group(1);
newFileName = extensionMatcher.replaceAll("");
newFileName = sonarrTitleService
.format(oldFileName, newFileNameFormat, tokenRuleMap)
.trim();
if (StringUtils.isBlank(newFileName)) {
newFileName = oldFileName;
} else {
newFileName = newFileName + extension;
}
}
String newFilePath = sourceTitle + "/" + newFileName;
qbittorrentService.renameFile(torrentInfoHash, oldFilePath,
newFilePath);
log.info("qBittorrent 文件重命名成功:{} => {}", oldFileName,
newFileName);
}
String newFilePath = sourceTitle + "/" + newFileName;
qbittorrentService.renameFile(torrentInfoHash, oldFilePath,
newFilePath);
log.info("qBittorrent 文件重命名成功:{} => {}", oldFileName, newFileName);
}
if (!renamed) {
log.info("qBittorrent 种子重命名成功:{} => {}", torrentInfoHash,
sourceTitle);
if (!renamed) {
log.info("qBittorrent 种子重命名成功:{} => {}", torrentInfoHash,
sourceTitle);
}
} else {
log.debug("已关闭文件重命名");
}
} else {
log.debug("qBittorrent 种子重命名失败:{} => {}", torrentInfoHash, sourceTitle);
Expand Down
Loading

0 comments on commit 5d10b42

Please sign in to comment.