TV-Center/existing.js
2022-09-09 22:08:34 +02:00

128 lines
3.0 KiB
JavaScript

const apiUrls = [
{
url: '/sonarr-hs-series',
name: 'hidden-sea',
domain: 'sonarr-hs',
},
{
url: '/sonarr-cb-series',
name: 'cold-badlands',
domain: 'sonarr-cb',
},
{
url: '/sonarr-fv-series',
name: 'fancy-valley',
domain: 'sonarr-fv',
},
{
url: '/radarr-hs-movies',
name: 'hidden-sea',
domain: 'radarr-hs',
},
{
url: '/radarr-cb-movies',
name: 'cold-badlands',
domain: 'radarr-cb',
},
{
url: '/radarr-fv-movies',
name: 'fancy-valley',
domain: 'radarr-fv',
},
];
let media = [];
function removeMessage()
{
const message = document.querySelector('#status-message');
if (message) {
message.remove();
}
}
async function initial()
{
for (const apiUrl of apiUrls) {
const response = await fetch(apiUrl.url);
let json = await response.json();
json.map((item) => {
item.server = `${apiUrl.name}|${apiUrl.domain}|${item.titleSlug}|${item.tmdbId || item.id}`;
item.mediaType = apiUrl.url.includes('sonarr') ? 'Series' : 'Movie';
return item;
});
media = [...media, ...json];
}
media = media.sort((a, b) => {
return a.sortTitle.localeCompare(b.sortTitle);
});
let rows = media.map((mediaItem) => {
const { title, mediaType, year, server } = mediaItem;
return [
title,
mediaType,
year,
server,
];
});
const tblData = {
headings: [
'Series/Movie name',
'Type',
'Year',
'Server',
],
data: rows,
};
const tbl = document.querySelector('#media-table');
const dataTblConfig = {
searchable: true,
fixedHeight: false,
perPage: 100,
perPageSelect: [25, 50, 100, 250, 500, 750, 1000],
data: tblData,
layout: {
top: '{search}{select}',
bottom: '{pager}{info}',
},
columns: [
{
select: [3],
render: function(data, cell, row) {
const [name, domain, slug, id] = data.split('|');
let url = `https://${domain}.decicus.com`;
if (domain.includes('sonarr')) {
url += `/series/${slug}`;
}
else {
url += `/movie/${id}`;
}
return `<a href="${url}" target="_blank">${name}</a>`;
},
}
],
};
removeMessage();
const dataTbl = new simpleDatatables.DataTable(tbl, dataTblConfig);
dataTbl.on('datatable.init', function() {
const search = document.querySelector('.dataTable-search input');
search.focus();
});
}
window.addEventListener('DOMContentLoaded', function() {
initial();
});