1
0
Fork 0

refinements

This commit is contained in:
xeviff 2023-02-23 20:20:55 +01:00
parent 0abb7cfe17
commit 03316dd265
5 changed files with 58 additions and 3 deletions

View File

@ -45,6 +45,7 @@ public class PlexCommandLauncher {
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh); String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh);
if (plexRefreshURL==null) return; if (plexRefreshURL==null) return;
try (CloseableHttpClient httpclient = HttpClients.createDefault()) { try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpUriRequest httpGET = RequestBuilder.get() HttpUriRequest httpGET = RequestBuilder.get()
.setUri(new URI(plexRefreshURL)) .setUri(new URI(plexRefreshURL))
.addParameter("path", plexPathToRefresh) .addParameter("path", plexPathToRefresh)
@ -68,11 +69,13 @@ public class PlexCommandLauncher {
public Document retrieveSectionsInfo() { public Document retrieveSectionsInfo() {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) { try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
String plexSectionsURL = getPlexSectionsURL();
HttpUriRequest httpGET = RequestBuilder.get() HttpUriRequest httpGET = RequestBuilder.get()
.setUri(new URI(getPlexSectionsURL())) .setUri(new URI(plexSectionsURL))
.addParameter("X-Plex-Token", config.getConfig(PLEX_TOKEN)) .addParameter("X-Plex-Token", config.getConfig(PLEX_TOKEN))
.build(); .build();
try (CloseableHttpResponse httpResponse = httpclient.execute(httpGET)) { try (CloseableHttpResponse httpResponse = httpclient.execute(httpGET)) {
final HttpEntity entity = httpResponse.getEntity(); final HttpEntity entity = httpResponse.getEntity();
if (entity != null) { if (entity != null) {
try (InputStream inputStream = entity.getContent()) { try (InputStream inputStream = entity.getContent()) {

View File

@ -8,6 +8,7 @@ import tv.mangrana.utils.rest.APIInterface;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.List;
/** /**
* For more information, visit: <a href="https://radarr.video/docs/api/#/Movie/get_api_v3_movie">...</a> * For more information, visit: <a href="https://radarr.video/docs/api/#/Movie/get_api_v3_movie">...</a>
@ -30,9 +31,20 @@ public interface RadarrAPIInterface extends APIInterface {
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
MovieResource getMovieById(@PathParam("id") int movieId, @QueryParam("apikey") String apikey); MovieResource getMovieById(@PathParam("id") int movieId, @QueryParam("apikey") String apikey);
@GET
@Path("/movie")
@Produces({ MediaType.APPLICATION_JSON })
List<MovieResource> movieLookupByTMDBid(@QueryParam("tmdbId") int tmdbId, @QueryParam("apikey") String apikey);
@POST @POST
@Path("/command") @Path("/command")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
void refreshMoviesCommand(RefreshMoviesCommand command, @QueryParam("apikey") String apikey); void refreshMoviesCommand(RefreshMoviesCommand command, @QueryParam("apikey") String apikey);
@PUT
@Path("/movie/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
void updateMovie(MovieResource movie, @PathParam("id") int movieId, @QueryParam("apikey") String apikey);
} }

View File

@ -6,6 +6,8 @@ import tv.mangrana.radarr.api.schema.movie.MovieResource;
import tv.mangrana.radarr.api.schema.queue.QueueResourcePagingResource; import tv.mangrana.radarr.api.schema.queue.QueueResourcePagingResource;
import tv.mangrana.utils.rest.APIProxyBuilderSingleton; import tv.mangrana.utils.rest.APIProxyBuilderSingleton;
import java.util.List;
import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.RADARR_API_HOST; import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.RADARR_API_HOST;
import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.RADARR_API_KEY; import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.RADARR_API_KEY;
import static tv.mangrana.utils.Output.log; import static tv.mangrana.utils.Output.log;
@ -30,6 +32,10 @@ public class RadarrApiGateway {
return movie; return movie;
} }
public List<MovieResource> movieLookupByTMDBid (int tmdbId) {
return proxy.movieLookupByTMDBid(tmdbId, apiKey);
}
public void removeQueueItem(int itemId) { public void removeQueueItem(int itemId) {
proxy.removeQueueItem(itemId, false, apiKey); proxy.removeQueueItem(itemId, false, apiKey);
log("removed item from queue successfully: "+itemId); log("removed item from queue successfully: "+itemId);
@ -40,4 +46,8 @@ public class RadarrApiGateway {
log("refreshed movie with id "+movieId); log("refreshed movie with id "+movieId);
} }
public void updateMovie(MovieResource movie){
proxy.updateMovie(movie, movie.getId(), apiKey);
}
} }

View File

@ -1,13 +1,14 @@
package tv.mangrana.sonarr.api.client.gateway; package tv.mangrana.sonarr.api.client.gateway;
import tv.mangrana.sonarr.api.schema.history.SonarrHistory;
import tv.mangrana.sonarr.api.schema.series.SonarrSerie;
import tv.mangrana.sonarr.api.schema.command.RefreshSerieCommand; import tv.mangrana.sonarr.api.schema.command.RefreshSerieCommand;
import tv.mangrana.sonarr.api.schema.history.SonarrHistory;
import tv.mangrana.sonarr.api.schema.queue.SonarrQueue; import tv.mangrana.sonarr.api.schema.queue.SonarrQueue;
import tv.mangrana.sonarr.api.schema.series.SonarrSerie;
import tv.mangrana.utils.rest.APIInterface; import tv.mangrana.utils.rest.APIInterface;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.List;
/** /**
* For more information, visit: <a href="https://github.com/Sonarr/Sonarr/wiki/API">official Documentation</a> * For more information, visit: <a href="https://github.com/Sonarr/Sonarr/wiki/API">official Documentation</a>
@ -31,6 +32,11 @@ public interface SonarrAPIInterface extends APIInterface {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
SonarrSerie getSerieById(@PathParam("id") Integer idSerie, @QueryParam("apikey") String apikey); SonarrSerie getSerieById(@PathParam("id") Integer idSerie, @QueryParam("apikey") String apikey);
@GET
@Path("/series")
@Produces({ MediaType.APPLICATION_JSON })
List<SonarrSerie> serieLookupByTVDBid(@QueryParam("tvdbId") int tvdbId, @QueryParam("apikey") String apikey);
@POST @POST
@Path("/command") @Path("/command")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@ -50,4 +56,10 @@ public interface SonarrAPIInterface extends APIInterface {
@QueryParam("pageSize") int pageSize, @QueryParam("page") int page, @QueryParam("pageSize") int pageSize, @QueryParam("page") int page,
@QueryParam("apikey") String apikey); @QueryParam("apikey") String apikey);
@PUT
@Path("/series/{id}")
@Consumes({ MediaType.APPLICATION_JSON })
void updateSerie(SonarrSerie serie, @PathParam("id") int serieId, @QueryParam("apikey") String apikey);
} }

View File

@ -9,6 +9,8 @@ import tv.mangrana.utils.EasyLogger;
import tv.mangrana.utils.Output; import tv.mangrana.utils.Output;
import tv.mangrana.utils.rest.APIProxyBuilderSingleton; import tv.mangrana.utils.rest.APIProxyBuilderSingleton;
import java.util.List;
import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.SONARR_API_HOST; import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.SONARR_API_HOST;
import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.SONARR_API_KEY; import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.SONARR_API_KEY;
@ -44,6 +46,18 @@ public class SonarrApiGateway {
return serie; return serie;
} }
public SonarrSerie getSerieByTvdb(Integer tvDbId) {
SonarrSerie serie = null;
try {
List<SonarrSerie> serieOutput = proxy.serieLookupByTVDBid(tvDbId, apiKey);
serie = serieOutput.get(0);
logger.nLog("retrieved serie from sonarr with tvdbId "+tvDbId);
} catch (Exception e) {
logger.nHLog("Error while getSerieByTvdb: {0}", e.getMessage());
}
return serie;
}
public void refreshSerie(Integer seriesId) { public void refreshSerie(Integer seriesId) {
proxy.refreshSeriesCommand(new RefreshSerieCommand(seriesId), apiKey); proxy.refreshSeriesCommand(new RefreshSerieCommand(seriesId), apiKey);
log("sent Refresh command to Sonarr for the serie with id "+seriesId); log("sent Refresh command to Sonarr for the serie with id "+seriesId);
@ -53,6 +67,10 @@ public class SonarrApiGateway {
return proxy.getHistory("date", "desc", 200, 1, apiKey); return proxy.getHistory("date", "desc", 200, 1, apiKey);
} }
public void updateSerie(SonarrSerie series){
proxy.updateSerie(series, series.getId(), apiKey);
}
private void log (String msg) { private void log (String msg) {
Output.log("SonarrApiGateway: "+msg); Output.log("SonarrApiGateway: "+msg);
} }