3 Commits

6 changed files with 43 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AssemblyVersion>0.1.1.0</AssemblyVersion>
<AssemblyVersion>0.1.1.1</AssemblyVersion>
</PropertyGroup>
</Project>

View File

@@ -32,7 +32,11 @@ public class StateController(MediaCleanerState state) : Controller
public IActionResult GetMovieInfo() => Ok(_state.GetMovieInfo());
[HttpGet("updateState")]
public IActionResult GetUpdateState() => Ok(_state.UpdateState());
public async Task<IActionResult> GetUpdateState()
{
await _state.UpdateState().ConfigureAwait(false);
return Ok();
}
[HttpGet("getMoviesTitle")]
public IActionResult GetMoviesTitle() =>

View File

@@ -11,28 +11,50 @@ using System.Net.Http;
using System;
using System.Text.Json;
using System.Globalization;
using MediaBrowser.Model.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Plugin.MediaCleaner.Data;
public class MediaCleanerState(ILogger<StaleMediaScanner> logger, ILibraryManager libraryManager)
public class MediaCleanerState(ILogger<StaleMediaScanner> logger, ILibraryManager libraryManager, ITaskManager taskManager)
{
private readonly Lock _lock = new();
private IEnumerable<MediaInfo> _mediaInfo = [];
private readonly StaleMediaScanner _staleMediaScanner = new(logger, libraryManager);
// private readonly ILibraryManager _libraryManager = libraryManager;
private readonly ITaskManager _taskManager = taskManager;
public async Task UpdateState()
{
// First re-scan library and then scan for stale media.
IScheduledTaskWorker? refreshLibraryWorker = _taskManager.ScheduledTasks.FirstOrDefault(task => task.ScheduledTask.Key == "RefreshLibrary");
if(refreshLibraryWorker != null)
{
await _taskManager.Execute(refreshLibraryWorker, new TaskOptions()).ConfigureAwait(false);
}
_mediaInfo = await _staleMediaScanner.ScanStaleMedia().ConfigureAwait(false);
return;
}
public async Task<IEnumerable<SeriesInfo>> GetTvSeriesInfo()
{
// Filter only TV
// Get all series on tv sonarr server
HttpHelper tvHttpHelper = new HttpHelper(ServerType.Sonarr);
var tvSeriesResponse = await tvHttpHelper.SendHttpRequestAsync(HttpMethod.Get,"/api/v3/series").ConfigureAwait(false);
var tvSeries = JsonSerializer.Deserialize<IEnumerable<SonarrSeries>>(tvSeriesResponse.GetRawText());
HttpHelper httpHelper = new HttpHelper(ServerType.Sonarr);
JsonElement tvSeriesResponse = new JsonElement();
try
{
tvSeriesResponse = await httpHelper.SendHttpRequestAsync(HttpMethod.Get,"/api/v3/series").ConfigureAwait(false);
}
catch
{
return [];
}
var tvSeries = JsonSerializer.Deserialize<IEnumerable<SonarrSeries>>(tvSeriesResponse.GetRawText());
if(tvSeries == null)
{
return [];
@@ -53,7 +75,16 @@ public class MediaCleanerState(ILogger<StaleMediaScanner> logger, ILibraryManage
{
// Get all series on anime sonarr server
HttpHelper animeHttpHelper = new HttpHelper(ServerType.SonarrAnime);
var animeSeriesResponse = await animeHttpHelper.SendHttpRequestAsync(HttpMethod.Get,"/api/v3/series").ConfigureAwait(false);
JsonElement animeSeriesResponse = new JsonElement();
try
{
animeSeriesResponse = await animeHttpHelper.SendHttpRequestAsync(HttpMethod.Get,"/api/v3/series").ConfigureAwait(false);
}
catch
{
return [];
}
var animeSeries = JsonSerializer.Deserialize<List<SonarrSeries>>(animeSeriesResponse.GetRawText());
if(animeSeries == null)

View File

@@ -1,12 +1,9 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;
using Jellyfin.Plugin.MediaCleaner.Enums;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.MediaCleaner.Helpers;

View File

@@ -3,7 +3,7 @@
<div data-role="content">
<div class="content-primary">
<link rel="stylesheet" href="/web/configurationpage?name=global.css" />
<div id="loading">Loading...</div>
<div id="loading">Loading... This may take some time whilst we scan your library and retrieve data from Radarr and Sonarr to accurately fill tables.</div>
<div id="homepage" style="visibility: hidden;">
<button class="links" data-target="configurationpage?name=Configuration">Configuration</button>
<h2>Media Cleaner</h2>

View File

@@ -56,8 +56,6 @@ const updateMediaCleanerState = async () => {
if(!response.ok){
throw new Error(`Response status: ${response.status}`)
}
return response.json();
};
const getMediaCleanerAnimeSeriesTitle = async () => {