Refactored sonarr controller to be able to return anime or tv series based on the media found in the server. Also updated models
This commit is contained in:
@@ -13,13 +13,6 @@ using System.Linq;
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||
|
||||
public record ConnectionTestRequest(string Address, string ApiKey);
|
||||
|
||||
public record RadarrMovie(
|
||||
[property: JsonPropertyName("id")] int? Id,
|
||||
[property: JsonPropertyName("title")] string? Title
|
||||
);
|
||||
|
||||
[Route("radarr")]
|
||||
public class RadarrController : Controller
|
||||
{
|
||||
|
||||
@@ -5,35 +5,15 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Text.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Globalization;
|
||||
using Jellyfin.Plugin.MediaCleaner.Enums;
|
||||
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||
|
||||
public record SonarrSeries(
|
||||
[property: JsonPropertyName("id")] int? Id,
|
||||
[property: JsonPropertyName("title")] string? Title,
|
||||
[property: JsonPropertyName("seasons")] IReadOnlyList<Season> Seasons
|
||||
);
|
||||
|
||||
public record EpisodeDeletionDetails(
|
||||
[property: JsonPropertyName("id")] int? EpisodeId,
|
||||
[property: JsonPropertyName("episodeFileId")] int? EpisodeFileId,
|
||||
[property: JsonPropertyName("seasonNumber")] int? SeasonNumber
|
||||
);
|
||||
|
||||
public record EpisodeIdLists(IReadOnlyList<int> EpisodeIds, IReadOnlyList<int> EpisodeFileIds);
|
||||
|
||||
public record Season(
|
||||
[property: JsonPropertyName("seasonNumber")] int? SeasonNumber
|
||||
);
|
||||
|
||||
[Route("sonarr")]
|
||||
public class SonarrController : Controller
|
||||
{
|
||||
@@ -69,7 +49,7 @@ public class SonarrController : Controller
|
||||
HttpHelper httpHelper = new(ServerType.Sonarr);
|
||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||
HttpMethod.Get,
|
||||
$"/api/v3/episode?seriesId={sonarrSeries.Id?.ToString(CultureInfo.InvariantCulture)}"
|
||||
$"/api/v3/episode?seriesId={sonarrSeries.Id.ToString(CultureInfo.InvariantCulture)}"
|
||||
).ConfigureAwait(false);
|
||||
|
||||
var episodesResponseObj = JsonSerializer.Deserialize<List<EpisodeDeletionDetails>>(responseBody.GetRawText());
|
||||
@@ -122,7 +102,9 @@ public class SonarrController : Controller
|
||||
SonarrSeries staleSeries = new(
|
||||
Id: retrievedSeries.Id,
|
||||
Title: retrievedSeries.Title,
|
||||
Seasons: [.. seriesInfo.Seasons.Select(season => new Season(SeasonNumber: int.Parse(season, CultureInfo.InvariantCulture)))]
|
||||
Seasons: [.. seriesInfo.Seasons.Select(season => new Season(SeasonNumber: int.Parse(season, CultureInfo.InvariantCulture)))],
|
||||
Ended: retrievedSeries.Ended,
|
||||
TvdbId: retrievedSeries.TvdbId
|
||||
);
|
||||
|
||||
var episodesToPurgeResult = await GetSonarrEpisodeInfo(staleSeries).ConfigureAwait(false);
|
||||
|
||||
@@ -2,6 +2,8 @@ using Jellyfin.Plugin.MediaCleaner.Data;
|
||||
using Jellyfin.Plugin.MediaCleaner;
|
||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||
|
||||
@@ -12,8 +14,19 @@ public class StateController(MediaCleanerState state) : Controller
|
||||
private static Configuration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
[HttpGet("getSeriesInfo")]
|
||||
public IActionResult GetSeriesInfo() => Ok(_state.GetSeriesInfo());
|
||||
[HttpGet("getTvSeriesInfo")]
|
||||
public async Task<IActionResult> GetTvSeriesInfo()
|
||||
{
|
||||
var tvSeriesInfo = await _state.GetTvSeriesInfo().ConfigureAwait(false);
|
||||
return Ok(tvSeriesInfo);
|
||||
}
|
||||
|
||||
[HttpGet("getAnimeSeriesInfo")]
|
||||
public async Task<IActionResult> GetAnimeSeriesInfo()
|
||||
{
|
||||
var animeSeriesInfo = await _state.GetAnimeSeriesInfo().ConfigureAwait(false);
|
||||
return Ok(animeSeriesInfo);
|
||||
}
|
||||
|
||||
[HttpGet("getMovieInfo")]
|
||||
public IActionResult GetMovieInfo() => Ok(_state.GetMovieInfo());
|
||||
|
||||
Reference in New Issue
Block a user