Compare commits
51 Commits
v0.0.11-al
...
ddb3433bef
| Author | SHA1 | Date | |
|---|---|---|---|
| ddb3433bef | |||
| 3f5b59b0bd | |||
| b6242de064 | |||
| 2786d6c73d | |||
| 16c8338ffe | |||
| 87bf40dab9 | |||
| a676a8e8ec | |||
| 21a9cc86d8 | |||
| d5b97e0bf3 | |||
| de94fbd7ec | |||
| 98dfd51d3e | |||
| b41979297a | |||
| 8f049e6704 | |||
| 324d48e7cf | |||
| 11c241b149 | |||
| 3f5074aa3b | |||
| 958c581280 | |||
| c94a8b8391 | |||
| fe3b7e412b | |||
| bf40d758fc | |||
| 48d118c56a | |||
| 4bcd89c1a9 | |||
| da94e130ac | |||
| 4642a6c762 | |||
| 1253693ebe | |||
| 80a126fb30 | |||
| be5a58dcf1 | |||
| e6c4939191 | |||
| 9348b33ed6 | |||
| 462a2beea1 | |||
| a720bba7a7 | |||
| 61e868bfa2 | |||
| bc7c95af08 | |||
| 1dfa4f9996 | |||
| b3db9a86f6 | |||
| d6bdfb95c7 | |||
| d73153ad37 | |||
| 1a4d1145b3 | |||
| 629d5d1f2e | |||
| 1bd4935232 | |||
| 984db9e089 | |||
| e77f7dcd5f | |||
| 669f59db15 | |||
| a69f9df4e1 | |||
| e99ce96563 | |||
| 56403b5722 | |||
| ebe24e2630 | |||
| 04ef815a9b | |||
| 66716a9bc9 | |||
| 9bddc59fe2 | |||
| 82441d5247 |
@@ -1,5 +1,5 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AssemblyVersion>0.0.0.9</AssemblyVersion>
|
<AssemblyVersion>0.1.0.0</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -3,30 +3,43 @@ using System.Collections.ObjectModel;
|
|||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Configuration;
|
namespace Jellyfin.Plugin.MediaCleaner;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Plugin configuration.
|
/// Plugin configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PluginConfiguration : BasePluginConfiguration
|
public class Configuration : BasePluginConfiguration
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PluginConfiguration"/> class.
|
/// Gets or sets the http and port address for your Radarr instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PluginConfiguration()
|
public string RadarrAddress { get; set; } = string.Empty;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the api for your Radarr instance.
|
/// Gets or sets the api for your Radarr instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string RadarrAPIKey { get; set; } = string.Empty;
|
public string RadarrAPIKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the http and port address for your Sonarr instance.
|
||||||
|
/// </summary>
|
||||||
|
public string SonarrAddress { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the api for your Sonarr instance.
|
/// Gets or sets the api for your Sonarr instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SonarrAPIKey { get; set; } = string.Empty;
|
public string SonarrAPIKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the http and port address for your Sonarr instance.
|
||||||
|
/// </summary>
|
||||||
|
public string SonarrAnimeAddress { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the api for your Sonarr instance.
|
||||||
|
/// </summary>
|
||||||
|
public string SonarrAnimeAPIKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the cut off days before deleting unwatched files.
|
/// Gets or sets the cut off days before deleting unwatched files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Media Cleaner</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="MediaCleanerConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
|
|
||||||
<div data-role="content">
|
|
||||||
<div class="content-primary">
|
|
||||||
<form id="MediaCleanerConfigForm">
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="RadarrAPIKey">Radarr API Key</label>
|
|
||||||
<input id="RadarrAPIKey" name="RadarrAPIKey" type="text" is="emby-input" />
|
|
||||||
<div class="fieldDescription">The api key used by your radarr instance</div>
|
|
||||||
</div>
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="SonarrAPIKey">Sonarr API Key</label>
|
|
||||||
<input id="SonarrAPIKey" name="SonarrAPIKey" type="text" is="emby-input" />
|
|
||||||
<div class="fieldDescription">The api key used by your sonarr instance</div>
|
|
||||||
</div>
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="StaleMediaCutoff">Stale Media Cutoff</label>
|
|
||||||
<input id="StaleMediaCutoff" name="StaleMediaCutoff" type="number" is="emby-input" style="width: 20%;"/>
|
|
||||||
<div class="fieldDescription">How many days to wait before marking files as stale</div>
|
|
||||||
</div>
|
|
||||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
|
||||||
<label class="emby-checkbox-label">
|
|
||||||
<input id="DebugMode" name="DebugMode" type="checkbox" is="emby-checkbox" />
|
|
||||||
<span>Debug Mode</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<!-- <div class="selectContainer">
|
|
||||||
<label class="selectLabel" for="Options">Several Options</label>
|
|
||||||
<select is="emby-select" id="Options" name="Options" class="emby-select-withcolor emby-select">
|
|
||||||
<option id="optOneOption" value="OneOption">One Option</option>
|
|
||||||
<option id="optAnotherOption" value="AnotherOption">Another Option</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="AnInteger">An Integer</label>
|
|
||||||
<input id="AnInteger" name="AnInteger" type="number" is="emby-input" min="0" />
|
|
||||||
<div class="fieldDescription">A Description</div>
|
|
||||||
</div>
|
|
||||||
<div class="checkboxContainer checkboxContainer-withDescription">
|
|
||||||
<label class="emby-checkbox-label">
|
|
||||||
<input id="TrueFalseSetting" name="TrueFalseCheckBox" type="checkbox" is="emby-checkbox" />
|
|
||||||
<span>A Checkbox</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="inputContainer">
|
|
||||||
<label class="inputLabel inputLabelUnfocused" for="AString">A String</label>
|
|
||||||
<input id="AString" name="AString" type="text" is="emby-input" />
|
|
||||||
<div class="fieldDescription">Another Description</div>
|
|
||||||
</div> -->
|
|
||||||
<div>
|
|
||||||
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
|
||||||
<span>Save</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var MediaCleanerConfig = {
|
|
||||||
pluginUniqueId: 'fef007a8-3e8f-4aa8-a22e-486a387f4192'
|
|
||||||
};
|
|
||||||
|
|
||||||
document.querySelector('#MediaCleanerConfigPage')
|
|
||||||
.addEventListener('pageshow', function() {
|
|
||||||
Dashboard.showLoadingMsg();
|
|
||||||
ApiClient.getPluginConfiguration(MediaCleanerConfig.pluginUniqueId).then(function (config) {
|
|
||||||
// document.querySelector('#Options').value = config.Options;
|
|
||||||
// document.querySelector('#AnInteger').value = config.AnInteger;
|
|
||||||
// document.querySelector('#TrueFalseSetting').checked = config.TrueFalseSetting;
|
|
||||||
// document.querySelector('#AString').value = config.AString;
|
|
||||||
document.querySelector('#RadarrAPIKey').value = config.RadarrAPIKey;
|
|
||||||
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
|
||||||
document.querySelector('#StaleMediaCutoff').value = config.StaleMediaCutoff;
|
|
||||||
document.querySelector('#DebugMode').checked = config.DebugMode;
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
document.querySelector('#MediaCleanerConfigForm')
|
|
||||||
.addEventListener('submit', function(e) {
|
|
||||||
Dashboard.showLoadingMsg();
|
|
||||||
ApiClient.getPluginConfiguration(MediaCleanerConfig.pluginUniqueId).then(function (config) {
|
|
||||||
// config.Options = document.querySelector('#Options').value;
|
|
||||||
// config.AnInteger = document.querySelector('#AnInteger').value;
|
|
||||||
// config.TrueFalseSetting = document.querySelector('#TrueFalseSetting').checked;
|
|
||||||
// config.AString = document.querySelector('#AString').value;
|
|
||||||
config.RadarrAPIKey = document.querySelector('#RadarrAPIKey').value;
|
|
||||||
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
|
||||||
config.StaleMediaCutoff = document.querySelector('#StaleMediaCutoff').value;
|
|
||||||
config.DebugMode = document.querySelector('#DebugMode').checked;
|
|
||||||
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
|
||||||
Dashboard.processPluginConfigurationUpdateResult(result);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
104
Jellyfin.Plugin.MediaCleaner/Controllers/RadarrController.cs
Normal file
104
Jellyfin.Plugin.MediaCleaner/Controllers/RadarrController.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Enums;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||||
|
|
||||||
|
[Route("radarr")]
|
||||||
|
public class RadarrController : Controller
|
||||||
|
{
|
||||||
|
private async Task<ObjectResult> GetRadarrMovieInfo(MovieInfo movieInfo)
|
||||||
|
{
|
||||||
|
HttpHelper httpHelper = new(ServerType.Radarr);
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Get,
|
||||||
|
$"/api/v3/movie?tmdbId={Uri.EscapeDataString(movieInfo.TmdbId ?? string.Empty)}&excludeLocalCovers=false"
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var movies = JsonSerializer.Deserialize<List<RadarrMovie>>(responseBody.GetRawText());
|
||||||
|
var movie = movies?.FirstOrDefault();
|
||||||
|
|
||||||
|
if (movie == null)
|
||||||
|
{
|
||||||
|
return NotFound("Movie not found in Radarr library.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(movie);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("deleteMovieFromRadarr")]
|
||||||
|
public async Task<IActionResult> DeleteMovieFromRadarr([FromBody] MovieInfo movieInfo){
|
||||||
|
|
||||||
|
if (movieInfo == null || string.IsNullOrEmpty(movieInfo.TmdbId))
|
||||||
|
{
|
||||||
|
return BadRequest("Invalid movie information provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var radarrMovieInfoResult = await GetRadarrMovieInfo(movieInfo).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if(radarrMovieInfoResult.StatusCode != StatusCodes.Status200OK || radarrMovieInfoResult.Value is not RadarrMovie){
|
||||||
|
return radarrMovieInfoResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
RadarrMovie movie = (RadarrMovie)radarrMovieInfoResult.Value;
|
||||||
|
|
||||||
|
HttpHelper httpHelper = new(ServerType.Radarr);
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Delete,
|
||||||
|
$"/api/v3/movie/{movie.Id}?deleteFiles=true&addImportExclusion=true"
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
// Radarr typically returns an empty body on successful delete.
|
||||||
|
return Ok(responseBody);
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, $"An unexpected error occurred. {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("testConnection")]
|
||||||
|
public async Task<IActionResult> TestConnection([FromBody] ConnectionTestRequest request)
|
||||||
|
{
|
||||||
|
if (request == null || string.IsNullOrWhiteSpace(request.Address) || string.IsNullOrWhiteSpace(request.ApiKey))
|
||||||
|
{
|
||||||
|
return BadRequest("Address and ApiKey are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var address = request.Address.Trim();
|
||||||
|
if (!address.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!address.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
address = "http://" + address;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var testHttpClient = new HttpClient();
|
||||||
|
using var httpRequest = new HttpRequestMessage(HttpMethod.Get, address);
|
||||||
|
httpRequest.Headers.Add("X-Api-Key", request.ApiKey);
|
||||||
|
|
||||||
|
var response = await testHttpClient.SendAsync(httpRequest).ConfigureAwait(false);
|
||||||
|
return Ok(new { success = response.IsSuccessStatusCode });
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status502BadGateway, e.Message);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
290
Jellyfin.Plugin.MediaCleaner/Controllers/SonarrController.cs
Normal file
290
Jellyfin.Plugin.MediaCleaner/Controllers/SonarrController.cs
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Globalization;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Enums;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||||
|
|
||||||
|
[Route("sonarr")]
|
||||||
|
public class SonarrController : Controller
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
|
public SonarrController(HttpClient httpClient)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
|
||||||
|
// Set the default request headers
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ObjectResult> GetSeriesInfo(SeriesInfo seriesInfo, ServerType serverType){
|
||||||
|
HttpHelper httpHelper = new(serverType);
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Get,
|
||||||
|
$"/api/v3/series?tvdbId={Uri.EscapeDataString(seriesInfo.TvdbId ?? string.Empty)}"
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var seriesResponseObj = JsonSerializer.Deserialize<List<SonarrSeries>>(responseBody.GetRawText());
|
||||||
|
var series = seriesResponseObj?.FirstOrDefault();
|
||||||
|
|
||||||
|
if (series == null)
|
||||||
|
{
|
||||||
|
return NotFound("Series not found in Sonarr library.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(series);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ObjectResult> GetEpisodeInfo(SonarrSeries sonarrSeries, ServerType serverType){
|
||||||
|
HttpHelper httpHelper = new(serverType);
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Get,
|
||||||
|
$"/api/v3/episode?seriesId={sonarrSeries.Id.ToString(CultureInfo.InvariantCulture)}"
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var episodesResponseObj = JsonSerializer.Deserialize<List<EpisodeDeletionDetails>>(responseBody.GetRawText());
|
||||||
|
|
||||||
|
if(episodesResponseObj == null){
|
||||||
|
return NotFound("No episodes in response object.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var seasonNumbers = new HashSet<int>(sonarrSeries.Seasons
|
||||||
|
.Select(s => s.SeasonNumber));
|
||||||
|
|
||||||
|
var staleEpisodesResponseObj = episodesResponseObj
|
||||||
|
.Where(episodeDeletionDetail => seasonNumbers.Contains(episodeDeletionDetail.SeasonNumber))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var episodeIds = staleEpisodesResponseObj
|
||||||
|
.Where(episodeDeletionDetail => episodeDeletionDetail.HasFile)
|
||||||
|
.Select(episodeDeletionDetail => episodeDeletionDetail.EpisodeId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var episodeFileIds = staleEpisodesResponseObj
|
||||||
|
.Where(episodeDeletionDetail => episodeDeletionDetail.HasFile)
|
||||||
|
.Select(episodeDeletionDetail => episodeDeletionDetail.EpisodeFileId)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return Ok(new EpisodeIdLists(episodeIds, episodeFileIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("deleteSeriesFromAnimeSonarr")]
|
||||||
|
public async Task<IActionResult> DeleteSeriesFromAnimeSonarr([FromBody] SeriesInfo seriesInfo){
|
||||||
|
|
||||||
|
if (seriesInfo == null || string.IsNullOrEmpty(seriesInfo.TvdbId))
|
||||||
|
{
|
||||||
|
return BadRequest("Invalid series information provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sonarrSeriesInfoResult = await GetSeriesInfo(seriesInfo, ServerType.SonarrAnime).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if(sonarrSeriesInfoResult.StatusCode != StatusCodes.Status200OK || sonarrSeriesInfoResult.Value is not SonarrSeries){
|
||||||
|
return sonarrSeriesInfoResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
SonarrSeries retrievedSeries = (SonarrSeries)sonarrSeriesInfoResult.Value;
|
||||||
|
SonarrSeries staleSeries = new(
|
||||||
|
Id: retrievedSeries.Id,
|
||||||
|
Title: retrievedSeries.Title,
|
||||||
|
Seasons: [.. seriesInfo.Seasons.Select(season => new Season(SeasonNumber: int.Parse(season, CultureInfo.InvariantCulture)))],
|
||||||
|
Ended: retrievedSeries.Ended,
|
||||||
|
TvdbId: retrievedSeries.TvdbId
|
||||||
|
);
|
||||||
|
|
||||||
|
var episodesToPurgeResult = await GetEpisodeInfo(staleSeries, ServerType.SonarrAnime).ConfigureAwait(false);
|
||||||
|
if (episodesToPurgeResult.StatusCode != StatusCodes.Status200OK || episodesToPurgeResult.Value is not EpisodeIdLists)
|
||||||
|
{
|
||||||
|
return sonarrSeriesInfoResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
EpisodeIdLists episodesToPurge = (EpisodeIdLists)episodesToPurgeResult.Value;
|
||||||
|
|
||||||
|
await UnmonitorSeasons(staleSeries, ServerType.SonarrAnime).ConfigureAwait(false);
|
||||||
|
await UnmonitorEpisodeIds(episodesToPurge.EpisodeIds, ServerType.SonarrAnime).ConfigureAwait(false);
|
||||||
|
await DeleteEpisodeFiles(episodesToPurge.EpisodeFileIds, ServerType.SonarrAnime).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, $"An unexpected error occurred. {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("deleteSeriesFromSonarr")]
|
||||||
|
public async Task<IActionResult> DeleteSeriesFromSonarr([FromBody] SeriesInfo seriesInfo){
|
||||||
|
|
||||||
|
if (seriesInfo == null || string.IsNullOrEmpty(seriesInfo.TvdbId))
|
||||||
|
{
|
||||||
|
return BadRequest("Invalid series information provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sonarrSeriesInfoResult = await GetSeriesInfo(seriesInfo, ServerType.Sonarr).ConfigureAwait(false);
|
||||||
|
|
||||||
|
if(sonarrSeriesInfoResult.StatusCode != StatusCodes.Status200OK || sonarrSeriesInfoResult.Value is not SonarrSeries){
|
||||||
|
return sonarrSeriesInfoResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
SonarrSeries retrievedSeries = (SonarrSeries)sonarrSeriesInfoResult.Value;
|
||||||
|
SonarrSeries staleSeries = new(
|
||||||
|
Id: retrievedSeries.Id,
|
||||||
|
Title: retrievedSeries.Title,
|
||||||
|
Seasons: [.. seriesInfo.Seasons.Select(season => new Season(SeasonNumber: int.Parse(season, CultureInfo.InvariantCulture)))],
|
||||||
|
Ended: retrievedSeries.Ended,
|
||||||
|
TvdbId: retrievedSeries.TvdbId
|
||||||
|
);
|
||||||
|
|
||||||
|
var episodesToPurgeResult = await GetEpisodeInfo(staleSeries, ServerType.Sonarr).ConfigureAwait(false);
|
||||||
|
if (episodesToPurgeResult.StatusCode != StatusCodes.Status200OK || episodesToPurgeResult.Value is not EpisodeIdLists)
|
||||||
|
{
|
||||||
|
return sonarrSeriesInfoResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
EpisodeIdLists episodesToPurge = (EpisodeIdLists)episodesToPurgeResult.Value;
|
||||||
|
|
||||||
|
await UnmonitorSeasons(staleSeries, ServerType.Sonarr).ConfigureAwait(false);
|
||||||
|
await UnmonitorEpisodeIds(episodesToPurge.EpisodeIds, ServerType.Sonarr).ConfigureAwait(false);
|
||||||
|
await DeleteEpisodeFiles(episodesToPurge.EpisodeFileIds, ServerType.Sonarr).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, $"An unexpected error occurred. {e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ObjectResult> UnmonitorSeasons(SonarrSeries staleSeries, ServerType serverType){
|
||||||
|
if (staleSeries == null)
|
||||||
|
{
|
||||||
|
return BadRequest("No stale series provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHelper httpHelper = new(serverType);
|
||||||
|
var series = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Get,
|
||||||
|
$"/api/v3/series/{staleSeries.Id}"
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var seriesDict = JsonSerializer.Deserialize<Dictionary<string, object>>(series.GetRawText());
|
||||||
|
if (seriesDict == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Failed to deserialize season.");
|
||||||
|
}
|
||||||
|
var seasons = series.GetProperty("seasons").EnumerateArray().ToList();
|
||||||
|
|
||||||
|
var staleSeasonNumbers = staleSeries.Seasons
|
||||||
|
.Select(s => s.SeasonNumber)
|
||||||
|
.ToHashSet();
|
||||||
|
|
||||||
|
var updatedSeasons = seasons.Select(season =>
|
||||||
|
{
|
||||||
|
var seasonNumber = season.GetProperty("seasonNumber").GetInt32();
|
||||||
|
|
||||||
|
if (staleSeasonNumbers.Contains(seasonNumber))
|
||||||
|
{
|
||||||
|
var seasonDict = JsonSerializer.Deserialize<Dictionary<string, object>>(season.GetRawText());
|
||||||
|
if (seasonDict == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Failed to deserialize season.");
|
||||||
|
}
|
||||||
|
seasonDict["monitored"] = false;
|
||||||
|
return seasonDict;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonSerializer.Deserialize<Dictionary<string, object>>(season.GetRawText());
|
||||||
|
}).ToArray();
|
||||||
|
|
||||||
|
seriesDict["seasons"] = updatedSeasons;
|
||||||
|
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Put,
|
||||||
|
$"/api/v3/series/{staleSeries.Id}",
|
||||||
|
seriesDict
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ObjectResult> DeleteEpisodeFiles(IReadOnlyList<int> episodeFileIds, ServerType serverType)
|
||||||
|
{
|
||||||
|
if (episodeFileIds == null || episodeFileIds.Count == 0)
|
||||||
|
{
|
||||||
|
return BadRequest("No episode file IDs provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpHelper httpHelper = new(serverType);
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Delete,
|
||||||
|
"/api/v3/episodefile/bulk",
|
||||||
|
new { episodeFileIds }
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ObjectResult> UnmonitorEpisodeIds(IReadOnlyList<int> episodeIds, ServerType serverType)
|
||||||
|
{
|
||||||
|
if (episodeIds == null || episodeIds.Count == 0)
|
||||||
|
{
|
||||||
|
return BadRequest("No episode IDs provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HttpHelper httpHelper = new(serverType);
|
||||||
|
var responseBody = await httpHelper.SendHttpRequestAsync(
|
||||||
|
HttpMethod.Put,
|
||||||
|
"/api/v3/episode/monitor",
|
||||||
|
new { episodeIds, monitored = false }
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("testConnection")]
|
||||||
|
public async Task<IActionResult> TestConnection([FromBody] ConnectionTestRequest request)
|
||||||
|
{
|
||||||
|
if (request == null || string.IsNullOrWhiteSpace(request.Address) || string.IsNullOrWhiteSpace(request.ApiKey))
|
||||||
|
{
|
||||||
|
return BadRequest("Address and ApiKey are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var address = request.Address.Trim();
|
||||||
|
if (!address.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!address.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
address = "http://" + address;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var httpRequest = new HttpRequestMessage(HttpMethod.Get, address);
|
||||||
|
httpRequest.Headers.Add("X-Api-Key", request.ApiKey);
|
||||||
|
|
||||||
|
var response = await _httpClient.SendAsync(httpRequest).ConfigureAwait(false);
|
||||||
|
return Ok(new { success = response.IsSuccessStatusCode });
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status502BadGateway, e.Message);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,48 @@
|
|||||||
using Jellyfin.Plugin.MediaCleaner.Data;
|
using Jellyfin.Plugin.MediaCleaner.Data;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||||
|
|
||||||
[Route("mediacleaner/state")]
|
[Route("mediacleaner/state")]
|
||||||
public class StateController : Controller
|
public class StateController(MediaCleanerState state) : Controller
|
||||||
{
|
{
|
||||||
private readonly PluginState _state;
|
private readonly MediaCleanerState _state = state;
|
||||||
public StateController(PluginState state) => _state = state;
|
private static Configuration Configuration =>
|
||||||
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet("getTvSeriesInfo")]
|
||||||
public IActionResult Get() => Ok(_state.GetSeriesInfo());
|
public async Task<IActionResult> GetTvSeriesInfo()
|
||||||
|
|
||||||
[HttpPost("add")]
|
|
||||||
public IActionResult AddSeriesInfo([FromBody] SeriesInfo seriesInfo)
|
|
||||||
{
|
{
|
||||||
_state.AddSeriesInfo(seriesInfo);
|
var tvSeriesInfo = await _state.GetTvSeriesInfo().ConfigureAwait(false);
|
||||||
return Ok();
|
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());
|
||||||
|
|
||||||
|
[HttpGet("updateState")]
|
||||||
|
public IActionResult GetUpdateState() => Ok(_state.UpdateState());
|
||||||
|
|
||||||
|
[HttpGet("getMoviesTitle")]
|
||||||
|
public IActionResult GetMoviesTitle() =>
|
||||||
|
Ok($"Stale Movies (Unwatched for and created over {Configuration.StaleMediaCutoff} Days ago.)");
|
||||||
|
|
||||||
|
[HttpGet("getSeriesTitle")]
|
||||||
|
public IActionResult GetSeriesTitle() =>
|
||||||
|
Ok($"Stale TV Series (Unwatched for and created over {Configuration.StaleMediaCutoff} Days ago.)");
|
||||||
|
|
||||||
|
[HttpGet("getAnimeSeriesTitle")]
|
||||||
|
public IActionResult GetAnimeSeriesTitle() =>
|
||||||
|
Ok($"Stale Anime Series (Unwatched for and created over {Configuration.StaleMediaCutoff} Days ago.)");
|
||||||
}
|
}
|
||||||
|
|||||||
82
Jellyfin.Plugin.MediaCleaner/Data/MediaCleanerState.cs
Normal file
82
Jellyfin.Plugin.MediaCleaner/Data/MediaCleanerState.cs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner.Enums;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Data;
|
||||||
|
|
||||||
|
public class MediaCleanerState(ILogger<StaleMediaScanner> logger, ILibraryManager libraryManager)
|
||||||
|
{
|
||||||
|
private readonly Lock _lock = new();
|
||||||
|
private IEnumerable<MediaInfo> _mediaInfo = [];
|
||||||
|
private readonly StaleMediaScanner _staleMediaScanner = new(logger, libraryManager);
|
||||||
|
|
||||||
|
public async Task UpdateState()
|
||||||
|
{
|
||||||
|
_mediaInfo = await _staleMediaScanner.ScanStaleMedia().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
if(tvSeries == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
var allSeries = _mediaInfo.OfType<SeriesInfo>();
|
||||||
|
|
||||||
|
var tvSeriesInfo = allSeries
|
||||||
|
.Where(series => tvSeries.Any(tv => tv.TvdbId == int.Parse(series.TvdbId, CultureInfo.InvariantCulture)));
|
||||||
|
|
||||||
|
return [.. tvSeriesInfo];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<SeriesInfo>> GetAnimeSeriesInfo()
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
var animeSeries = JsonSerializer.Deserialize<List<SonarrSeries>>(animeSeriesResponse.GetRawText());
|
||||||
|
|
||||||
|
if(animeSeries == null)
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<SeriesInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
var allSeries = _mediaInfo.OfType<SeriesInfo>();
|
||||||
|
|
||||||
|
var animeSeriesInfo = allSeries
|
||||||
|
.Where(series => animeSeries.Any(anime => anime.TvdbId == int.Parse(series.TvdbId, CultureInfo.InvariantCulture)));
|
||||||
|
|
||||||
|
return animeSeriesInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<MovieInfo> GetMovieInfo()
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
return _mediaInfo.OfType<MovieInfo>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Data;
|
|
||||||
|
|
||||||
public class PluginState
|
|
||||||
{
|
|
||||||
private readonly object _lock = new();
|
|
||||||
private List<SeriesInfo> _seriesInfo = new List<SeriesInfo>
|
|
||||||
{
|
|
||||||
new SeriesInfo { SeriesName = "TestName", Id = System.Guid.NewGuid() }
|
|
||||||
};
|
|
||||||
|
|
||||||
public void AddSeriesInfo(SeriesInfo seriesInfo)
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
_seriesInfo.Add(seriesInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<SeriesInfo> GetSeriesInfo()
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
return _seriesInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8
Jellyfin.Plugin.MediaCleaner/Enums/ServerType.cs
Normal file
8
Jellyfin.Plugin.MediaCleaner/Enums/ServerType.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Enums;
|
||||||
|
|
||||||
|
public enum ServerType
|
||||||
|
{
|
||||||
|
Radarr,
|
||||||
|
Sonarr,
|
||||||
|
SonarrAnime
|
||||||
|
}
|
||||||
77
Jellyfin.Plugin.MediaCleaner/Helpers/HttpHelper.cs
Normal file
77
Jellyfin.Plugin.MediaCleaner/Helpers/HttpHelper.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public class HttpHelper
|
||||||
|
{
|
||||||
|
private string _baseAddress { get; }
|
||||||
|
private HttpClient _httpClient { get; }
|
||||||
|
|
||||||
|
private static Configuration Configuration =>
|
||||||
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
|
public HttpHelper(ServerType serverType)
|
||||||
|
{
|
||||||
|
_httpClient = new HttpClient();
|
||||||
|
|
||||||
|
// Set the default request headers
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", RetrieveApiKey(serverType));
|
||||||
|
|
||||||
|
_baseAddress = RetrieveBaseAddress(serverType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a JSON request and returns the raw JSON element response.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Do NOT create a new HttpClient on every call; reuse one instance (DI or a singleton) to avoid socket exhaustion.
|
||||||
|
/// </remarks>
|
||||||
|
public async Task<JsonElement> SendHttpRequestAsync(HttpMethod method, string path, object? body = null)
|
||||||
|
{
|
||||||
|
var uri = new UriBuilder($"{_baseAddress}{path}").Uri;
|
||||||
|
using var request = new HttpRequestMessage(method, uri);
|
||||||
|
|
||||||
|
if (body != null)
|
||||||
|
{
|
||||||
|
var json = JsonSerializer.Serialize(body);
|
||||||
|
request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await _httpClient.SendAsync(request).ConfigureAwait(false);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
|
return JsonSerializer.Deserialize<JsonElement>(responseBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string RetrieveApiKey(ServerType serverType)
|
||||||
|
{
|
||||||
|
return serverType switch
|
||||||
|
{
|
||||||
|
ServerType.Sonarr => Configuration.SonarrAPIKey,
|
||||||
|
ServerType.SonarrAnime => Configuration.SonarrAnimeAPIKey,
|
||||||
|
ServerType.Radarr => Configuration.RadarrAPIKey,
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private string RetrieveBaseAddress(ServerType serverType)
|
||||||
|
{
|
||||||
|
return serverType switch
|
||||||
|
{
|
||||||
|
ServerType.Sonarr => Configuration.SonarrAddress,
|
||||||
|
ServerType.SonarrAnime => Configuration.SonarrAnimeAddress,
|
||||||
|
ServerType.Radarr => Configuration.RadarrAddress,
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.ScheduledTasks;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
@@ -30,6 +23,6 @@ public class LoggingHelper(ILogger logger)
|
|||||||
_logger.LogInformation(message, args);
|
_logger.LogInformation(message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginConfiguration Configuration =>
|
private static Configuration Configuration =>
|
||||||
Plugin.Instance!.Configuration;
|
Plugin.Instance!.Configuration;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using Jellyfin.Database.Implementations.Entities;
|
using Jellyfin.Database.Implementations.Entities;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
@@ -12,12 +10,15 @@ public class MovieHelper(ILogger logger)
|
|||||||
{
|
{
|
||||||
private readonly LoggingHelper _loggingHelper = new(logger);
|
private readonly LoggingHelper _loggingHelper = new(logger);
|
||||||
|
|
||||||
private static PluginConfiguration Configuration =>
|
private static Configuration Configuration =>
|
||||||
Plugin.Instance!.Configuration;
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
public bool IsMovieStale(BaseItem movie)
|
public bool IsMovieStale(BaseItem movie)
|
||||||
{
|
{
|
||||||
_loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie);
|
ArgumentNullException.ThrowIfNull(movie, "IsMovieStale process recieved a null movie. Logic failure. Exception thrown.");
|
||||||
|
|
||||||
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
|
_loggingHelper.LogDebugInformation("Scanning movie: {Movie}", movie);
|
||||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
|
|
||||||
bool movieIsStale = false;
|
bool movieIsStale = false;
|
||||||
@@ -47,13 +48,20 @@ public class MovieHelper(ILogger logger)
|
|||||||
movieIsStale = true;
|
movieIsStale = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (createdOutsideCutoff)
|
|
||||||
|
if (createdOutsideCutoff && !hasUserData)
|
||||||
{
|
{
|
||||||
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}.", movie.DateCreated);
|
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}.", movie.DateCreated);
|
||||||
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
|
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
|
||||||
movieIsStale = true;
|
movieIsStale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!createdOutsideCutoff && !hasUserData)
|
||||||
|
{
|
||||||
|
_loggingHelper.LogDebugInformation("Movie has no user data and was not created outside of cutoff: {DateCreated}.", movie.DateCreated);
|
||||||
|
_loggingHelper.LogDebugInformation("Movie is not stale.");
|
||||||
|
}
|
||||||
|
|
||||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);
|
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using Jellyfin.Database.Implementations.Entities;
|
using Jellyfin.Database.Implementations.Entities;
|
||||||
using Jellyfin.Database.Implementations.Entities.Libraries;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
@@ -15,7 +12,7 @@ public class SeriesHelper(ILogger logger)
|
|||||||
{
|
{
|
||||||
private readonly LoggingHelper _loggingHelper = new(logger);
|
private readonly LoggingHelper _loggingHelper = new(logger);
|
||||||
|
|
||||||
private static PluginConfiguration Configuration =>
|
private static Configuration Configuration =>
|
||||||
Plugin.Instance!.Configuration;
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
private List<BaseItem> ProcessEpisodes(IReadOnlyCollection<BaseItem> episodes)
|
private List<BaseItem> ProcessEpisodes(IReadOnlyCollection<BaseItem> episodes)
|
||||||
@@ -69,10 +66,7 @@ public class SeriesHelper(ILogger logger)
|
|||||||
|
|
||||||
public bool IsSeasonDataStale(IReadOnlyList<BaseItem> episodes)
|
public bool IsSeasonDataStale(IReadOnlyList<BaseItem> episodes)
|
||||||
{
|
{
|
||||||
if(episodes == null)
|
ArgumentNullException.ThrowIfNull(episodes, "IsSeasonDataStale process recieved null episodes. Logic failure. Exception thrown.");
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(episodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool seasonIsStale = false;
|
bool seasonIsStale = false;
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="Configuration\settings.html" />
|
|
||||||
<EmbeddedResource Include="Configuration\settings.html" />
|
|
||||||
<None Remove="Pages\*" />
|
<None Remove="Pages\*" />
|
||||||
<EmbeddedResource Include="Pages\*" />
|
<EmbeddedResource Include="Pages\*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
public record ConnectionTestRequest(string Address, string ApiKey);
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
public record EpisodeDeletionDetails(
|
||||||
|
[property: JsonPropertyName("id")] int EpisodeId,
|
||||||
|
[property: JsonPropertyName("episodeFileId")] int EpisodeFileId,
|
||||||
|
[property: JsonPropertyName("seasonNumber")] int SeasonNumber,
|
||||||
|
[property: JsonPropertyName("hasFile")] bool HasFile
|
||||||
|
);
|
||||||
5
Jellyfin.Plugin.MediaCleaner/Models/EpisodeIdLists.cs
Normal file
5
Jellyfin.Plugin.MediaCleaner/Models/EpisodeIdLists.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
public record EpisodeIdLists(IReadOnlyList<int> EpisodeIds, IReadOnlyList<int> EpisodeFileIds);
|
||||||
9
Jellyfin.Plugin.MediaCleaner/Models/MediaInfo.cs
Normal file
9
Jellyfin.Plugin.MediaCleaner/Models/MediaInfo.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
public abstract class MediaInfo
|
||||||
|
{
|
||||||
|
public required string TmdbId { get; set; }
|
||||||
|
public required string Name { get; set; }
|
||||||
|
}
|
||||||
14
Jellyfin.Plugin.MediaCleaner/Models/MovieInfo.cs
Normal file
14
Jellyfin.Plugin.MediaCleaner/Models/MovieInfo.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains Movie information.
|
||||||
|
/// </summary>
|
||||||
|
public class MovieInfo : MediaInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
8
Jellyfin.Plugin.MediaCleaner/Models/RadarrMovie.cs
Normal file
8
Jellyfin.Plugin.MediaCleaner/Models/RadarrMovie.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
public record RadarrMovie(
|
||||||
|
[property: JsonPropertyName("id")] int? Id,
|
||||||
|
[property: JsonPropertyName("title")] string? Title
|
||||||
|
);
|
||||||
@@ -1,26 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using Jellyfin.Plugin.MediaCleaner;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains series information.
|
/// Contains series information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SeriesInfo
|
public class SeriesInfo : MediaInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
public Guid SeriesId { get; set; }
|
||||||
/// Gets or sets series identifier.
|
|
||||||
/// </summary>
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets series name.
|
|
||||||
/// </summary>
|
|
||||||
public string SeriesName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets seasons.
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<string> Seasons { get; set; } = [];
|
public IEnumerable<string> Seasons { get; set; } = [];
|
||||||
|
public required string TvdbId { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
18
Jellyfin.Plugin.MediaCleaner/Models/SonarrSeries.cs
Normal file
18
Jellyfin.Plugin.MediaCleaner/Models/SonarrSeries.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
|
|
||||||
|
public record SonarrSeries(
|
||||||
|
[property: JsonPropertyName("id")] int Id,
|
||||||
|
[property: JsonPropertyName("title")] string? Title,
|
||||||
|
[property: JsonPropertyName("seasons")] IReadOnlyList<Season> Seasons,
|
||||||
|
[property: JsonPropertyName("ended")] bool Ended,
|
||||||
|
[property: JsonPropertyName("tvdbId")] int TvdbId
|
||||||
|
// [property: JsonPropertyName("tmdbId")] int TmdbId,
|
||||||
|
// [property: JsonPropertyName("imdbId")] int ImdbId
|
||||||
|
);
|
||||||
|
|
||||||
|
public record Season(
|
||||||
|
[property: JsonPropertyName("seasonNumber")] int SeasonNumber
|
||||||
|
);
|
||||||
94
Jellyfin.Plugin.MediaCleaner/Pages/configuration.html
Normal file
94
Jellyfin.Plugin.MediaCleaner/Pages/configuration.html
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<div id="MediaCleanerConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox" data-controller="__plugin/configuration.js">
|
||||||
|
<div data-role="content">
|
||||||
|
<div class="content-primary">
|
||||||
|
<link rel="stylesheet" href="/web/configurationpage?name=global.css" />
|
||||||
|
<form id="MediaCleanerConfigForm">
|
||||||
|
<h2>Media Cleaner Configuration</h2>
|
||||||
|
|
||||||
|
<h3>Management Configuration</h3>
|
||||||
|
|
||||||
|
<div class="inlineContainer">
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="RadarrAddress">Radarr Address (http:port)</label>
|
||||||
|
<input id="RadarrAddress" name="RadarrAddress" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The address and port of your radarr instance.</div>
|
||||||
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="RadarrAPIKey">Radarr API Key</label>
|
||||||
|
<input id="RadarrAPIKey" name="RadarrAPIKey" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The api key used by your radarr instance</div>
|
||||||
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<button id="RadarrTestConnectionButton" is="emby-button" type="button" class="raised button-submit block emby-button">
|
||||||
|
<span>Test</span>
|
||||||
|
</button>
|
||||||
|
<div class="validation" id="RadarrConnectionValidation" hidden>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inlineContainer">
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="SonarrAddress">Sonarr Address (http:port)</label>
|
||||||
|
<input id="SonarrAddress" name="SonarrAddress" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The address and port of your sonarr instance.</div>
|
||||||
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="SonarrAPIKey">Sonarr API Key</label>
|
||||||
|
<input id="SonarrAPIKey" name="SonarrAPIKey" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The api key used by your sonarr instance</div>
|
||||||
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<button id="SonarrTestConnectionButton" is="emby-button" type="button" class="raised button-submit block emby-button">
|
||||||
|
<span>Test</span>
|
||||||
|
</button>
|
||||||
|
<div class="validation" id="SonarrConnectionValidation" hidden>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inlineContainer">
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="SonarrAnimeAddress">Sonarr Anime Address (http:port)</label>
|
||||||
|
<input id="SonarrAnimeAddress" name="SonarrAnimeAddress" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The address and port of your sonarr instance.</div>
|
||||||
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="SonarrAnimeAPIKey">Sonarr Anime API Key</label>
|
||||||
|
<input id="SonarrAnimeAPIKey" name="SonarrAnimeAPIKey" type="text" is="emby-input" />
|
||||||
|
<div class="fieldDescription">The api key used by your sonarr instance</div>
|
||||||
|
</div>
|
||||||
|
<div class="inputContainer">
|
||||||
|
<button id="SonarrAnimeTestConnectionButton" is="emby-button" type="button" class="raised button-submit block emby-button">
|
||||||
|
<span>Test</span>
|
||||||
|
</button>
|
||||||
|
<div class="validation" id="SonarrAnimeConnectionValidation" hidden>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>General Settings</h3>
|
||||||
|
<div class="inlineContainer">
|
||||||
|
<div class="inputContainer">
|
||||||
|
<label class="inputLabel inputLabelUnfocused" for="StaleMediaCutoff">Stale Media Cutoff</label>
|
||||||
|
<input id="StaleMediaCutoff" class="medium-width" name="StaleMediaCutoff" type="number" is="emby-input"/>
|
||||||
|
<div class="fieldDescription">How many days to wait before marking files as stale</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="checkboxContainer checkboxContainer-withDescription">
|
||||||
|
<label class="emby-checkbox-label">
|
||||||
|
<input id="DebugMode" name="DebugMode" type="checkbox" is="emby-checkbox" />
|
||||||
|
<span>Debug Mode</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
|
||||||
|
<span>Save</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
180
Jellyfin.Plugin.MediaCleaner/Pages/configuration.js
Normal file
180
Jellyfin.Plugin.MediaCleaner/Pages/configuration.js
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
// Variables
|
||||||
|
var MediaCleanerConfig = {
|
||||||
|
pluginUniqueId: 'fef007a8-3e8f-4aa8-a22e-486a387f4192'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fades
|
||||||
|
const startFadeOut = (element, interval = 100) => {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
let currentOpacity = parseFloat(getComputedStyle(element).opacity);
|
||||||
|
if (isNaN(currentOpacity)) currentOpacity = 1;
|
||||||
|
if (currentOpacity > 0) {
|
||||||
|
currentOpacity = Math.max(0, currentOpacity - 0.05);
|
||||||
|
element.style.opacity = currentOpacity.toString();
|
||||||
|
} else {
|
||||||
|
clearInterval(timer);
|
||||||
|
element.setAttribute('hidden', '');
|
||||||
|
}
|
||||||
|
}, interval);
|
||||||
|
};
|
||||||
|
|
||||||
|
const startFadeIn = (element, interval = 100) => {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
let currentOpacity = parseFloat(getComputedStyle(element).opacity);
|
||||||
|
if (isNaN(currentOpacity)) currentOpacity = 0;
|
||||||
|
if (currentOpacity < 1) {
|
||||||
|
currentOpacity = Math.max(0, currentOpacity + 0.05);
|
||||||
|
element.style.opacity = currentOpacity.toString();
|
||||||
|
} else {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
}, interval);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Connection Methods
|
||||||
|
const testConnectionSonarrAnime = async () => {
|
||||||
|
var apiKeyElement = document.getElementById('SonarrAnimeAPIKey');
|
||||||
|
var addressElement = document.getElementById('SonarrAnimeAddress');
|
||||||
|
var validationElement = document.getElementById('SonarrAnimeConnectionValidation');
|
||||||
|
|
||||||
|
await validateConnection(apiKeyElement, addressElement, validationElement, "sonarr");
|
||||||
|
}
|
||||||
|
|
||||||
|
const testConnectionSonarr = async () => {
|
||||||
|
var apiKeyElement = document.getElementById('SonarrAPIKey');
|
||||||
|
var addressElement = document.getElementById('SonarrAddress');
|
||||||
|
var validationElement = document.getElementById('SonarrConnectionValidation');
|
||||||
|
|
||||||
|
await validateConnection(apiKeyElement, addressElement, validationElement, "sonarr");
|
||||||
|
}
|
||||||
|
|
||||||
|
const testConnectionRadarr = async () => {
|
||||||
|
var apiKeyElement = document.getElementById('RadarrAPIKey');
|
||||||
|
var addressElement = document.getElementById('RadarrAddress');
|
||||||
|
var validationElement = document.getElementById('RadarrConnectionValidation');
|
||||||
|
|
||||||
|
await validateConnection(apiKeyElement, addressElement, validationElement, "radarr");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation and Normalization
|
||||||
|
const normalizeUrl = (url) => {
|
||||||
|
let normalizedUrl = url.trim();
|
||||||
|
if (!/^https?:\/\//i.test(normalizedUrl)) {
|
||||||
|
normalizedUrl = 'http://' + normalizedUrl;
|
||||||
|
}
|
||||||
|
return normalizedUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
const validateConnection = async (apiKeyElement, addressElement, validationElement, controller) => {
|
||||||
|
var httpAddress = addressElement.value;
|
||||||
|
var apiKey = apiKeyElement.value;
|
||||||
|
|
||||||
|
console.log("Address: ", httpAddress);
|
||||||
|
console.log("Api Key: ", apiKey);
|
||||||
|
|
||||||
|
// Only valid with characters
|
||||||
|
const validHttp = httpAddress.trim().length > 0;
|
||||||
|
const validApiKey = apiKey.trim().length > 0;
|
||||||
|
|
||||||
|
console.log("Valid Http: ", validHttp);
|
||||||
|
console.log("Valid Api: ", validApiKey);
|
||||||
|
|
||||||
|
var success = false;
|
||||||
|
|
||||||
|
if(validHttp && validApiKey){
|
||||||
|
setAttemptingConnection(validationElement);
|
||||||
|
try{
|
||||||
|
const url = normalizeUrl(httpAddress);
|
||||||
|
// Move endpoint to a constant?
|
||||||
|
const response = await fetch(`/${controller}/testConnection`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ address: url, apiKey })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
success = result?.success === true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error){
|
||||||
|
console.error(`Error: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processValidationElement(validationElement, success);
|
||||||
|
}
|
||||||
|
|
||||||
|
const setAttemptingConnection = (validationElement) => {
|
||||||
|
validationElement.removeAttribute('hidden');
|
||||||
|
validationElement.style.opacity = '0';
|
||||||
|
|
||||||
|
validationElement.style.color = 'Yellow';
|
||||||
|
validationElement.innerText = "Attempting Connection..."
|
||||||
|
setTimeout(startFadeIn(validationElement, 50));
|
||||||
|
}
|
||||||
|
|
||||||
|
const processValidationElement = (validationElement, success) => {
|
||||||
|
validationElement.removeAttribute('hidden');
|
||||||
|
validationElement.style.opacity = '1';
|
||||||
|
|
||||||
|
if(success){
|
||||||
|
validationElement.style.color = 'Green';
|
||||||
|
validationElement.innerText = "Successful Connection!"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
validationElement.style.color = 'Red';
|
||||||
|
validationElement.innerText = "Failed Connection!"
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => startFadeOut(validationElement, 50), 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
document.querySelector('#RadarrTestConnectionButton')
|
||||||
|
.addEventListener('click', testConnectionRadarr);
|
||||||
|
|
||||||
|
document.querySelector('#SonarrTestConnectionButton')
|
||||||
|
.addEventListener('click', testConnectionSonarr);
|
||||||
|
|
||||||
|
document.querySelector('#SonarrAnimeTestConnectionButton')
|
||||||
|
.addEventListener('click', testConnectionSonarrAnime);
|
||||||
|
|
||||||
|
document.querySelector('#MediaCleanerConfigPage')
|
||||||
|
.addEventListener('pageshow', function() {
|
||||||
|
Dashboard.showLoadingMsg();
|
||||||
|
ApiClient.getPluginConfiguration(MediaCleanerConfig.pluginUniqueId).then(function (config) {
|
||||||
|
document.querySelector('#RadarrAPIKey').value = config.RadarrAPIKey;
|
||||||
|
document.querySelector('#RadarrAddress').value = config.RadarrAddress;
|
||||||
|
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
||||||
|
document.querySelector('#SonarrAddress').value = config.SonarrAddress;
|
||||||
|
document.querySelector('#SonarrAnimeAPIKey').value = config.SonarrAnimeAPIKey;
|
||||||
|
document.querySelector('#SonarrAnimeAddress').value = config.SonarrAnimeAddress;
|
||||||
|
document.querySelector('#StaleMediaCutoff').value = config.StaleMediaCutoff;
|
||||||
|
document.querySelector('#DebugMode').checked = config.DebugMode;
|
||||||
|
Dashboard.hideLoadingMsg();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#MediaCleanerConfigForm')
|
||||||
|
.addEventListener('submit', function(e) {
|
||||||
|
Dashboard.showLoadingMsg();
|
||||||
|
ApiClient.getPluginConfiguration(MediaCleanerConfig.pluginUniqueId).then(function (config) {
|
||||||
|
config.RadarrAPIKey = document.querySelector('#RadarrAPIKey').value;
|
||||||
|
config.RadarrAddress = document.querySelector('#RadarrAddress').value;
|
||||||
|
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
||||||
|
config.SonarrAddress = document.querySelector('#SonarrAddress').value;
|
||||||
|
config.SonarrAnimeAPIKey = document.querySelector('#SonarrAnimeAPIKey').value;
|
||||||
|
config.SonarrAnimeAddress = document.querySelector('#SonarrAnimeAddress').value;
|
||||||
|
config.StaleMediaCutoff = document.querySelector('#StaleMediaCutoff').value;
|
||||||
|
config.DebugMode = document.querySelector('#DebugMode').checked;
|
||||||
|
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
||||||
|
Dashboard.processPluginConfigurationUpdateResult(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
91
Jellyfin.Plugin.MediaCleaner/Pages/global.css
Normal file
91
Jellyfin.Plugin.MediaCleaner/Pages/global.css
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
.content-primary > * {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inlineContainer {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-direction: column;
|
||||||
|
/* Would be nice to figure out why 50% doesn't work. */
|
||||||
|
width: 49%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inlineContainer > * {
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border: 1px solid;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 1px solid;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-text {
|
||||||
|
font-size: large;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Custom emby checkbox for table */
|
||||||
|
.table-checkbox {
|
||||||
|
padding-left: 1.05rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-checkbox .checkboxContainer .emby-checkbox-label .checkboxOutline {
|
||||||
|
height: 1.5em;
|
||||||
|
width: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-checkbox .checkboxContainer .emby-checkbox-label {
|
||||||
|
height: 1.8em
|
||||||
|
}
|
||||||
|
|
||||||
|
.links {
|
||||||
|
background-color: #0f0f0f;
|
||||||
|
border: 1px solid #00a4dc;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
padding: 0.8rem 1.8rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
color: #ffffff;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: inherit;
|
||||||
|
vertical-align: baseline;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links:hover {
|
||||||
|
background-color: #2a2a2a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions-cell {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation {
|
||||||
|
border: 1px solid;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
margin-top: 1rem;
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: 1rem;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.max-width{
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.medium-width {
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.small-width {
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.xsmall-width {
|
||||||
|
width: 10%;
|
||||||
|
}
|
||||||
@@ -1,21 +1,53 @@
|
|||||||
<div data-role="page" class="page type-interior pluginConfigurationPage withTabs"
|
<div data-role="page" class="page type-interior pluginConfigurationPage"
|
||||||
data-controller="__plugin/media_cleaner_table.js">
|
data-controller="__plugin/home.js">
|
||||||
<div data-role="content">
|
<div data-role="content">
|
||||||
<div class="content-primary">
|
<div class="content-primary">
|
||||||
<div>
|
<link rel="stylesheet" href="/web/configurationpage?name=global.css" />
|
||||||
<a href="#configurationpage?name=Home">Home</a>
|
<div id="loading">Loading...</div>
|
||||||
<a href="#configurationpage?name=Settings">Settings</a>
|
<div id="homepage" style="visibility: hidden;">
|
||||||
</div>
|
<button class="links" data-target="configurationpage?name=Configuration">Configuration</button>
|
||||||
<h2>Media Cleaner</h2>
|
<h2>Media Cleaner</h2>
|
||||||
<table id="seriesTable">
|
|
||||||
|
<h3 id="moviesTitle"></h3>
|
||||||
|
<table id="moviesTable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>Name</th>
|
||||||
<th>Series Name</th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<button id="moviesDeleteButton" class="delete-button raised button-submit emby-button" style="visibility: hidden;">Delete</button>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3 id="seriesTitle"></h3>
|
||||||
|
<table id="seriesTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Seasons</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
<button id="seriesDeleteButton" class="delete-button raised button-submit emby-button" style="visibility: hidden;">Delete</button>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<h3 id="animeSeriesTitle"></h3>
|
||||||
|
<table id="animeSeriesTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Seasons</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
<button id="animeSeriesDeleteButton" class="delete-button raised button-submit emby-button" style="visibility: hidden;">Delete</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
327
Jellyfin.Plugin.MediaCleaner/Pages/home.js
Normal file
327
Jellyfin.Plugin.MediaCleaner/Pages/home.js
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
document.addEventListener('pageshow', async () => {
|
||||||
|
await refreshFrontEnd();
|
||||||
|
});
|
||||||
|
|
||||||
|
const refreshFrontEnd = async () => {
|
||||||
|
startLoading();
|
||||||
|
await updateMediaCleanerState();
|
||||||
|
|
||||||
|
var moviesTitle = document.getElementById("moviesTitle");
|
||||||
|
var seriesTitle = document.getElementById("seriesTitle");
|
||||||
|
var animeSeriesTitle = document.getElementById("animeSeriesTitle");
|
||||||
|
|
||||||
|
moviesTitle.innerHTML = await getMediaCleanerMoviesTitle();
|
||||||
|
seriesTitle.innerHTML = await getMediaCleanerSeriesTitle();
|
||||||
|
animeSeriesTitle.innerHTML = await getMediaCleanerAnimeSeriesTitle();
|
||||||
|
|
||||||
|
await populateTables();
|
||||||
|
addClickHandlersToLinks();
|
||||||
|
addClickHandlersToDeleteButtons();
|
||||||
|
finishLoading();
|
||||||
|
}
|
||||||
|
|
||||||
|
const getMediaCleanerTvSeriesInfo = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/getTvSeriesInfo");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMediaCleanerAnimeSeriesInfo = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/getAnimeSeriesInfo");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMediaCleanerMovieInfo = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/getMovieInfo");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateMediaCleanerState = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/updateState");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMediaCleanerAnimeSeriesTitle = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/getAnimeSeriesTitle");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMediaCleanerSeriesTitle = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/getSeriesTitle");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getMediaCleanerMoviesTitle = async () => {
|
||||||
|
const response = await fetch("/mediacleaner/state/getMoviesTitle");
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const populateTables = async () => {
|
||||||
|
var moviesInfo = await getMediaCleanerMovieInfo();
|
||||||
|
var seriesInfo = await getMediaCleanerTvSeriesInfo();
|
||||||
|
var animeSeriesInfo = await getMediaCleanerAnimeSeriesInfo();
|
||||||
|
|
||||||
|
var seriesTable = document.getElementById("seriesTable");
|
||||||
|
var moviesTable = document.getElementById("moviesTable");
|
||||||
|
var animeSeriesTable = document.getElementById("animeSeriesTable");
|
||||||
|
|
||||||
|
var seriesTableBody = seriesTable.getElementsByTagName('tbody')[0];
|
||||||
|
seriesTableBody.replaceChildren();
|
||||||
|
var seriesDeleteButton = document.getElementById('seriesDeleteButton');
|
||||||
|
|
||||||
|
var moviesTableBody = moviesTable.getElementsByTagName('tbody')[0];
|
||||||
|
moviesTableBody.replaceChildren();
|
||||||
|
var moviesDeleteButton = document.getElementById('moviesDeleteButton');
|
||||||
|
|
||||||
|
var animeSeriesTableBody = animeSeriesTable.getElementsByTagName('tbody')[0];
|
||||||
|
animeSeriesTableBody.replaceChildren();
|
||||||
|
var animeSeriesDeleteButton = document.getElementById('animeSeriesDeleteButton');
|
||||||
|
|
||||||
|
if (moviesInfo.length > 0){
|
||||||
|
for(let i = 0; i < moviesInfo.length; i++){
|
||||||
|
var row = moviesTableBody.insertRow(-1);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
var cell2 = row.insertCell(1);
|
||||||
|
cell1.innerHTML = moviesInfo[i].Name;
|
||||||
|
cell1.className = "table-text";
|
||||||
|
cell2.appendChild(createCheckbox(moviesInfo[i], moviesTable, moviesDeleteButton));
|
||||||
|
cell2.className = "table-checkbox"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var columnCount = moviesTable.tHead.rows[0].cells.length;
|
||||||
|
var row = moviesTableBody.insertRow(-1);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
cell1.colSpan = columnCount;
|
||||||
|
cell1.innerHTML = "No stale movies found.";
|
||||||
|
cell1.className = "table-text";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(seriesInfo.length > 0){
|
||||||
|
for(let i = 0; i < seriesInfo.length; i++){
|
||||||
|
var row = seriesTableBody.insertRow(-1);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
var cell2 = row.insertCell(1);
|
||||||
|
var cell3 = row.insertCell(2);
|
||||||
|
cell1.innerHTML = seriesInfo[i].Name;
|
||||||
|
cell1.className = "table-text";
|
||||||
|
cell2.innerHTML = seriesInfo[i].Seasons.map(season => season).join(", ");
|
||||||
|
cell2.className = "table-text";
|
||||||
|
cell3.appendChild(createCheckbox(seriesInfo[i], seriesTable, seriesDeleteButton));
|
||||||
|
cell3.className = "table-checkbox"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var columnCount = seriesTable.tHead.rows[0].cells.length;
|
||||||
|
var row = seriesTableBody.insertRow(-1);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
cell1.colSpan = columnCount;
|
||||||
|
cell1.innerHTML = "No stale tv series found.";
|
||||||
|
cell1.className = "table-text";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(animeSeriesInfo.length > 0){
|
||||||
|
for(let i = 0; i < animeSeriesInfo.length; i++){
|
||||||
|
var row = animeSeriesTableBody.insertRow(-1);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
var cell2 = row.insertCell(1);
|
||||||
|
var cell3 = row.insertCell(2);
|
||||||
|
cell1.innerHTML = animeSeriesInfo[i].Name;
|
||||||
|
cell1.className = "table-text";
|
||||||
|
cell2.innerHTML = animeSeriesInfo[i].Seasons.map(season => season).join(", ");
|
||||||
|
cell2.className = "table-text";
|
||||||
|
cell3.appendChild(createCheckbox(animeSeriesInfo[i], animeSeriesTable, animeSeriesDeleteButton));
|
||||||
|
cell3.className = "table-checkbox"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var columnCount = animeSeriesTable.tHead.rows[0].cells.length;
|
||||||
|
var row = animeSeriesTableBody.insertRow(-1);
|
||||||
|
var cell1 = row.insertCell(0);
|
||||||
|
cell1.colSpan = columnCount;
|
||||||
|
cell1.innerHTML = "No stale anime series found.";
|
||||||
|
cell1.className = "table-text";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const createCheckbox = (mediaInfo = {}, table, deleteButton) => {
|
||||||
|
const container = document.createElement('div');
|
||||||
|
container.className = 'checkboxContainer';
|
||||||
|
container.style.marginBottom = 0;
|
||||||
|
|
||||||
|
const label = document.createElement('label');
|
||||||
|
label.className = 'emby-checkbox-label';
|
||||||
|
label.style.textAlign = 'center';
|
||||||
|
label.style.paddingLeft = '1.8em';
|
||||||
|
|
||||||
|
const checkbox = document.createElement('input');
|
||||||
|
checkbox.type = 'checkbox';
|
||||||
|
checkbox.setAttribute('is', 'emby-checkbox');
|
||||||
|
checkbox.dataset.mediaInfo = JSON.stringify(mediaInfo) || '';
|
||||||
|
|
||||||
|
const span = document.createElement('span');
|
||||||
|
span.textContent = '';
|
||||||
|
|
||||||
|
label.appendChild(checkbox);
|
||||||
|
label.appendChild(span);
|
||||||
|
container.appendChild(label);
|
||||||
|
|
||||||
|
checkbox.addEventListener('change', (e) => {
|
||||||
|
if(isDeleteButtonVisible(table)){
|
||||||
|
deleteButton.style.visibility = 'visible';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
deleteButton.style.visibility = 'hidden';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return container;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isDeleteButtonVisible = (table) => {
|
||||||
|
const checkboxes = table.getElementsByClassName('emby-checkbox');
|
||||||
|
const hasChecked = Array.from(checkboxes).some(checkbox => checkbox.checked);
|
||||||
|
return hasChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
const addClickHandlersToLinks = () => {
|
||||||
|
const linkBtns = document.querySelectorAll("button.links");
|
||||||
|
linkBtns.forEach(btn => {
|
||||||
|
btn.addEventListener("click", () => {
|
||||||
|
const target = btn.dataset.target;
|
||||||
|
if (!target) return;
|
||||||
|
window.location.hash = target;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const addClickHandlersToDeleteButtons = () => {
|
||||||
|
const deleteMoviesButtonElement = document.getElementById("moviesDeleteButton");
|
||||||
|
const deleteSeriesButtonElement = document.getElementById("seriesDeleteButton");
|
||||||
|
const deleteAnimeSeriesButtonElement = document.getElementById("animeSeriesDeleteButton");
|
||||||
|
deleteMoviesButtonElement.addEventListener("click", deleteFromRadarr);
|
||||||
|
deleteSeriesButtonElement.addEventListener("click", deleteFromSonarr);
|
||||||
|
deleteAnimeSeriesButtonElement.addEventListener("click", deleteFromAnimeSonarr);
|
||||||
|
}
|
||||||
|
|
||||||
|
const getCheckedMedia = (table) => {
|
||||||
|
const checkboxes = table.getElementsByClassName('emby-checkbox');
|
||||||
|
const selectedMediaCheckboxes = Array.from(checkboxes).filter(checkbox => checkbox.checked);
|
||||||
|
const selectedMedia = selectedMediaCheckboxes.map(selectedMediaCheckbox => JSON.parse(selectedMediaCheckbox.dataset.mediaInfo));
|
||||||
|
console.log("Selected media: ", selectedMedia);
|
||||||
|
return selectedMedia;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteMovieFromRadarrApi = async (movie) => {
|
||||||
|
const response = await fetch("/radarr/deleteMovieFromRadarr", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(movie)
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteSeriesFromSonarrApi = async (series) => {
|
||||||
|
const response = await fetch("/sonarr/deleteSeriesFromSonarr", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(series)
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteSeriesFromAnimeSonarrApi = async (series) => {
|
||||||
|
const response = await fetch("/sonarr/deleteSeriesFromAnimeSonarr", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(series)
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!response.ok){
|
||||||
|
throw new Error(`Response status: ${response.status}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteFromRadarr = async () => {
|
||||||
|
const selectedMovies = getCheckedMedia(moviesTable);
|
||||||
|
selectedMovies.forEach(async movie => await deleteMovieFromRadarrApi(movie));
|
||||||
|
refreshFrontEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteFromSonarr = () => {
|
||||||
|
const selectedSeries = getCheckedMedia(seriesTable);
|
||||||
|
selectedSeries.forEach(async series => await deleteSeriesFromSonarrApi(series));
|
||||||
|
refreshFrontEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteFromAnimeSonarr = () => {
|
||||||
|
const selectedSeries = getCheckedMedia(animeSeriesTable);
|
||||||
|
selectedSeries.forEach(async series => await deleteSeriesFromAnimeSonarrApi(series));
|
||||||
|
refreshFrontEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
const finishLoading = () => {
|
||||||
|
const loadingElement = document.getElementById("loading");
|
||||||
|
const homepage = document.getElementById("homepage");
|
||||||
|
loadingElement.style.visibility = "hidden";
|
||||||
|
homepage.style.visibility = "visible";
|
||||||
|
}
|
||||||
|
|
||||||
|
const startLoading = () => {
|
||||||
|
const loadingElement = document.getElementById("loading");
|
||||||
|
const homepage = document.getElementById("homepage");
|
||||||
|
const moviesDeleteButton = document.getElementById('moviesDeleteButton');
|
||||||
|
const seriesDeleteButton = document.getElementById('seriesDeleteButton');
|
||||||
|
|
||||||
|
loadingElement.style.visibility = "visible";
|
||||||
|
homepage.style.visibility = "hidden";
|
||||||
|
moviesDeleteButton.style.visibility = "hidden";
|
||||||
|
seriesDeleteButton.style.visibility = "hidden";
|
||||||
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
var table = document.getElementById("seriesTable");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getMediaCleanerState = async () => {
|
|
||||||
const response = await fetch('/mediacleaner/state');
|
|
||||||
|
|
||||||
if(!response.ok){
|
|
||||||
throw new Error(`Response status: ${response.status}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
var state = await getMediaCleanerState();
|
|
||||||
|
|
||||||
console.log("State: ", state);
|
|
||||||
|
|
||||||
for(let i = 0; i < state.length; i++){
|
|
||||||
var row = table.insertRow(-1);
|
|
||||||
var cell1 = row.insertCell(0);
|
|
||||||
var cell2 = row.insertCell(1);
|
|
||||||
var cell3 = row.insertCell(2);
|
|
||||||
cell1.innerHTML = state[i].Id;
|
|
||||||
cell2.innerHTML = state[i].SeriesName;
|
|
||||||
cell3.innerHTML = state[i].Seasons.length;
|
|
||||||
}
|
|
||||||
@@ -1,21 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Data;
|
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Controller.Entities;
|
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner;
|
namespace Jellyfin.Plugin.MediaCleaner;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main plugin.
|
/// The main plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
public class Plugin : BasePlugin<Configuration>, IHasWebPages
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
||||||
@@ -46,8 +42,13 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
[
|
[
|
||||||
new PluginPageInfo
|
new PluginPageInfo
|
||||||
{
|
{
|
||||||
Name = "Settings",
|
Name = "configuration.js",
|
||||||
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.settings.html", GetType().Namespace),
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Pages.configuration.js", GetType().Namespace),
|
||||||
|
},
|
||||||
|
new PluginPageInfo
|
||||||
|
{
|
||||||
|
Name = "Configuration",
|
||||||
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Pages.configuration.html", GetType().Namespace),
|
||||||
},
|
},
|
||||||
new PluginPageInfo
|
new PluginPageInfo
|
||||||
{
|
{
|
||||||
@@ -57,8 +58,13 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
|||||||
},
|
},
|
||||||
new PluginPageInfo
|
new PluginPageInfo
|
||||||
{
|
{
|
||||||
Name = "media_cleaner_table.js",
|
Name = "home.js",
|
||||||
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Pages.media_cleaner_table.js", GetType().Namespace),
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Pages.home.js", GetType().Namespace),
|
||||||
|
},
|
||||||
|
new PluginPageInfo
|
||||||
|
{
|
||||||
|
Name = "global.css",
|
||||||
|
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Pages.global.css", GetType().Namespace),
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ public class PluginServiceRegistrator : IPluginServiceRegistrator
|
|||||||
{
|
{
|
||||||
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
|
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
|
||||||
{
|
{
|
||||||
serviceCollection.AddSingleton<PluginState>();
|
serviceCollection.AddSingleton<MediaCleanerState>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data.Common;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Reflection.Metadata.Ecma335;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Enums;
|
using Jellyfin.Data.Enums;
|
||||||
using Jellyfin.Database.Implementations.Entities;
|
|
||||||
using Jellyfin.Database.Implementations.Entities.Libraries;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
|
||||||
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Model.Tasks;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.ScheduledTasks;
|
namespace Jellyfin.Plugin.MediaCleaner;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A task to scan media for stale files.
|
/// A task to scan media for stale files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class StaleMediaTask : IScheduledTask
|
public sealed class StaleMediaScanner
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
@@ -38,7 +27,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Logger for StaleMediaTask.</param>
|
/// <param name="logger">Logger for StaleMediaTask.</param>
|
||||||
/// <param name="libraryManager">Accesses jellyfin's library manager for media.</param>
|
/// <param name="libraryManager">Accesses jellyfin's library manager for media.</param>
|
||||||
public StaleMediaTask(ILogger<StaleMediaTask> logger, ILibraryManager libraryManager)
|
public StaleMediaScanner(ILogger<StaleMediaScanner> logger, ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
@@ -47,18 +36,7 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
_seriesHelper = new SeriesHelper(_logger);
|
_seriesHelper = new SeriesHelper(_logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginConfiguration Configuration =>
|
public Task<IEnumerable<MediaInfo>> ScanStaleMedia()
|
||||||
Plugin.Instance!.Configuration;
|
|
||||||
|
|
||||||
string IScheduledTask.Name => "Scan Stale Media";
|
|
||||||
|
|
||||||
string IScheduledTask.Key => "Stale Media";
|
|
||||||
|
|
||||||
string IScheduledTask.Description => "Scan Stale Media";
|
|
||||||
|
|
||||||
string IScheduledTask.Category => "Media";
|
|
||||||
|
|
||||||
Task IScheduledTask.ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
_loggingHelper.LogDebugInformation("--DEBUG MODE ACTIVE--");
|
_loggingHelper.LogDebugInformation("--DEBUG MODE ACTIVE--");
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||||
@@ -73,78 +51,103 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
|
|
||||||
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
|
||||||
|
|
||||||
_loggingHelper.LogInformation("Total items: {ItemCount}", allItems.Count);
|
_loggingHelper.LogInformation("Total items to scan: {ItemCount}", allItems.Count);
|
||||||
_loggingHelper.LogInformation("Stale items found: {AllItems}", allItems);
|
_loggingHelper.LogDebugInformation("Items found: {AllItems}", allItems);
|
||||||
|
|
||||||
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
|
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
|
||||||
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
|
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
|
||||||
|
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogInformation("Starting scan of series items.");
|
_loggingHelper.LogDebugInformation("Starting scan of series items.");
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
|
||||||
|
|
||||||
List<BaseItem> staleSeasons = [.. series.SelectMany(GetStaleSeasons)];
|
List<BaseItem> staleSeasons = [.. series.SelectMany(GetStaleSeasons)];
|
||||||
|
|
||||||
_loggingHelper.LogInformation("Starting scan of movies items.");
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogDebugInformation("End of scan for series items.");
|
||||||
|
|
||||||
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
|
_loggingHelper.LogDebugInformation("Starting scan of movie items.");
|
||||||
|
|
||||||
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
|
List<BaseItem> staleMovies = [.. GetStaleMovies(movies)];
|
||||||
|
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
|
_loggingHelper.LogDebugInformation("End of scan for movie items.");
|
||||||
|
|
||||||
if (staleMovies.Count > 0 && Configuration.DebugMode)
|
|
||||||
{
|
|
||||||
foreach (var movieInfo in staleMovies)
|
|
||||||
{
|
|
||||||
_loggingHelper.LogDebugInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogInformation("Stale seasons found: {StaleSeasons}", staleSeasons.Count);
|
_loggingHelper.LogInformation("Stale seasons found: {StaleSeasons}", staleSeasons.Count);
|
||||||
|
|
||||||
if (staleSeasons.Count > 0 && Configuration.DebugMode)
|
IEnumerable<MediaInfo> staleSeriesInfo = [];
|
||||||
{
|
|
||||||
IEnumerable<SeriesInfo> staleSeriesInfo = FindSeriesInfo(staleSeasons);
|
|
||||||
|
|
||||||
foreach (var seriesInfo in staleSeriesInfo)
|
if (staleSeasons.Count > 0)
|
||||||
{
|
{
|
||||||
_loggingHelper.LogDebugInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
staleSeriesInfo = FindSeriesInfo(staleSeasons);
|
||||||
|
|
||||||
|
foreach (SeriesInfo seriesInfo in staleSeriesInfo.Cast<SeriesInfo>())
|
||||||
|
{
|
||||||
|
_loggingHelper.LogInformation("Series Info: TmbdID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.TmdbId, seriesInfo.Name, string.Join(", ", seriesInfo.Seasons)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loggingHelper.LogInformation("No stale seasons found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||||
|
_loggingHelper.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
|
||||||
|
|
||||||
|
IEnumerable<MediaInfo> staleMoviesInfo = [];
|
||||||
|
|
||||||
|
if (staleMovies.Count > 0)
|
||||||
|
{
|
||||||
|
staleMoviesInfo = staleMovies.Select(movie => {
|
||||||
|
movie.ProviderIds.TryGetValue("Tmdb", out string? tmdbId);
|
||||||
|
return new MovieInfo
|
||||||
|
{
|
||||||
|
TmdbId = tmdbId ?? string.Empty,
|
||||||
|
Name = movie.Name
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (MovieInfo movieInfo in staleMoviesInfo.Cast<MovieInfo>())
|
||||||
|
{
|
||||||
|
_loggingHelper.LogInformation("Movie Info: TmdbID: {Id} | Movie Name: {MovieName}", [movieInfo.TmdbId, movieInfo.Name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loggingHelper.LogInformation("No stale movies found!");
|
||||||
|
}
|
||||||
|
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogInformation("Ending stale media scan...");
|
_loggingHelper.LogInformation("Ending stale media scan...");
|
||||||
_loggingHelper.LogInformation("-------------------------------------------------");
|
_loggingHelper.LogInformation("-------------------------------------------------");
|
||||||
|
|
||||||
return Task.CompletedTask;
|
IEnumerable<MediaInfo> mediaInfo = staleSeriesInfo.Concat(staleMoviesInfo);
|
||||||
|
|
||||||
|
return Task.FromResult(mediaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BaseItem> GetStaleMovies(List<BaseItem> movies)
|
private List<BaseItem> GetStaleMovies(List<BaseItem> movies)
|
||||||
{
|
{
|
||||||
List<BaseItem> staleMovies = [];
|
List<BaseItem> staleMovies = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
staleMovies.AddRange(movies.Where(_movieHelper.IsMovieStale));
|
staleMovies.AddRange(movies.Where(_movieHelper.IsMovieStale));
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_loggingHelper.LogInformation("Arguement Null Exception in GetStaleMovies!");
|
||||||
|
_loggingHelper.LogInformation(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
return staleMovies;
|
return staleMovies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<BaseItem> GetStaleSeasonsWithShortCircuitOnNonStaleSeason(IEnumerable<BaseItem> seasons)
|
||||||
private List<BaseItem> GetStaleSeasons(BaseItem item)
|
|
||||||
{
|
{
|
||||||
_loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name);
|
foreach (BaseItem season in seasons)
|
||||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
|
||||||
|
|
||||||
// Gets each season in a show
|
|
||||||
var seasons = _libraryManager.GetItemList(new InternalItemsQuery
|
|
||||||
{
|
{
|
||||||
ParentId = item.Id,
|
|
||||||
Recursive = false
|
|
||||||
});
|
|
||||||
|
|
||||||
List<BaseItem> staleSeasons = [ ..seasons
|
|
||||||
.Where(season => {
|
|
||||||
var episodes = _libraryManager.GetItemList(new InternalItemsQuery
|
var episodes = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
{
|
{
|
||||||
ParentId = season.Id,
|
ParentId = season.Id,
|
||||||
@@ -153,22 +156,46 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
|
|
||||||
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
|
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
|
||||||
|
|
||||||
bool isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
|
bool isSeasonDataStale = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException ex)
|
||||||
|
{
|
||||||
|
_loggingHelper.LogInformation("Argument Null Exception in GetStaleSeasons!");
|
||||||
|
_loggingHelper.LogInformation(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
_loggingHelper.LogDebugInformation("End of season debug information for {SeasonNumber}.", season);
|
_loggingHelper.LogDebugInformation("End of season debug information for {SeasonNumber}.", season);
|
||||||
|
|
||||||
return isSeasonDataStale;
|
if (!isSeasonDataStale) yield break;
|
||||||
})];
|
yield return season;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<BaseItem> GetStaleSeasons(BaseItem item)
|
||||||
|
{
|
||||||
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
|
_loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name);
|
||||||
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
|
|
||||||
|
var seasons = _libraryManager.GetItemList(new InternalItemsQuery
|
||||||
|
{
|
||||||
|
ParentId = item.Id,
|
||||||
|
Recursive = false
|
||||||
|
});
|
||||||
|
|
||||||
|
List<BaseItem> staleSeasons = [.. GetStaleSeasonsWithShortCircuitOnNonStaleSeason(seasons)];
|
||||||
|
|
||||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
||||||
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
|
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
|
||||||
_loggingHelper.LogDebugInformation("-------------------------------------------------");
|
|
||||||
|
|
||||||
return staleSeasons;
|
return staleSeasons;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<SeriesInfo> FindSeriesInfo(IReadOnlyCollection<BaseItem> seasons)
|
private IEnumerable<MediaInfo> FindSeriesInfo(IReadOnlyCollection<BaseItem> seasons)
|
||||||
{
|
{
|
||||||
Guid[] seriesIds = [.. seasons.Select(season => season.ParentId).Distinct()];
|
Guid[] seriesIds = [.. seasons.Select(season => season.ParentId).Distinct()];
|
||||||
|
|
||||||
@@ -179,24 +206,19 @@ public sealed class StaleMediaTask : IScheduledTask
|
|||||||
|
|
||||||
IEnumerable<SeriesInfo> seriesInfoList = series.Select(series =>
|
IEnumerable<SeriesInfo> seriesInfoList = series.Select(series =>
|
||||||
{
|
{
|
||||||
|
series.ProviderIds.TryGetValue("Tvdb", out string? tvdbId);
|
||||||
|
series.ProviderIds.TryGetValue("Tmdb", out string? tmdbId);
|
||||||
|
|
||||||
return new SeriesInfo
|
return new SeriesInfo
|
||||||
{
|
{
|
||||||
Id = series.Id,
|
SeriesId = series.Id,
|
||||||
SeriesName = series.Name,
|
TmdbId = tmdbId ?? string.Empty,
|
||||||
Seasons = [.. seasons.Where(season => season.ParentId == series.Id).Select(season => season.Name)]
|
TvdbId = tvdbId ?? string.Empty,
|
||||||
|
Name = series.Name,
|
||||||
|
Seasons = [.. seasons.Where(season => season.ParentId == series.Id).Select(season => season.Name.Replace("Season ", "", StringComparison.OrdinalIgnoreCase))]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return seriesInfoList;
|
return seriesInfoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<TaskTriggerInfo> IScheduledTask.GetDefaultTriggers()
|
|
||||||
{
|
|
||||||
// Run this task every 24 hours
|
|
||||||
yield return new TaskTriggerInfo
|
|
||||||
{
|
|
||||||
Type = TaskTriggerInfoType.IntervalTrigger,
|
|
||||||
IntervalTicks = TimeSpan.FromHours(24).Ticks
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,9 @@ At the time of writing, the plugin is only capable of logging movies and shows t
|
|||||||
|
|
||||||
Planned features:
|
Planned features:
|
||||||
- Better logging to show more than just the count. ✅
|
- Better logging to show more than just the count. ✅
|
||||||
- A page that shows what media is currently flagged for removal. And a button to confirm removal.
|
- A page that shows what media is currently flagged for removal. ✅
|
||||||
- Integration with sonarr and radarr apis to delete your media.
|
- Checkboxes to select media for removal within Jellyfin. ✅
|
||||||
|
- Integration with sonarr and radarr apis to delete your media. ✅
|
||||||
- Whitelist for shows to ignore. (Seasonal shows)
|
- Whitelist for shows to ignore. (Seasonal shows)
|
||||||
|
|
||||||
Future features if I feel like it:
|
Future features if I feel like it:
|
||||||
|
|||||||
Reference in New Issue
Block a user