Reworked Models to use tmdb to enable integration with Radarr api. Also reworked test connection to use api to validate as I ran into CORS errors. I also set up an endpoint to call radarr to delete movies. Currently only got to retrieving movie info. Should be able to use the id retrieved to then delete the movie.

This commit is contained in:
2026-03-07 18:02:45 -07:00
parent 958c581280
commit 3f5074aa3b
7 changed files with 276 additions and 70 deletions

View File

@@ -63,45 +63,6 @@ const getMediaCleanerMoviesTitle = async () => {
return response.json();
};
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 populateTables = async () => {
var moviesInfo = await getMediaCleanerMovieInfo();
@@ -159,6 +120,46 @@ const populateTables = async () => {
}
};
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 => {
@@ -177,15 +178,41 @@ const addClickHandlersToDeleteButtons = () => {
deleteSeriesButtonElement.addEventListener("click", deleteFromSonarr);
}
const deleteFromRadarr = () => {
// Need to GET first for movieIds?
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;
}
// Likely need to use MovieEditor DELETE endpoint (/api/v3/movie/editor)
const deleteMovieFromRadarrApi = async (movie) => {
console.log("Movie to post: ", 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}`)
}
return console.log("Response: ", response.json());
}
const deleteFromRadarr = async () => {
// Get all movies with checked checkboxes
const selectedMovies = getCheckedMedia(moviesTable);
selectedMovies.forEach(async movie => await deleteMovieFromRadarrApi(movie));
// Need to GET first for movieIds?
// /api/v3/movie?tmdbId=383275
// Likely need to use Movie DELETE endpoint (/api/v3/movie/{id})
// Payload:
// {
// "movieIds": [
// 0
// ],
// "id": id
// "deleteFiles": true
// }
console.log("Delete from Radarr!")
@@ -193,16 +220,13 @@ const deleteFromRadarr = () => {
const deleteFromSonarr = () => {
// Need to GET first for seriesIds?
getCheckedMedia(seriesTable);
// Use tvdbId included in filenames.
// /api/v5/series?tvdbId=383275
// Possibly use statistics from GET to show on front end?
// Likely need to use SeriesEditor DELETE endpoint
// Payload:
// {
// "seriesIds": [
// 1
// ],
// "seasonFolder": null,
// "deleteFiles": true,
// }
// Likely need to use EpisodeFile bulk DELETE endpoint
// /api/v5/episodefile/bulk
console.log("Delete from Sonarr!")
}