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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user