diff --git a/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrApi.java b/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrApi.java deleted file mode 100644 index 6206185..0000000 --- a/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrApi.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.nekolr.peashooter.api.sonarr; - -import com.github.nekolr.peashooter.api.sonarr.rsp.Queue; -import com.github.nekolr.peashooter.api.sonarr.rsp.Series; -import com.github.nekolr.peashooter.api.sonarr.rsp.Status; - -import java.util.List; - -public interface SonarrApi { - - String GET_QUEUE_LIST_URI = "/api/queue"; - String GET_STATUS_URI = "/api/system/status"; - String GET_SERIES_LIST_URI = "/api/series"; - String GET_SERIES_URI = "/api/series/{0}"; - - Status getStatus(); - - List getQueueList(); - - Series getSeries(String id); - - List getSeriesList(); -} diff --git a/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrV3Api.java b/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrV3Api.java index cb5339d..3886686 100644 --- a/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrV3Api.java +++ b/src/main/java/com/github/nekolr/peashooter/api/sonarr/SonarrV3Api.java @@ -2,10 +2,31 @@ import com.github.nekolr.peashooter.api.sonarr.req.AddRssIndexer; +import com.github.nekolr.peashooter.api.sonarr.rsp.Queue; +import com.github.nekolr.peashooter.api.sonarr.rsp.Series; +import com.github.nekolr.peashooter.api.sonarr.rsp.Status; + +import java.util.List; public interface SonarrV3Api { String ADD_INDEXER_URI = "/api/v3/indexer"; + String GET_STATUS_URI = "/api/v3/system/status"; + + String GET_SERIES_LIST_URI = "/api/v3/series"; + + String GET_SERIES_URI = "/api/v3/series/{0}"; + + String GET_QUEUE_LIST_URI = "/api/queue"; + + List getQueueList(); + Boolean addRssIndexer(AddRssIndexer indexer); + + Status getStatus(); + + List getSeriesList(); + + Series getSeries(String id); } diff --git a/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrClient.java b/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrClient.java deleted file mode 100644 index 86b11ed..0000000 --- a/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrClient.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.github.nekolr.peashooter.api.sonarr.client; - -import com.alibaba.fastjson2.JSON; -import com.github.nekolr.peashooter.api.sonarr.rsp.Series; -import com.github.nekolr.peashooter.config.SettingsManager; -import com.github.nekolr.peashooter.api.sonarr.SonarrApi; -import com.github.nekolr.peashooter.api.sonarr.rsp.Queue; -import com.github.nekolr.peashooter.api.sonarr.rsp.Status; -import jodd.http.HttpException; -import jodd.http.HttpRequest; -import jodd.http.HttpResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.retry.annotation.Backoff; -import org.springframework.retry.annotation.Retryable; -import org.springframework.stereotype.Component; - -import java.text.MessageFormat; -import java.util.List; - -import static com.github.nekolr.peashooter.constant.Peashooter.API_KEY; - -@Slf4j -@Component -@RequiredArgsConstructor -public class SonarrClient implements SonarrApi { - - private final SettingsManager settingsManager; - - @Override - public Status getStatus() { - String apiKey = settingsManager.get().getSonarr().getApiKey(); - HttpRequest request = HttpRequest.get(this.getUrl(GET_STATUS_URI)); - request.query(API_KEY, apiKey); - try { - HttpResponse response = request.send(); - if (response.statusCode() != 200) - return null; - return JSON.parseObject(response.bodyText(), Status.class); - } catch (Exception e) { - log.error("get status error: {}", e.getMessage()); - return null; - } - } - - @Override - public List getQueueList() { - String apiKey = settingsManager.get().getSonarr().getApiKey(); - HttpRequest request = HttpRequest.get(this.getUrl(GET_QUEUE_LIST_URI)); - request.query(API_KEY, apiKey); - HttpResponse response = request.send(); - if (response.statusCode() != 200) - return null; - return JSON.parseArray(response.bodyText(), Queue.class); - } - - @Override - @Retryable(retryFor = HttpException.class, backoff = @Backoff(multiplier = 1.5)) - public Series getSeries(String id) { - String apiKey = settingsManager.get().getSonarr().getApiKey(); - String uri = MessageFormat.format(GET_SERIES_URI, id); - HttpRequest request = HttpRequest.get(this.getUrl(uri)); - request.query(API_KEY, apiKey); - HttpResponse response = request.send(); - if (response.statusCode() != 200) - return null; - return JSON.parseObject(response.bodyText(), Series.class); - } - - @Override - public List getSeriesList() { - String apiKey = settingsManager.get().getSonarr().getApiKey(); - HttpRequest request = HttpRequest.get(this.getUrl(GET_SERIES_LIST_URI)); - request.query(API_KEY, apiKey); - HttpResponse response = request.send(); - if (response.statusCode() != 200) - return null; - return JSON.parseArray(response.bodyText(), Series.class); - } - - private String getUrl(String uri) { - return settingsManager.get().getSonarr().getUrl() + uri; - } -} diff --git a/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrV3Client.java b/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrV3Client.java index 6a74221..5220fa0 100644 --- a/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrV3Client.java +++ b/src/main/java/com/github/nekolr/peashooter/api/sonarr/client/SonarrV3Client.java @@ -1,15 +1,25 @@ package com.github.nekolr.peashooter.api.sonarr.client; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.github.nekolr.peashooter.api.sonarr.SonarrV3Api; import com.github.nekolr.peashooter.api.sonarr.req.AddRssIndexer; +import com.github.nekolr.peashooter.api.sonarr.rsp.Queue; +import com.github.nekolr.peashooter.api.sonarr.rsp.Series; +import com.github.nekolr.peashooter.api.sonarr.rsp.Status; import com.github.nekolr.peashooter.config.SettingsManager; +import jodd.http.HttpException; import jodd.http.HttpRequest; import jodd.http.HttpResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; import org.springframework.stereotype.Component; +import java.text.MessageFormat; +import java.util.List; + import static com.github.nekolr.peashooter.constant.Peashooter.API_KEY; @Slf4j @@ -19,6 +29,18 @@ public class SonarrV3Client implements SonarrV3Api { private final SettingsManager settingsManager; + @Override + public List getQueueList() { + String apiKey = settingsManager.get().getSonarr().getApiKey(); + HttpRequest request = HttpRequest.get(this.getUrl(GET_QUEUE_LIST_URI)); + request.query(API_KEY, apiKey); + HttpResponse response = request.send(); + if (response.statusCode() != 200) + return null; + JSONObject respObj = JSON.parseObject(response.bodyText()); + return JSON.parseArray(respObj.getString("records"), Queue.class); + } + @Override public Boolean addRssIndexer(AddRssIndexer indexer) { String apiKey = settingsManager.get().getSonarr().getApiKey(); @@ -34,6 +56,46 @@ public Boolean addRssIndexer(AddRssIndexer indexer) { } } + @Override + public Status getStatus() { + String apiKey = settingsManager.get().getSonarr().getApiKey(); + HttpRequest request = HttpRequest.get(this.getUrl(GET_STATUS_URI)); + request.query(API_KEY, apiKey); + try { + HttpResponse response = request.send(); + if (response.statusCode() != 200) + return null; + return JSON.parseObject(response.bodyText(), Status.class); + } catch (Exception e) { + log.error("get status error: {}", e.getMessage()); + return null; + } + } + + @Override + public List getSeriesList() { + String apiKey = settingsManager.get().getSonarr().getApiKey(); + HttpRequest request = HttpRequest.get(this.getUrl(GET_SERIES_LIST_URI)); + request.query(API_KEY, apiKey); + HttpResponse response = request.send(); + if (response.statusCode() != 200) + return null; + return JSON.parseArray(response.bodyText(), Series.class); + } + + @Override + @Retryable(retryFor = HttpException.class, backoff = @Backoff(multiplier = 1.5)) + public Series getSeries(String id) { + String apiKey = settingsManager.get().getSonarr().getApiKey(); + String uri = MessageFormat.format(GET_SERIES_URI, id); + HttpRequest request = HttpRequest.get(this.getUrl(uri)); + request.query(API_KEY, apiKey); + HttpResponse response = request.send(); + if (response.statusCode() != 200) + return null; + return JSON.parseObject(response.bodyText(), Series.class); + } + private String getUrl(String uri) { return settingsManager.get().getSonarr().getUrl() + uri; } diff --git a/src/main/java/com/github/nekolr/peashooter/api/sonarr/rsp/Series.java b/src/main/java/com/github/nekolr/peashooter/api/sonarr/rsp/Series.java index 59e73a5..e542740 100644 --- a/src/main/java/com/github/nekolr/peashooter/api/sonarr/rsp/Series.java +++ b/src/main/java/com/github/nekolr/peashooter/api/sonarr/rsp/Series.java @@ -1,6 +1,6 @@ package com.github.nekolr.peashooter.api.sonarr.rsp; -public record Series(String id, String title, Integer seasonCount, Long tvdbId, +public record Series(String id, String title, Long tvdbId, String imdbId, String languageProfileId, String qualityProfileId) { } \ No newline at end of file diff --git a/src/main/java/com/github/nekolr/peashooter/job/rename/RenameTorrentJob.java b/src/main/java/com/github/nekolr/peashooter/job/rename/RenameTorrentJob.java index 151b1f8..f36ff8a 100644 --- a/src/main/java/com/github/nekolr/peashooter/job/rename/RenameTorrentJob.java +++ b/src/main/java/com/github/nekolr/peashooter/job/rename/RenameTorrentJob.java @@ -1,7 +1,7 @@ package com.github.nekolr.peashooter.job.rename; import com.github.nekolr.peashooter.api.qb.QBittorrentApi; -import com.github.nekolr.peashooter.api.sonarr.SonarrApi; +import com.github.nekolr.peashooter.api.sonarr.SonarrV3Api; import com.github.nekolr.peashooter.api.sonarr.rsp.Queue; import com.github.nekolr.peashooter.entity.domain.DownloadInfo; import com.github.nekolr.peashooter.service.IDownloadInfoService; @@ -20,14 +20,14 @@ @RequiredArgsConstructor public class RenameTorrentJob extends QuartzJobBean { - private final SonarrApi sonarrApi; + private final SonarrV3Api sonarrV3Api; private final QBittorrentApi qBittorrentApi; private final IDownloadInfoService downloadInfoService; @Override protected void executeInternal(JobExecutionContext context) { List downloadInfoList = downloadInfoService.findAll(); - List queueList = sonarrApi.getQueueList(); + List queueList = sonarrV3Api.getQueueList(); for (DownloadInfo info : downloadInfoList) { if (!CollectionUtils.isEmpty(queueList)) { for (Queue queue : queueList) { diff --git a/src/main/java/com/github/nekolr/peashooter/rss/convert/RssConvertorImpl.java b/src/main/java/com/github/nekolr/peashooter/rss/convert/RssConvertorImpl.java index bf7241c..476a26e 100644 --- a/src/main/java/com/github/nekolr/peashooter/rss/convert/RssConvertorImpl.java +++ b/src/main/java/com/github/nekolr/peashooter/rss/convert/RssConvertorImpl.java @@ -1,6 +1,6 @@ package com.github.nekolr.peashooter.rss.convert; -import com.github.nekolr.peashooter.api.sonarr.SonarrApi; +import com.github.nekolr.peashooter.api.sonarr.SonarrV3Api; import com.github.nekolr.peashooter.api.sonarr.rsp.Series; import com.github.nekolr.peashooter.config.SettingsManager; import com.github.nekolr.peashooter.constant.Peashooter; @@ -38,7 +38,8 @@ public class RssConvertorImpl implements RssConvertor { private static final String TORRENT_URI_PARAM_TITLE = "title"; private static final String TORRENT_URI_PARAM_EPISODE = "episode"; private static final String TORRENT_URI_PARAM_SEASON = "season"; - private final SonarrApi sonarrApi; + + private final SonarrV3Api sonarrV3Api; private final SettingsManager settingsManager; private Map resolverMap; @@ -78,7 +79,7 @@ public Item convert(SyndEntry entry, ConvertContext ctx) { Item item = null; String epTitle = FeedUtils.getTitle(entry); List matchers = ctx.matchers(); - Series series = sonarrApi.getSeries(ctx.referenceId()); + Series series = sonarrV3Api.getSeries(ctx.referenceId()); if (Objects.isNull(series)) { log.warn("转换分组 {} 失败,Entry Title:{}", ctx.groupId(), epTitle); return null; diff --git a/src/main/java/com/github/nekolr/peashooter/service/impl/SettingsServiceImpl.java b/src/main/java/com/github/nekolr/peashooter/service/impl/SettingsServiceImpl.java index 35bf0ac..da312b6 100644 --- a/src/main/java/com/github/nekolr/peashooter/service/impl/SettingsServiceImpl.java +++ b/src/main/java/com/github/nekolr/peashooter/service/impl/SettingsServiceImpl.java @@ -2,7 +2,7 @@ import com.github.nekolr.peashooter.api.qb.QBittorrentApi; import com.github.nekolr.peashooter.api.qb.rsp.AppVersion; -import com.github.nekolr.peashooter.api.sonarr.SonarrApi; +import com.github.nekolr.peashooter.api.sonarr.SonarrV3Api; import com.github.nekolr.peashooter.api.sonarr.rsp.Status; import com.github.nekolr.peashooter.config.Settings; import com.github.nekolr.peashooter.config.Settings.*; @@ -19,13 +19,13 @@ @RequiredArgsConstructor public class SettingsServiceImpl implements ISettingsService { - private final SonarrApi sonarrApi; + private final SonarrV3Api sonarrV3Api; private final QBittorrentApi qBittorrentApi; private final SettingsManager settingsManager; @Override public boolean testSonarr() { - Status status = sonarrApi.getStatus(); + Status status = sonarrV3Api.getStatus(); return Objects.nonNull(status); } diff --git a/src/main/java/com/github/nekolr/peashooter/service/impl/SonarrServiceImpl.java b/src/main/java/com/github/nekolr/peashooter/service/impl/SonarrServiceImpl.java index ba30d9f..d6776b6 100644 --- a/src/main/java/com/github/nekolr/peashooter/service/impl/SonarrServiceImpl.java +++ b/src/main/java/com/github/nekolr/peashooter/service/impl/SonarrServiceImpl.java @@ -1,6 +1,5 @@ package com.github.nekolr.peashooter.service.impl; -import com.github.nekolr.peashooter.api.sonarr.SonarrApi; import com.github.nekolr.peashooter.api.sonarr.SonarrV3Api; import com.github.nekolr.peashooter.api.sonarr.req.AddRssIndexer; import com.github.nekolr.peashooter.api.sonarr.rsp.Series; @@ -31,7 +30,6 @@ public class SonarrServiceImpl implements ISonarrService { private Map sonarrSeries = new ConcurrentHashMap(); - private final SonarrApi sonarrApi; private final SonarrV3Api sonarrV3Api; private final TheMovieDbApi theMovieDbApi; private final SettingsManager settingsManager; @@ -39,7 +37,7 @@ public class SonarrServiceImpl implements ISonarrService { @Override public List getSeriesNameList() { - List seriesList = sonarrApi.getSeriesList(); + List seriesList = sonarrV3Api.getSeriesList(); if (CollectionUtils.isEmpty(seriesList)) { return Collections.emptyList(); } else { @@ -54,7 +52,7 @@ public List getSeriesNameList() { @Override public List refreshSeriesName() { log.info("开始刷新 sonarr 的剧集中文信息"); - List seriesList = sonarrApi.getSeriesList(); + List seriesList = sonarrV3Api.getSeriesList(); if (CollectionUtils.isEmpty(seriesList)) { log.info("没有获取到 sonarr 的剧集信息"); return Collections.emptyList(); @@ -98,7 +96,7 @@ public List refreshSeriesName() { public void syncSeriesLatest() { final long REFRESH_COUNT = 100; log.info("重新同步 sonarr 最近 {} 部剧集的中文信息", REFRESH_COUNT); - List seriesList = sonarrApi.getSeriesList(); + List seriesList = sonarrV3Api.getSeriesList(); if (CollectionUtils.isEmpty(seriesList)) { log.info("没有获取到 sonarr 的剧集信息"); } else {