Skip to content

Commit

Permalink
feat: add endpoint to get file ids to delete
Browse files Browse the repository at this point in the history
according to the configured file quality preference in the settings.
  • Loading branch information
revam committed Nov 20, 2023
1 parent 2dd60c4 commit 53792a0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Shoko.Server/API/v3/Controllers/WebUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Shoko.Commons.Extensions;
using Shoko.Server.API.Annotations;
using Shoko.Server.API.ModelBinders;
using Shoko.Server.API.v3.Helpers;
using Shoko.Server.API.v3.Models.Common;
using Shoko.Server.API.v3.Models.Shoko;
using Shoko.Server.API.WebUI;
using Shoko.Server.Models;
using Shoko.Server.Repositories;
using Shoko.Server.Settings;
using Shoko.Server.Utilities;
Expand Down Expand Up @@ -277,6 +279,41 @@ public ActionResult<WebUISeriesFileSummary> GetSeriesFileSummary(
return new WebUISeriesFileSummary(series, type, includeEpisodeDetails, includeMissingFutureEpisodes, includeMissingUnknownEpisodes, groupBy);
}


/// <summary>
/// Get the list of file ids to remove according to the file quality
/// preference.
/// </summary>
/// <param name="ignoreVariations">Ignore manually toggled variations in the results.</param>
/// <param name="onlyFinishedSeries">Only show finished series.</param>
/// <returns></returns>
[HttpGet("Episode/WithMultipleFiles/FilesToDelete")]
public ActionResult<List<int>> GetFileIdsWithPreference([FromQuery] bool ignoreVariations = true, [FromQuery] bool onlyFinishedSeries = false)
{
IEnumerable<SVR_AnimeEpisode> enumerable =
RepoFactory.AnimeEpisode.GetEpisodesWithMultipleFiles(ignoreVariations);
if (onlyFinishedSeries)
{
var dictSeriesFinishedAiring = RepoFactory.AnimeSeries.GetAll()
.ToDictionary(a => a.AnimeSeriesID, a => a.GetAnime().GetFinishedAiring());
enumerable = enumerable.Where(episode =>
dictSeriesFinishedAiring.TryGetValue(episode.AnimeSeriesID, out var finishedAiring) && finishedAiring);
}

return enumerable
.SelectMany(episode =>
{
var files = episode.GetVideoLocals();
files.Sort(FileQualityFilter.CompareTo);
return files
.Skip(FileQualityFilter.Settings.MaxNumberOfFilesToKeep)
.Where(file => !FileQualityFilter.CheckFileKeep(file))
.Select(file => file.VideoLocalID);
})
.Distinct()
.ToList();
}

/// <summary>
/// Install a fresh copy of the web ui for the selected
/// <paramref name="channel"/>. Will only install if it detects that no
Expand Down

0 comments on commit 53792a0

Please sign in to comment.