JDRssDownloader/apiFunctions.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-10-25 15:52:25 +01:00
const fs = require('fs');
2022-10-26 10:15:08 +01:00
2022-10-25 15:52:25 +01:00
async function addNewShow(showData) {
2022-10-26 10:15:08 +01:00
let shows = JSON.parse(fs.readFileSync('shows.json'))
2022-10-25 15:52:25 +01:00
let exist = false
2022-10-26 10:15:08 +01:00
for (let show of shows) {
2022-10-25 15:52:25 +01:00
if (show.Name == showData.showName) {
exist = true
}
}
if (exist) {
log.error(showData.showName + ' Already exists in list and not added')
} else {
2022-10-26 10:15:08 +01:00
shows.push({
2022-10-25 15:52:25 +01:00
"Name": showData.showName,
"Quality": showData.quality
})
try {
2022-10-26 10:15:08 +01:00
fs.writeFileSync('shows.json', JSON.stringify(shows));
log.info(showData.showName + ' Added to the list, checking for ' + showData.quality + 'p')
2022-10-25 15:52:25 +01:00
} catch (err) {
console.error(err);
}
}
}
async function removeShow(showData) {
2022-10-26 10:15:08 +01:00
let shows = JSON.parse(fs.readFileSync('shows.json'))
2022-10-25 15:52:25 +01:00
2022-10-26 10:15:08 +01:00
myArray = shows.filter(function (obj) {
2022-10-25 15:52:25 +01:00
return obj.Name !== showData.showName;
});
2022-10-26 10:15:08 +01:00
shows = myArray
2022-10-25 15:52:25 +01:00
try {
2022-10-26 10:15:08 +01:00
fs.writeFileSync('shows.json', JSON.stringify(shows));
log.info(showData.showName + ' Removed from tracking list.')
2022-10-25 15:52:25 +01:00
} catch (err) {
console.error(err);
}
}
async function editShow(showData) {
let shows = JSON.parse(fs.readFileSync('shows.json'))
for (let index = 0; index < shows.length; index++) {
const element = shows[index];
if (element.Name == showData.showName) {
shows[index] = {
"Name": showData.showName,
"Quality": showData.quality
}
}
}
try {
fs.writeFileSync('shows.json', JSON.stringify(shows));
log.info(showData.showName + ' Quality modified to ' + showData.quality + 'p')
} catch (err) {
console.error(err);
}
}
2023-01-24 12:04:14 +00:00
async function removeShowFromCache(showData) {
let shows = JSON.parse(fs.readFileSync('./cache/retryCache.json'))
myArray = shows.filter(function (obj) {
return obj.title !== showData;
});
shows = myArray
try {
fs.writeFileSync('./cache/retryCache.json', JSON.stringify(shows));
log.info(showData + ' Removed from retry cache.')
} catch (err) {
console.error(err);
}
}
2022-10-25 15:52:25 +01:00
module.exports = {
2023-01-24 12:04:14 +00:00
addNewShow, removeShow, editShow, removeShowFromCache
2022-10-25 15:52:25 +01:00
}