Compare commits
2 Commits
a676a8e8ec
...
v1.0.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
| de94fbd7ec | |||
| 98dfd51d3e |
@@ -1,5 +1,5 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<AssemblyVersion>0.0.0.12</AssemblyVersion>
|
<AssemblyVersion>0.1.0.0</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -30,16 +30,6 @@ public class Configuration : BasePluginConfiguration
|
|||||||
/// </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>
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Enums;
|
using System.Web;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -23,10 +24,25 @@ public record RadarrMovie(
|
|||||||
[Route("radarr")]
|
[Route("radarr")]
|
||||||
public class RadarrController : Controller
|
public class RadarrController : Controller
|
||||||
{
|
{
|
||||||
|
private static Configuration Configuration =>
|
||||||
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
|
public RadarrController(HttpClient httpClient)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
|
||||||
|
// Set the default request headers
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", Configuration.RadarrAPIKey);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<ObjectResult> GetRadarrMovieInfo(MovieInfo movieInfo)
|
private async Task<ObjectResult> GetRadarrMovieInfo(MovieInfo movieInfo)
|
||||||
{
|
{
|
||||||
HttpHelper httpHelper = new(ServerType.Radarr);
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
_httpClient,
|
||||||
|
Configuration.RadarrAddress,
|
||||||
HttpMethod.Get,
|
HttpMethod.Get,
|
||||||
$"/api/v3/movie?tmdbId={Uri.EscapeDataString(movieInfo.TmdbId ?? string.Empty)}&excludeLocalCovers=false"
|
$"/api/v3/movie?tmdbId={Uri.EscapeDataString(movieInfo.TmdbId ?? string.Empty)}&excludeLocalCovers=false"
|
||||||
).ConfigureAwait(false);
|
).ConfigureAwait(false);
|
||||||
@@ -60,8 +76,9 @@ public class RadarrController : Controller
|
|||||||
|
|
||||||
RadarrMovie movie = (RadarrMovie)radarrMovieInfoResult.Value;
|
RadarrMovie movie = (RadarrMovie)radarrMovieInfoResult.Value;
|
||||||
|
|
||||||
HttpHelper httpHelper = new(ServerType.Radarr);
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
_httpClient,
|
||||||
|
Configuration.RadarrAddress,
|
||||||
HttpMethod.Delete,
|
HttpMethod.Delete,
|
||||||
$"/api/v3/movie/{movie.Id}?deleteFiles=true&addImportExclusion=true"
|
$"/api/v3/movie/{movie.Id}?deleteFiles=true&addImportExclusion=true"
|
||||||
).ConfigureAwait(false);
|
).ConfigureAwait(false);
|
||||||
@@ -92,11 +109,10 @@ public class RadarrController : Controller
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var testHttpClient = new HttpClient();
|
|
||||||
using var httpRequest = new HttpRequestMessage(HttpMethod.Get, address);
|
using var httpRequest = new HttpRequestMessage(HttpMethod.Get, address);
|
||||||
httpRequest.Headers.Add("X-Api-Key", request.ApiKey);
|
httpRequest.Headers.Add("X-Api-Key", request.ApiKey);
|
||||||
|
|
||||||
var response = await testHttpClient.SendAsync(httpRequest).ConfigureAwait(false);
|
var response = await _httpClient.SendAsync(httpRequest).ConfigureAwait(false);
|
||||||
return Ok(new { success = response.IsSuccessStatusCode });
|
return Ok(new { success = response.IsSuccessStatusCode });
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Enums;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
using Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
namespace Jellyfin.Plugin.MediaCleaner.Controllers;
|
||||||
@@ -37,6 +37,9 @@ public record Season(
|
|||||||
[Route("sonarr")]
|
[Route("sonarr")]
|
||||||
public class SonarrController : Controller
|
public class SonarrController : Controller
|
||||||
{
|
{
|
||||||
|
private static Configuration Configuration =>
|
||||||
|
Plugin.Instance!.Configuration;
|
||||||
|
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
|
||||||
public SonarrController(HttpClient httpClient)
|
public SonarrController(HttpClient httpClient)
|
||||||
@@ -45,11 +48,13 @@ public class SonarrController : Controller
|
|||||||
|
|
||||||
// Set the default request headers
|
// Set the default request headers
|
||||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", Configuration.SonarrAPIKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ObjectResult> GetSonarrSeriesInfo(SeriesInfo seriesInfo){
|
private async Task<ObjectResult> GetSonarrSeriesInfo(SeriesInfo seriesInfo){
|
||||||
HttpHelper httpHelper = new(ServerType.Sonarr);
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
_httpClient,
|
||||||
|
Configuration.SonarrAddress,
|
||||||
HttpMethod.Get,
|
HttpMethod.Get,
|
||||||
$"/api/v3/series?tvdbId={Uri.EscapeDataString(seriesInfo.TvdbId ?? string.Empty)}"
|
$"/api/v3/series?tvdbId={Uri.EscapeDataString(seriesInfo.TvdbId ?? string.Empty)}"
|
||||||
).ConfigureAwait(false);
|
).ConfigureAwait(false);
|
||||||
@@ -66,8 +71,9 @@ public class SonarrController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ObjectResult> GetSonarrEpisodeInfo(SonarrSeries sonarrSeries){
|
private async Task<ObjectResult> GetSonarrEpisodeInfo(SonarrSeries sonarrSeries){
|
||||||
HttpHelper httpHelper = new(ServerType.Sonarr);
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
_httpClient,
|
||||||
|
Configuration.SonarrAddress,
|
||||||
HttpMethod.Get,
|
HttpMethod.Get,
|
||||||
$"/api/v3/episode?seriesId={sonarrSeries.Id?.ToString(CultureInfo.InvariantCulture)}"
|
$"/api/v3/episode?seriesId={sonarrSeries.Id?.ToString(CultureInfo.InvariantCulture)}"
|
||||||
).ConfigureAwait(false);
|
).ConfigureAwait(false);
|
||||||
@@ -103,7 +109,7 @@ public class SonarrController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("deleteSeriesFromSonarr")]
|
[HttpPost("deleteSeriesFromSonarr")]
|
||||||
public async Task<IActionResult> DeleteSeriesFromSonarr([FromBody] SeriesInfo seriesInfo){
|
public async Task<IActionResult> DeleteSeriesFromRadarr([FromBody] SeriesInfo seriesInfo){
|
||||||
|
|
||||||
if (seriesInfo == null || string.IsNullOrEmpty(seriesInfo.TvdbId))
|
if (seriesInfo == null || string.IsNullOrEmpty(seriesInfo.TvdbId))
|
||||||
{
|
{
|
||||||
@@ -151,8 +157,9 @@ public class SonarrController : Controller
|
|||||||
return BadRequest("No stale series provided.");
|
return BadRequest("No stale series provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpHelper httpHelper = new(ServerType.Sonarr);
|
var series = await HttpHelper.SendHttpRequestAsync(
|
||||||
var series = await httpHelper.SendHttpRequestAsync(
|
_httpClient,
|
||||||
|
Configuration.SonarrAddress,
|
||||||
HttpMethod.Get,
|
HttpMethod.Get,
|
||||||
$"/api/v3/series/{staleSeries.Id}"
|
$"/api/v3/series/{staleSeries.Id}"
|
||||||
).ConfigureAwait(false);
|
).ConfigureAwait(false);
|
||||||
@@ -188,7 +195,9 @@ public class SonarrController : Controller
|
|||||||
|
|
||||||
seriesDict["seasons"] = updatedSeasons;
|
seriesDict["seasons"] = updatedSeasons;
|
||||||
|
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
|
_httpClient,
|
||||||
|
Configuration.SonarrAddress,
|
||||||
HttpMethod.Put,
|
HttpMethod.Put,
|
||||||
$"/api/v3/series/{staleSeries.Id}",
|
$"/api/v3/series/{staleSeries.Id}",
|
||||||
seriesDict
|
seriesDict
|
||||||
@@ -204,8 +213,9 @@ public class SonarrController : Controller
|
|||||||
return BadRequest("No episode file IDs provided.");
|
return BadRequest("No episode file IDs provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpHelper httpHelper = new(ServerType.Sonarr);
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
_httpClient,
|
||||||
|
Configuration.SonarrAddress,
|
||||||
HttpMethod.Delete,
|
HttpMethod.Delete,
|
||||||
"/api/v3/episodefile/bulk",
|
"/api/v3/episodefile/bulk",
|
||||||
new { episodeFileIds }
|
new { episodeFileIds }
|
||||||
@@ -221,9 +231,9 @@ public class SonarrController : Controller
|
|||||||
return BadRequest("No episode IDs provided.");
|
return BadRequest("No episode IDs provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var responseBody = await HttpHelper.SendHttpRequestAsync(
|
||||||
HttpHelper httpHelper = new(ServerType.Sonarr);
|
_httpClient,
|
||||||
var responseBody = await httpHelper.SendHttpRequestAsync(
|
Configuration.SonarrAddress,
|
||||||
HttpMethod.Put,
|
HttpMethod.Put,
|
||||||
"/api/v3/episode/monitor",
|
"/api/v3/episode/monitor",
|
||||||
new { episodeIds, monitored = false }
|
new { episodeIds, monitored = false }
|
||||||
|
|||||||
@@ -25,11 +25,7 @@ public class StateController(MediaCleanerState state) : Controller
|
|||||||
public IActionResult GetMoviesTitle() =>
|
public IActionResult GetMoviesTitle() =>
|
||||||
Ok($"Stale Movies (Unwatched for and created over {Configuration.StaleMediaCutoff} Days ago.)");
|
Ok($"Stale Movies (Unwatched for and created over {Configuration.StaleMediaCutoff} Days ago.)");
|
||||||
|
|
||||||
[HttpGet("getSeriesTitle")]
|
[HttpGet("getSeriesTitle")]
|
||||||
public IActionResult GetSeriesTitle() =>
|
public IActionResult GetSeriesTitle() =>
|
||||||
Ok($"Stale TV Series (Unwatched for and created over {Configuration.StaleMediaCutoff} Days ago.)");
|
Ok($"Stale 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.)");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Jellyfin.Plugin.MediaCleaner.Enums;
|
|
||||||
|
|
||||||
public enum ServerType
|
|
||||||
{
|
|
||||||
Radarr,
|
|
||||||
Sonarr,
|
|
||||||
SonarrAnime
|
|
||||||
}
|
|
||||||
@@ -1,43 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Plugin.MediaCleaner.Enums;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||||
|
|
||||||
public class HttpHelper
|
public static 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>
|
/// <summary>
|
||||||
/// Sends a JSON request and returns the raw JSON element response.
|
/// Sends a JSON request and returns the raw JSON element response.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Do NOT create a new HttpClient on every call; reuse one instance (DI or a singleton) to avoid socket exhaustion.
|
/// Do NOT create a new HttpClient on every call; reuse one instance (DI or a singleton) to avoid socket exhaustion.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public async Task<JsonElement> SendHttpRequestAsync(HttpMethod method, string path, object? body = null)
|
public static async Task<JsonElement> SendHttpRequestAsync(HttpClient httpClient, string baseAddress, HttpMethod method, string path, object? body = null)
|
||||||
{
|
{
|
||||||
var uri = new UriBuilder($"{_baseAddress}{path}").Uri;
|
var uri = new UriBuilder($"{baseAddress}{path}").Uri;
|
||||||
using var request = new HttpRequestMessage(method, uri);
|
using var request = new HttpRequestMessage(method, uri);
|
||||||
|
|
||||||
if (body != null)
|
if (body != null)
|
||||||
@@ -46,32 +26,10 @@ public class HttpHelper
|
|||||||
request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
|
request.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = await _httpClient.SendAsync(request).ConfigureAwait(false);
|
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
return JsonSerializer.Deserialize<JsonElement>(responseBody);
|
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,26 +47,6 @@
|
|||||||
</div>
|
</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>
|
<h3>General Settings</h3>
|
||||||
<div class="inlineContainer">
|
<div class="inlineContainer">
|
||||||
<div class="inputContainer">
|
<div class="inputContainer">
|
||||||
|
|||||||
@@ -32,14 +32,6 @@ const startFadeIn = (element, interval = 100) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Connection Methods
|
// 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 () => {
|
const testConnectionSonarr = async () => {
|
||||||
var apiKeyElement = document.getElementById('SonarrAPIKey');
|
var apiKeyElement = document.getElementById('SonarrAPIKey');
|
||||||
var addressElement = document.getElementById('SonarrAddress');
|
var addressElement = document.getElementById('SonarrAddress');
|
||||||
@@ -139,9 +131,6 @@ document.querySelector('#RadarrTestConnectionButton')
|
|||||||
document.querySelector('#SonarrTestConnectionButton')
|
document.querySelector('#SonarrTestConnectionButton')
|
||||||
.addEventListener('click', testConnectionSonarr);
|
.addEventListener('click', testConnectionSonarr);
|
||||||
|
|
||||||
document.querySelector('#SonarrAnimeTestConnectionButton')
|
|
||||||
.addEventListener('click', testConnectionSonarrAnime);
|
|
||||||
|
|
||||||
document.querySelector('#MediaCleanerConfigPage')
|
document.querySelector('#MediaCleanerConfigPage')
|
||||||
.addEventListener('pageshow', function() {
|
.addEventListener('pageshow', function() {
|
||||||
Dashboard.showLoadingMsg();
|
Dashboard.showLoadingMsg();
|
||||||
@@ -150,8 +139,6 @@ document.querySelector('#MediaCleanerConfigPage')
|
|||||||
document.querySelector('#RadarrAddress').value = config.RadarrAddress;
|
document.querySelector('#RadarrAddress').value = config.RadarrAddress;
|
||||||
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
document.querySelector('#SonarrAPIKey').value = config.SonarrAPIKey;
|
||||||
document.querySelector('#SonarrAddress').value = config.SonarrAddress;
|
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('#StaleMediaCutoff').value = config.StaleMediaCutoff;
|
||||||
document.querySelector('#DebugMode').checked = config.DebugMode;
|
document.querySelector('#DebugMode').checked = config.DebugMode;
|
||||||
Dashboard.hideLoadingMsg();
|
Dashboard.hideLoadingMsg();
|
||||||
@@ -166,8 +153,6 @@ document.querySelector('#MediaCleanerConfigForm')
|
|||||||
config.RadarrAddress = document.querySelector('#RadarrAddress').value;
|
config.RadarrAddress = document.querySelector('#RadarrAddress').value;
|
||||||
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
config.SonarrAPIKey = document.querySelector('#SonarrAPIKey').value;
|
||||||
config.SonarrAddress = document.querySelector('#SonarrAddress').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.StaleMediaCutoff = document.querySelector('#StaleMediaCutoff').value;
|
||||||
config.DebugMode = document.querySelector('#DebugMode').checked;
|
config.DebugMode = document.querySelector('#DebugMode').checked;
|
||||||
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
ApiClient.updatePluginConfiguration(MediaCleanerConfig.pluginUniqueId, config).then(function (result) {
|
||||||
|
|||||||
@@ -33,19 +33,6 @@
|
|||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
<button id="seriesDeleteButton" class="delete-button raised button-submit emby-button" style="visibility: hidden;">Delete</button>
|
<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>
|
||||||
|
|||||||
@@ -8,11 +8,9 @@ const refreshFrontEnd = async () => {
|
|||||||
|
|
||||||
var moviesTitle = document.getElementById("moviesTitle");
|
var moviesTitle = document.getElementById("moviesTitle");
|
||||||
var seriesTitle = document.getElementById("seriesTitle");
|
var seriesTitle = document.getElementById("seriesTitle");
|
||||||
var animeSeriesTitle = document.getElementById("animeSeriesTitle");
|
|
||||||
|
|
||||||
moviesTitle.innerHTML = await getMediaCleanerMoviesTitle();
|
moviesTitle.innerHTML = await getMediaCleanerMoviesTitle();
|
||||||
seriesTitle.innerHTML = await getMediaCleanerSeriesTitle();
|
seriesTitle.innerHTML = await getMediaCleanerSeriesTitle();
|
||||||
animeSeriesTitle.innerHTML = await getMediaCleanerAnimeSeriesTitle();
|
|
||||||
|
|
||||||
await populateTables();
|
await populateTables();
|
||||||
addClickHandlersToLinks();
|
addClickHandlersToLinks();
|
||||||
@@ -50,16 +48,6 @@ const updateMediaCleanerState = async () => {
|
|||||||
return response.json();
|
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 getMediaCleanerSeriesTitle = async () => {
|
||||||
const response = await fetch("/mediacleaner/state/getSeriesTitle");
|
const response = await fetch("/mediacleaner/state/getSeriesTitle");
|
||||||
|
|
||||||
@@ -84,11 +72,6 @@ const getMediaCleanerMoviesTitle = async () => {
|
|||||||
const populateTables = async () => {
|
const populateTables = async () => {
|
||||||
var moviesInfo = await getMediaCleanerMovieInfo();
|
var moviesInfo = await getMediaCleanerMovieInfo();
|
||||||
var seriesInfo = await getMediaCleanerSeriesInfo();
|
var seriesInfo = await getMediaCleanerSeriesInfo();
|
||||||
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];
|
var seriesTableBody = seriesTable.getElementsByTagName('tbody')[0];
|
||||||
seriesTableBody.replaceChildren();
|
seriesTableBody.replaceChildren();
|
||||||
@@ -98,10 +81,6 @@ const populateTables = async () => {
|
|||||||
moviesTableBody.replaceChildren();
|
moviesTableBody.replaceChildren();
|
||||||
var moviesDeleteButton = document.getElementById('moviesDeleteButton');
|
var moviesDeleteButton = document.getElementById('moviesDeleteButton');
|
||||||
|
|
||||||
var animeSeriesTableBody = animeSeriesTable.getElementsByTagName('tbody')[0];
|
|
||||||
animeSeriesTableBody.replaceChildren();
|
|
||||||
var animeSeriesDeleteButton = document.getElementById('animeSeriesDeleteButton');
|
|
||||||
|
|
||||||
if (moviesInfo.length > 0){
|
if (moviesInfo.length > 0){
|
||||||
for(let i = 0; i < moviesInfo.length; i++){
|
for(let i = 0; i < moviesInfo.length; i++){
|
||||||
var row = moviesTableBody.insertRow(-1);
|
var row = moviesTableBody.insertRow(-1);
|
||||||
@@ -141,30 +120,7 @@ const populateTables = async () => {
|
|||||||
var row = seriesTableBody.insertRow(-1);
|
var row = seriesTableBody.insertRow(-1);
|
||||||
var cell1 = row.insertCell(0);
|
var cell1 = row.insertCell(0);
|
||||||
cell1.colSpan = columnCount;
|
cell1.colSpan = columnCount;
|
||||||
cell1.innerHTML = "No stale tv series found.";
|
cell1.innerHTML = "No stale 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 = animeSeriesTableBody.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";
|
cell1.className = "table-text";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -223,10 +179,8 @@ const addClickHandlersToLinks = () => {
|
|||||||
const addClickHandlersToDeleteButtons = () => {
|
const addClickHandlersToDeleteButtons = () => {
|
||||||
const deleteMoviesButtonElement = document.getElementById("moviesDeleteButton");
|
const deleteMoviesButtonElement = document.getElementById("moviesDeleteButton");
|
||||||
const deleteSeriesButtonElement = document.getElementById("seriesDeleteButton");
|
const deleteSeriesButtonElement = document.getElementById("seriesDeleteButton");
|
||||||
const deleteAnimeSeriesButtonElement = document.getElementById("animeSeriesDeleteButton");
|
|
||||||
deleteMoviesButtonElement.addEventListener("click", deleteFromRadarr);
|
deleteMoviesButtonElement.addEventListener("click", deleteFromRadarr);
|
||||||
deleteSeriesButtonElement.addEventListener("click", deleteFromSonarr);
|
deleteSeriesButtonElement.addEventListener("click", deleteFromSonarr);
|
||||||
deleteAnimeSeriesButtonElement.addEventListener("click", deleteFromSonarrAnime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCheckedMedia = (table) => {
|
const getCheckedMedia = (table) => {
|
||||||
@@ -265,20 +219,6 @@ const deleteSeriesFromSonarrApi = async (series) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteSeriesFromSonarrAnimeApi = async (series) => {
|
|
||||||
const response = await fetch("/sonarr/deleteSeriesFromSonarrAnime", {
|
|
||||||
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 deleteFromRadarr = async () => {
|
||||||
const selectedMovies = getCheckedMedia(moviesTable);
|
const selectedMovies = getCheckedMedia(moviesTable);
|
||||||
selectedMovies.forEach(async movie => await deleteMovieFromRadarrApi(movie));
|
selectedMovies.forEach(async movie => await deleteMovieFromRadarrApi(movie));
|
||||||
@@ -291,12 +231,6 @@ const deleteFromSonarr = () => {
|
|||||||
refreshFrontEnd();
|
refreshFrontEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteFromAnimeSonarr = () => {
|
|
||||||
const selectedSeries = getCheckedMedia(animeSeriesTable);
|
|
||||||
selectedSeries.forEach(async series => await deleteSeriesFromSonarrApi(series));
|
|
||||||
refreshFrontEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
const finishLoading = () => {
|
const finishLoading = () => {
|
||||||
const loadingElement = document.getElementById("loading");
|
const loadingElement = document.getElementById("loading");
|
||||||
const homepage = document.getElementById("homepage");
|
const homepage = document.getElementById("homepage");
|
||||||
|
|||||||
Reference in New Issue
Block a user