mirror of
https://github.com/wushuo894/ani-rss.git
synced 2026-03-13 09:20:23 +00:00
refactor: 优化 @Service
This commit is contained in:
@@ -7,6 +7,7 @@ import ani.rss.util.other.AniUtil;
|
||||
import ani.rss.util.other.ConfigUtil;
|
||||
import cn.hutool.core.net.NetUtil;
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -20,6 +21,9 @@ import java.net.InetSocketAddress;
|
||||
@Component
|
||||
public class Runner implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
@Value("${server.port}")
|
||||
private String port;
|
||||
|
||||
@@ -30,7 +34,7 @@ public class Runner implements ApplicationRunner {
|
||||
ConfigUtil.backup();
|
||||
|
||||
AniUtil.load();
|
||||
TaskService.start();
|
||||
taskService.start();
|
||||
String version = MavenUtils.getVersion();
|
||||
log.info("version {}", version);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -44,6 +45,15 @@ import java.util.function.ToLongFunction;
|
||||
public class AniController extends BaseController {
|
||||
public static final AtomicBoolean DOWNLOAD = new AtomicBoolean(false);
|
||||
|
||||
@Resource
|
||||
private AniService aniService;
|
||||
|
||||
@Resource
|
||||
private ClearService clearService;
|
||||
|
||||
@Resource
|
||||
private DownloadService downloadService;
|
||||
|
||||
@Auth
|
||||
@Operation(summary = "添加订阅")
|
||||
@PostMapping("/addAni")
|
||||
@@ -84,7 +94,7 @@ public class AniController extends BaseController {
|
||||
if (enable) {
|
||||
ThreadUtil.execute(() -> {
|
||||
if (TorrentUtil.login()) {
|
||||
DownloadService.downloadAni(ani);
|
||||
downloadService.downloadAni(ani);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -130,8 +140,8 @@ public class AniController extends BaseController {
|
||||
if (Boolean.parseBoolean(move)) {
|
||||
Ani get = ObjectUtil.clone(first.get());
|
||||
ThreadUtil.execute(() -> {
|
||||
String downloadPath = DownloadService.getDownloadPath(get);
|
||||
String newDownloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = downloadService.getDownloadPath(get);
|
||||
String newDownloadPath = downloadService.getDownloadPath(ani);
|
||||
Boolean login = TorrentUtil.login();
|
||||
List<TorrentsInfo> torrentsInfos = new ArrayList<>();
|
||||
if (login) {
|
||||
@@ -170,7 +180,7 @@ public class AniController extends BaseController {
|
||||
FileUtil.move(oldFile, new File(newDownloadPath), true);
|
||||
}
|
||||
FileUtil.del(downloadPath);
|
||||
ClearService.clearParentFile(downloadPath);
|
||||
clearService.clearParentFile(downloadPath);
|
||||
} catch (Exception e) {
|
||||
log.error(ExceptionUtils.getMessage(e), e);
|
||||
}
|
||||
@@ -211,7 +221,7 @@ public class AniController extends BaseController {
|
||||
for (Ani ani : anis) {
|
||||
File torrentDir = TorrentUtil.getTorrentDir(ani);
|
||||
FileUtil.del(torrentDir);
|
||||
ClearService.clearParentFile(torrentDir);
|
||||
clearService.clearParentFile(torrentDir);
|
||||
log.info("删除订阅 {} {} {}", ani.getTitle(), ani.getUrl(), ani.getId());
|
||||
}
|
||||
if (!deleteFiles) {
|
||||
@@ -221,7 +231,7 @@ public class AniController extends BaseController {
|
||||
|
||||
List<File> files = anis
|
||||
.stream()
|
||||
.map(DownloadService::getDownloadPath)
|
||||
.map(ani -> downloadService.getDownloadPath(ani))
|
||||
.map(File::new)
|
||||
.toList();
|
||||
|
||||
@@ -244,7 +254,7 @@ public class AniController extends BaseController {
|
||||
ThreadUtil.sleep(3000);
|
||||
log.info("删除 {}", file);
|
||||
FileUtil.del(file);
|
||||
ClearService.clearParentFile(file);
|
||||
clearService.clearParentFile(file);
|
||||
}
|
||||
});
|
||||
return Result.success("删除订阅成功");
|
||||
@@ -329,7 +339,7 @@ public class AniController extends BaseController {
|
||||
log.error(e.getMessage(), e);
|
||||
continue;
|
||||
}
|
||||
Boolean b = AniService.updateTotalEpisodeNumber(ani, bgmInfo, force);
|
||||
Boolean b = aniService.updateTotalEpisodeNumber(ani, bgmInfo, force);
|
||||
if (b) {
|
||||
count++;
|
||||
}
|
||||
@@ -386,7 +396,7 @@ public class AniController extends BaseController {
|
||||
ThreadUtil.execute(() -> {
|
||||
try {
|
||||
if (TorrentUtil.login()) {
|
||||
DownloadService.downloadAni(downloadAni);
|
||||
downloadService.downloadAni(downloadAni);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String message = ExceptionUtils.getMessage(e);
|
||||
@@ -425,7 +435,7 @@ public class AniController extends BaseController {
|
||||
public Result<Map<String, Object>> previewAni(@RequestBody Ani ani) {
|
||||
List<Item> items = ItemsUtil.getItems(ani);
|
||||
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = downloadService.getDownloadPath(ani);
|
||||
|
||||
for (Item item : items) {
|
||||
item.setLocal(false);
|
||||
@@ -434,7 +444,7 @@ public class AniController extends BaseController {
|
||||
item.setLocal(true);
|
||||
continue;
|
||||
}
|
||||
if (DownloadService.itemDownloaded(ani, item, false)) {
|
||||
if (downloadService.itemDownloaded(ani, item, false)) {
|
||||
item.setLocal(true);
|
||||
}
|
||||
}
|
||||
@@ -453,7 +463,7 @@ public class AniController extends BaseController {
|
||||
@Operation(summary = "获取订阅的下载位置")
|
||||
@PostMapping("/downloadPath")
|
||||
public Result<Map<String, Object>> downloadPath(@RequestBody Ani ani) {
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = downloadService.getDownloadPath(ani);
|
||||
|
||||
boolean change = false;
|
||||
Optional<Ani> first = AniUtil.ANI_LIST.stream()
|
||||
@@ -463,7 +473,7 @@ public class AniController extends BaseController {
|
||||
Ani oldAni = ObjectUtil.clone(first.get());
|
||||
// 只在名称改变时移动
|
||||
oldAni.setSeason(ani.getSeason());
|
||||
String oldDownloadPath = DownloadService.getDownloadPath(oldAni);
|
||||
String oldDownloadPath = downloadService.getDownloadPath(oldAni);
|
||||
change = !downloadPath.equals(oldDownloadPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.Cleanup;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -52,6 +53,12 @@ public class ConfigController extends BaseController {
|
||||
|
||||
private final CronConfig cronConfig;
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
@Resource
|
||||
private ClearService clearService;
|
||||
|
||||
/**
|
||||
* 构建信息
|
||||
*/
|
||||
@@ -132,7 +139,7 @@ public class ConfigController extends BaseController {
|
||||
!Objects.equals(newSleep, sleep) ||
|
||||
!Objects.equals(newRenameSleepSeconds, renameSleepSeconds)
|
||||
) {
|
||||
TaskService.restart();
|
||||
taskService.restart();
|
||||
}
|
||||
// 下载工具发生改变
|
||||
if (!download.equals(config.getDownloadToolType())) {
|
||||
@@ -177,7 +184,7 @@ public class ConfigController extends BaseController {
|
||||
|
||||
for (File file : files) {
|
||||
FileUtil.del(file);
|
||||
ClearService.clearParentFile(file);
|
||||
clearService.clearParentFile(file);
|
||||
}
|
||||
|
||||
FileUtil.del(configDirStr + "/img");
|
||||
@@ -324,7 +331,7 @@ public class ConfigController extends BaseController {
|
||||
// 重新加载设置
|
||||
ConfigUtil.load();
|
||||
AniUtil.load();
|
||||
TaskService.restart();
|
||||
taskService.restart();
|
||||
|
||||
return Result.success("导入成功");
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.hutool.core.thread.ExecutorBuilder;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -26,6 +27,10 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class EmbyController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private DownloadService downloadService;
|
||||
|
||||
@Auth
|
||||
@Operation(summary = "获取媒体库")
|
||||
@PostMapping("/getEmbyViews")
|
||||
@@ -159,7 +164,7 @@ public class EmbyController extends BaseController {
|
||||
|
||||
String path = item.getPath();
|
||||
String parent = new File(path).getParent();
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = downloadService.getDownloadPath(ani);
|
||||
if (downloadPath.equals(parent)) {
|
||||
// 路径相同
|
||||
return true;
|
||||
|
||||
@@ -17,6 +17,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.matthewn4444.ebml.EBMLReader;
|
||||
import com.matthewn4444.ebml.subtitles.Subtitles;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Cleanup;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -29,6 +30,9 @@ import java.util.*;
|
||||
@RestController
|
||||
public class PlayController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private DownloadService downloadService;
|
||||
|
||||
@Auth
|
||||
@Operation(summary = "获取内封字幕")
|
||||
@PostMapping("/getSubtitles")
|
||||
@@ -96,7 +100,7 @@ public class PlayController extends BaseController {
|
||||
}
|
||||
ani = first.get();
|
||||
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = downloadService.getDownloadPath(ani);
|
||||
List<PlayItem> collect = getPlayItem(new File(downloadPath));
|
||||
|
||||
// 按照集数排序
|
||||
|
||||
@@ -6,6 +6,7 @@ import ani.rss.entity.Result;
|
||||
import ani.rss.service.ScrapeService;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -14,12 +15,15 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class ScrapeController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ScrapeService scrapeService;
|
||||
|
||||
@Auth
|
||||
@Operation(summary = "刮削")
|
||||
@PostMapping("/scrape")
|
||||
public Result<Void> scrape(@RequestParam("force") Boolean force, @RequestBody Ani ani) {
|
||||
ThreadUtil.execute(() ->
|
||||
ScrapeService.scrape(ani, force)
|
||||
scrapeService.scrape(ani, force)
|
||||
);
|
||||
|
||||
String title = ani.getTitle();
|
||||
|
||||
@@ -40,6 +40,8 @@ import java.util.*;
|
||||
@RequiredArgsConstructor
|
||||
public class qBittorrent implements BaseDownload {
|
||||
|
||||
private final DownloadService downloadService;
|
||||
|
||||
private Config config;
|
||||
|
||||
/**
|
||||
@@ -354,7 +356,7 @@ public class qBittorrent implements BaseDownload {
|
||||
|
||||
String host = config.getDownloadToolHost();
|
||||
|
||||
Optional<Ani> aniOpt = DownloadService.findAniByDownloadPath(torrentsInfo);
|
||||
Optional<Ani> aniOpt = downloadService.findAniByDownloadPath(torrentsInfo);
|
||||
|
||||
if (aniOpt.isEmpty()) {
|
||||
log.error("未能获取番剧对象: {}", torrentsInfo.getName());
|
||||
|
||||
@@ -15,6 +15,7 @@ import cn.hutool.core.lang.func.Func1;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import wushuo.tmdb.api.entity.Tmdb;
|
||||
|
||||
import java.util.List;
|
||||
@@ -120,7 +121,7 @@ public interface BaseNotification {
|
||||
notificationTemplate = notificationTemplate.replace("${emoji}", emoji);
|
||||
notificationTemplate = notificationTemplate.replace("${action}", action);
|
||||
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani);
|
||||
notificationTemplate = notificationTemplate.replace("${downloadPath}", downloadPath);
|
||||
|
||||
if (notificationTemplate.contains("${jpTitle}")) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
@@ -58,7 +59,7 @@ public class FileMoveNotification implements BaseNotification {
|
||||
ani = ObjectUtil.clone(ani);
|
||||
|
||||
// 旧的位置
|
||||
String src = DownloadService.getDownloadPath(ani);
|
||||
String src = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani);
|
||||
|
||||
// 新的位置; 设置自定义下载位置同时启用, 用以获取新的位置
|
||||
Boolean ova = ani.getOva();
|
||||
@@ -72,7 +73,7 @@ public class FileMoveNotification implements BaseNotification {
|
||||
}
|
||||
ani.setCustomDownloadPath(true);
|
||||
|
||||
String target = DownloadService.getDownloadPath(ani);
|
||||
String target = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani);
|
||||
|
||||
// 进行移动
|
||||
FileUtil.mkdir(target);
|
||||
|
||||
@@ -18,6 +18,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpConfig;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
@@ -91,7 +92,7 @@ public class OpenListUploadNotification implements BaseNotification {
|
||||
Boolean deleteOldEpisode = notificationConfig.getOpenListUploadDeleteOldEpisode();
|
||||
|
||||
// 本地位置
|
||||
String localPath = DownloadService.getDownloadPath(ani);
|
||||
String localPath = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani);
|
||||
|
||||
// 新的位置; 设置自定义下载位置同时启用, 用以获取新的位置
|
||||
Boolean ova = ani.getOva();
|
||||
@@ -109,7 +110,7 @@ public class OpenListUploadNotification implements BaseNotification {
|
||||
|
||||
ani.setCustomDownloadPath(true);
|
||||
|
||||
String target = DownloadService.getDownloadPath(ani);
|
||||
String target = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani);
|
||||
target = ReUtil.replaceAll(target, "^[A-z]:", "");
|
||||
|
||||
if (ova) {
|
||||
|
||||
@@ -4,8 +4,10 @@ import ani.rss.entity.Ani;
|
||||
import ani.rss.entity.BgmInfo;
|
||||
import ani.rss.util.other.BgmUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AniService {
|
||||
|
||||
/**
|
||||
@@ -16,7 +18,7 @@ public class AniService {
|
||||
* @param force 强制
|
||||
* @return 是否已发生更新
|
||||
*/
|
||||
public static Boolean updateTotalEpisodeNumber(Ani ani, BgmInfo bgmInfo, Boolean force) {
|
||||
public Boolean updateTotalEpisodeNumber(Ani ani, BgmInfo bgmInfo, Boolean force) {
|
||||
Integer totalEpisodeNumber = ani.getTotalEpisodeNumber();
|
||||
if (!force) {
|
||||
// 未开启强制更新
|
||||
|
||||
@@ -4,19 +4,21 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ClearService {
|
||||
/**
|
||||
* 清理父级空文件夹
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
public static void clearParentFile(String path) {
|
||||
public void clearParentFile(String path) {
|
||||
clearParentFile(new File(path));
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ public class ClearService {
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
public static void clearParentFile(File file) {
|
||||
public void clearParentFile(File file) {
|
||||
if (file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,10 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.Synchronized;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import wushuo.tmdb.api.entity.Tmdb;
|
||||
|
||||
import java.io.File;
|
||||
@@ -32,16 +34,20 @@ import java.util.stream.Collectors;
|
||||
* 下载的主要逻辑
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DownloadService {
|
||||
private static final String lock = "lock";
|
||||
private static final Object LOCK = new Object();
|
||||
|
||||
@Resource
|
||||
private ScrapeService scrapeService;
|
||||
|
||||
/**
|
||||
* 下载动漫
|
||||
*
|
||||
* @param ani
|
||||
*/
|
||||
@Synchronized("lock")
|
||||
public static void downloadAni(Ani ani) {
|
||||
@Synchronized("LOCK")
|
||||
public void downloadAni(Ani ani) {
|
||||
Config config = ConfigUtil.CONFIG;
|
||||
Boolean delete = config.getDelete();
|
||||
Boolean autoDisabled = config.getAutoDisabled();
|
||||
@@ -271,7 +277,7 @@ public class DownloadService {
|
||||
* @param ani
|
||||
* @param item
|
||||
*/
|
||||
public static void deleteStandbyRss(Ani ani, Item item) {
|
||||
public void deleteStandbyRss(Ani ani, Item item) {
|
||||
Config config = ConfigUtil.CONFIG;
|
||||
Boolean standbyRss = config.getStandbyRss();
|
||||
Boolean coexist = config.getCoexist();
|
||||
@@ -375,7 +381,7 @@ public class DownloadService {
|
||||
* @param savePath
|
||||
* @param torrentFile
|
||||
*/
|
||||
public static synchronized void download(Ani ani, Item item, String savePath, File torrentFile) {
|
||||
public synchronized void download(Ani ani, Item item, String savePath, File torrentFile) {
|
||||
ani = ObjectUtil.clone(ani);
|
||||
|
||||
String name = item.getReName();
|
||||
@@ -429,7 +435,7 @@ public class DownloadService {
|
||||
*
|
||||
* @param torrentsInfo
|
||||
*/
|
||||
public static synchronized void notification(TorrentsInfo torrentsInfo) {
|
||||
public synchronized void notification(TorrentsInfo torrentsInfo) {
|
||||
TorrentsInfo.State state = torrentsInfo.getState();
|
||||
String name = torrentsInfo.getName();
|
||||
|
||||
@@ -481,8 +487,13 @@ public class DownloadService {
|
||||
Config config = ConfigUtil.CONFIG;
|
||||
Boolean scrape = config.getScrape();
|
||||
if (scrape) {
|
||||
// 刮削
|
||||
ScrapeService.scrape(ani, false);
|
||||
try {
|
||||
// 刮削
|
||||
scrapeService.scrape(ani, false);
|
||||
} catch (Exception e) {
|
||||
log.error("刮削失败: {}", ani.getTitle());
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
String text = StrFormatter.format("{} 下载完成", name);
|
||||
if (tags.contains(TorrentsTags.BACK_RSS.getValue())) {
|
||||
@@ -506,7 +517,7 @@ public class DownloadService {
|
||||
* @param ani
|
||||
* @return
|
||||
*/
|
||||
public static String getDownloadPath(Ani ani) {
|
||||
public String getDownloadPath(Ani ani) {
|
||||
return getDownloadPath(ani, ConfigUtil.CONFIG);
|
||||
}
|
||||
|
||||
@@ -516,7 +527,7 @@ public class DownloadService {
|
||||
* @param ani
|
||||
* @return
|
||||
*/
|
||||
public static String getDownloadPath(Ani ani, Config config) {
|
||||
public String getDownloadPath(Ani ani, Config config) {
|
||||
Boolean customDownloadPath = ani.getCustomDownloadPath();
|
||||
String aniDownloadPath = ani.getDownloadPath();
|
||||
Boolean ova = ani.getOva();
|
||||
@@ -633,7 +644,7 @@ public class DownloadService {
|
||||
* @param downloadList
|
||||
* @return
|
||||
*/
|
||||
public static Boolean itemDownloaded(Ani ani, Item item, Boolean downloadList) {
|
||||
public Boolean itemDownloaded(Ani ani, Item item, Boolean downloadList) {
|
||||
Config config = ConfigUtil.CONFIG;
|
||||
Boolean rename = config.getRename();
|
||||
if (!rename) {
|
||||
@@ -725,7 +736,7 @@ public class DownloadService {
|
||||
* @param torrentsInfo
|
||||
* @return
|
||||
*/
|
||||
public static synchronized Optional<Ani> findAniByDownloadPath(TorrentsInfo torrentsInfo) {
|
||||
public synchronized Optional<Ani> findAniByDownloadPath(TorrentsInfo torrentsInfo) {
|
||||
String downloadDir = torrentsInfo.getDownloadDir();
|
||||
return AniUtil.ANI_LIST
|
||||
.stream()
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import wushuo.tmdb.api.entity.*;
|
||||
@@ -24,6 +25,7 @@ import java.util.Objects;
|
||||
* nfo生成
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class NfoGenerator {
|
||||
|
||||
/**
|
||||
@@ -33,7 +35,7 @@ public class NfoGenerator {
|
||||
* @param outputPath 输出位置
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateEpisodeNfo(TmdbEpisode tmdbEpisode, String outputPath) throws Exception {
|
||||
public void generateEpisodeNfo(TmdbEpisode tmdbEpisode, String outputPath) throws Exception {
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||
Document doc = docBuilder.newDocument();
|
||||
@@ -60,7 +62,7 @@ public class NfoGenerator {
|
||||
* @param outputPath
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateSeasonNfo(TmdbSeason tmdbSeason, String outputPath) throws Exception {
|
||||
public void generateSeasonNfo(TmdbSeason tmdbSeason, String outputPath) throws Exception {
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||
Document doc = docBuilder.newDocument();
|
||||
@@ -90,7 +92,7 @@ public class NfoGenerator {
|
||||
* @param outputPath 输出位置
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateTvShowNfo(Tmdb tmdb, String outputPath) throws Exception {
|
||||
public void generateTvShowNfo(Tmdb tmdb, String outputPath) throws Exception {
|
||||
generateNfo(tmdb, outputPath, "tvshow");
|
||||
}
|
||||
|
||||
@@ -101,7 +103,7 @@ public class NfoGenerator {
|
||||
* @param outputPath 输出位置
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateMovieNfo(Tmdb tmdb, String outputPath) throws Exception {
|
||||
public void generateMovieNfo(Tmdb tmdb, String outputPath) throws Exception {
|
||||
generateNfo(tmdb, outputPath, "movie");
|
||||
}
|
||||
|
||||
@@ -113,7 +115,7 @@ public class NfoGenerator {
|
||||
* @param rootTag 根标签
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateNfo(Tmdb tmdb, String outputPath, String rootTag) throws Exception {
|
||||
public void generateNfo(Tmdb tmdb, String outputPath, String rootTag) throws Exception {
|
||||
// 创建 XML 文档
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||
@@ -191,7 +193,7 @@ public class NfoGenerator {
|
||||
* @param tagName 标签名
|
||||
* @param value 文本值
|
||||
*/
|
||||
private static void addElement(Document doc, Element parent, String tagName, Object value) {
|
||||
private void addElement(Document doc, Element parent, String tagName, Object value) {
|
||||
if (Objects.isNull(value)) {
|
||||
return;
|
||||
}
|
||||
@@ -214,7 +216,7 @@ public class NfoGenerator {
|
||||
* @param savePath 保存位置
|
||||
* @throws Exception
|
||||
*/
|
||||
private static void saveXmlDocument(Document doc, String savePath) throws Exception {
|
||||
private void saveXmlDocument(Document doc, String savePath) throws Exception {
|
||||
FileUtil.mkdir(new File(savePath).getParentFile());
|
||||
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
|
||||
@@ -9,7 +9,10 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import wushuo.tmdb.api.entity.*;
|
||||
import wushuo.tmdb.api.enums.TmdbTypeEnum;
|
||||
|
||||
@@ -23,14 +26,23 @@ import java.util.stream.Stream;
|
||||
* 刮削
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ScrapeService {
|
||||
|
||||
@Resource
|
||||
private NfoGenerator nfoGenerator;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private DownloadService downloadService;
|
||||
|
||||
/**
|
||||
* 刮削
|
||||
*
|
||||
* @param ani 订阅
|
||||
* @param force 强制
|
||||
*/
|
||||
public static void scrape(Ani ani, Boolean force) {
|
||||
public void scrape(Ani ani, Boolean force) {
|
||||
String title = ani.getTitle();
|
||||
|
||||
Tmdb tmdb = ani.getTmdb();
|
||||
@@ -39,13 +51,14 @@ public class ScrapeService {
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean ova = ani.getOva();
|
||||
boolean isForce = Boolean.TRUE.equals(force);
|
||||
boolean isOva = Boolean.TRUE.equals(ani.getOva());
|
||||
try {
|
||||
log.info("正在刮削 ... {}", title);
|
||||
if (ova) {
|
||||
scrapeMovie(ani, force);
|
||||
if (isOva) {
|
||||
scrapeMovie(ani, isForce);
|
||||
} else {
|
||||
scrapeTv(ani, force);
|
||||
scrapeTv(ani, isForce);
|
||||
}
|
||||
log.info("刮削完成 {}", title);
|
||||
} catch (Exception e) {
|
||||
@@ -61,7 +74,7 @@ public class ScrapeService {
|
||||
* @param force 强制
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void scrapeMovie(Ani ani, Boolean force) throws Exception {
|
||||
public void scrapeMovie(Ani ani, Boolean force) throws Exception {
|
||||
Tmdb tmdb = ani.getTmdb();
|
||||
|
||||
// 更新tmdb信息
|
||||
@@ -73,7 +86,7 @@ public class ScrapeService {
|
||||
tmdb = tmdbOptional.get();
|
||||
|
||||
// 下载位置
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = downloadService.getDownloadPath(ani);
|
||||
File[] files = FileUtils.listFiles(downloadPath);
|
||||
|
||||
if (ArrayUtil.isEmpty(files)) {
|
||||
@@ -101,7 +114,7 @@ public class ScrapeService {
|
||||
// 保存nfo
|
||||
String outputPath = downloadPath + "/" + mainName + ".nfo";
|
||||
if (force || !FileUtil.exist(outputPath)) {
|
||||
NfoGenerator.generateMovieNfo(tmdb, outputPath);
|
||||
nfoGenerator.generateMovieNfo(tmdb, outputPath);
|
||||
}
|
||||
|
||||
String posterPath = tmdb.getPosterPath();
|
||||
@@ -138,7 +151,7 @@ public class ScrapeService {
|
||||
* @param force 强制
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void scrapeTv(Ani ani, Boolean force) throws Exception {
|
||||
public void scrapeTv(Ani ani, Boolean force) throws Exception {
|
||||
Tmdb tmdb = ani.getTmdb();
|
||||
|
||||
// 更新tmdb信息
|
||||
@@ -150,7 +163,7 @@ public class ScrapeService {
|
||||
tmdb = tmdbOptional.get();
|
||||
|
||||
// 下载位置
|
||||
File downloadPath = new File(DownloadService.getDownloadPath(ani));
|
||||
File downloadPath = new File(downloadService.getDownloadPath(ani));
|
||||
if (!FileUtil.exist(downloadPath)) {
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +171,7 @@ public class ScrapeService {
|
||||
// tvshow.nfo
|
||||
String tvShowNfoFile = downloadPath.getParent() + "/tvshow.nfo";
|
||||
if (force || !FileUtil.exist(tvShowNfoFile)) {
|
||||
NfoGenerator.generateTvShowNfo(tmdb, tvShowNfoFile);
|
||||
nfoGenerator.generateTvShowNfo(tmdb, tvShowNfoFile);
|
||||
}
|
||||
|
||||
String posterPath = tmdb.getPosterPath();
|
||||
@@ -206,7 +219,7 @@ public class ScrapeService {
|
||||
// 季nfo
|
||||
String seasonNfoFile = downloadPath + "/season.nfo";
|
||||
if (force || !FileUtil.exist(seasonNfoFile)) {
|
||||
NfoGenerator.generateSeasonNfo(tmdbSeason, seasonNfoFile);
|
||||
nfoGenerator.generateSeasonNfo(tmdbSeason, seasonNfoFile);
|
||||
}
|
||||
|
||||
File[] files = FileUtils.listFiles(downloadPath);
|
||||
@@ -260,7 +273,7 @@ public class ScrapeService {
|
||||
// 集图片
|
||||
String episodeFile = downloadPath + "/" + mainName + ".nfo";
|
||||
if (force || !FileUtil.exist(episodeFile)) {
|
||||
NfoGenerator.generateEpisodeNfo(tmdbEpisode, episodeFile);
|
||||
nfoGenerator.generateEpisodeNfo(tmdbEpisode, episodeFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -273,7 +286,7 @@ public class ScrapeService {
|
||||
* @param force 强制
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void saveImages(String tmdbPath, File saveFile, Boolean force) throws Exception {
|
||||
public void saveImages(String tmdbPath, File saveFile, Boolean force) throws Exception {
|
||||
if (StrUtil.isBlank(tmdbPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,17 +5,19 @@ import ani.rss.task.RenameTask;
|
||||
import ani.rss.task.RssTask;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TaskService {
|
||||
public static final AtomicBoolean LOOP = new AtomicBoolean(false);
|
||||
public static final List<Thread> THREADS = new Vector<>();
|
||||
|
||||
public static synchronized void stop() {
|
||||
public synchronized void stop() {
|
||||
LOOP.set(false);
|
||||
for (Thread thread : THREADS) {
|
||||
try {
|
||||
@@ -32,12 +34,16 @@ public class TaskService {
|
||||
THREADS.clear();
|
||||
}
|
||||
|
||||
public static synchronized void restart() {
|
||||
public synchronized void restart() {
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
||||
public static synchronized void start() {
|
||||
public synchronized void start() {
|
||||
if (LOOP.get() && !THREADS.isEmpty()) {
|
||||
log.warn("任务已经在运行中");
|
||||
return;
|
||||
}
|
||||
LOOP.set(true);
|
||||
THREADS.add(new RenameTask(LOOP));
|
||||
THREADS.add(new RssTask(LOOP));
|
||||
|
||||
@@ -8,6 +8,7 @@ import ani.rss.util.other.AniUtil;
|
||||
import ani.rss.util.other.BgmUtil;
|
||||
import ani.rss.util.other.ConfigUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
@@ -69,7 +70,7 @@ public class BgmTask extends Thread {
|
||||
continue;
|
||||
}
|
||||
|
||||
AniService.updateTotalEpisodeNumber(ani, bgmInfo, forceUpdateTotalEpisodeNumber);
|
||||
SpringUtil.getBean(AniService.class).updateTotalEpisodeNumber(ani, bgmInfo, forceUpdateTotalEpisodeNumber);
|
||||
}
|
||||
AniUtil.sync();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import ani.rss.service.DownloadService;
|
||||
import ani.rss.util.other.ConfigUtil;
|
||||
import ani.rss.util.other.TorrentUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
@@ -45,7 +46,7 @@ public class RenameTask extends Thread {
|
||||
Boolean deleteStandbyRSSOnly = config.getDeleteStandbyRSSOnly();
|
||||
try {
|
||||
TorrentUtil.rename(torrentsInfo);
|
||||
DownloadService.notification(torrentsInfo);
|
||||
SpringUtil.getBean(DownloadService.class).notification(torrentsInfo);
|
||||
if (deleteStandbyRSSOnly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import ani.rss.util.other.AniUtil;
|
||||
import ani.rss.util.other.ConfigUtil;
|
||||
import ani.rss.util.other.TorrentUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -46,7 +47,7 @@ public class RssTask extends Thread {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
DownloadService.downloadAni(ani);
|
||||
SpringUtil.getBean(DownloadService.class).downloadAni(ani);
|
||||
} catch (Exception e) {
|
||||
String message = ExceptionUtils.getMessage(e);
|
||||
log.error("{} {}", title, message);
|
||||
|
||||
@@ -16,6 +16,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -335,14 +336,14 @@ public class AniUtil {
|
||||
}
|
||||
|
||||
// 旧文件路径
|
||||
String oldPath = DownloadService.getDownloadPath(ani, config);
|
||||
String oldPath = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani, config);
|
||||
|
||||
config.setDownloadPathTemplate(completedPathTemplate);
|
||||
// 因为临时修改下载位置模版以获取对应下载位置, 要关闭自定义下载位置
|
||||
ani.setCustomDownloadPath(false);
|
||||
|
||||
// 新文件路径
|
||||
String newPath = DownloadService.getDownloadPath(ani, config);
|
||||
String newPath = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani, config);
|
||||
|
||||
if (!FileUtil.exist(oldPath)) {
|
||||
// 旧文件不存在
|
||||
@@ -379,7 +380,7 @@ public class AniUtil {
|
||||
log.info("移动 {} ==> {}", file, newPath);
|
||||
FileUtil.move(file, new File(newPath), true);
|
||||
// 清理残留文件夹
|
||||
ClearService.clearParentFile(file);
|
||||
SpringUtil.getBean(ClearService.class).clearParentFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
@@ -818,7 +819,7 @@ public class BgmUtil {
|
||||
}
|
||||
|
||||
// 下载位置
|
||||
String downloadPath = DownloadService.getDownloadPath(ani);
|
||||
String downloadPath = SpringUtil.getBean(DownloadService.class).getDownloadPath(ani);
|
||||
|
||||
String completedPathTemplate = config.getCompletedPathTemplate();
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@ import ani.rss.util.basic.HttpReq;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.bittorrent.TorrentFile;
|
||||
|
||||
@@ -229,7 +230,7 @@ public class TorrentUtil {
|
||||
return true;
|
||||
}
|
||||
// 清理空文件夹
|
||||
ClearService.clearParentFile(new File(torrentsInfo.getDownloadDir() + "/" + name));
|
||||
SpringUtil.getBean(ClearService.class).clearParentFile(new File(torrentsInfo.getDownloadDir() + "/" + name));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -318,7 +319,7 @@ public class TorrentUtil {
|
||||
ConfigUtil.sync();
|
||||
}
|
||||
|
||||
DOWNLOAD = ReflectUtil.newInstance("ani.rss.download." + download);
|
||||
DOWNLOAD = SpringUtil.getBean(ClassUtil.loadClass("ani.rss.download." + download));
|
||||
log.info("下载工具 {}", download);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user