new update code

This commit is contained in:
karl.hudgell 2022-06-08 22:10:37 +01:00
parent 52885e1e8c
commit ed45fa5c92
4 changed files with 23 additions and 52 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ releasebb.json
config.json
package-lock.json
jdrssdownloader.log
.vscode/launch.json

View File

@ -14,9 +14,9 @@ function filterFeed(fileName) {
let urls_with_HEVC_in_url = extracted_urls_for_show.filter(item => item.includes('HEVC'))
let urls_with_quality_in_url = urls_with_HEVC_in_url.filter(item => item.includes(show.Quality))
let urls_without_torrent_in_url = urls_with_quality_in_url.filter(item => !item.includes('torrent'))
log.info(show + ' - ' + urls_without_torrent_in_url)
log.info(show.Name + ' - ' + urls_without_torrent_in_url)
linkAdder(urls_without_torrent_in_url)
// console.log(list_filtered_for_show)
// console.log(urls_without_torrent_in_url)
} catch (error) {
log.info(show.Name + ' not on feed')
}

43
main.js
View File

@ -2,9 +2,10 @@
const fs = require("fs");
const Parser = require("rss-parser");
const { filterFeed } = require("./feed");
const lodash = require('lodash');
(async function main() {
(async function main() {
// Make a new RSS Parser
@ -21,44 +22,12 @@ const { filterFeed } = require("./feed");
if (fs.existsSync(fileName)) {
items = require(`./${fileName}`);
}
// Add the items to the items array
await Promise.all(feed.items.map(async (currentItem) => {
// Add a new item if it doesn't already exist
if (items.filter((item) => isEquivalent(item, currentItem)).length <= 0) {
items.push(currentItem);
}
}));
let updatedArray = lodash.unionBy(feed.items, items, 'title');
// Save the file
fs.writeFileSync(fileName, JSON.stringify(items));
console.log(updatedArray.length)
fs.writeFileSync(fileName, JSON.stringify(updatedArray));
// run next part
filterFeed(fileName)
})();
function isEquivalent(a, b) {
// Create arrays of property names
let aProps = Object.getOwnPropertyNames(a);
let bProps = Object.getOwnPropertyNames(b);
// if number of properties is different, objects are not equivalent
if (aProps.length != bProps.length) {
return false;
}
for (let i = 0; i < aProps.length; i++) {
let propName = aProps[i];
// if values of same property are not equal, objects are not equivalent
if (a[propName] !== b[propName]) {
return false;
}
}
// if we made it this far, objects are considered equivalent
return true;
}
})();

View File

@ -11,6 +11,7 @@
"dependencies": {
"extract-urls": "^1.3.2",
"jdownloader-client": "^1.0.0",
"lodash": "^4.17.21",
"rss-parser": "^3.12.0",
"simple-node-logger": "^21.8.12"
}