From ed45fa5c92a9874906f0ddd9cc3f093dddb28474 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Wed, 8 Jun 2022 22:10:37 +0100 Subject: [PATCH] new update code --- .gitignore | 1 + feed.js | 4 +-- main.js | 69 +++++++++++++++------------------------------------- package.json | 1 + 4 files changed, 23 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index a32eafe..c3e7486 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ releasebb.json config.json package-lock.json jdrssdownloader.log +.vscode/launch.json diff --git a/feed.js b/feed.js index 3ef9c6f..129a045 100644 --- a/feed.js +++ b/feed.js @@ -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') } diff --git a/main.js b/main.js index b3f6918..dea5e22 100644 --- a/main.js +++ b/main.js @@ -2,63 +2,32 @@ 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 - const parser = new Parser(); + // Make a new RSS Parser + const parser = new Parser(); - // Get all the items in the RSS feed - const feed = await parser.parseURL(JSON.parse(fs.readFileSync('config.json')).RSSFeed); + // Get all the items in the RSS feed + const feed = await parser.parseURL(JSON.parse(fs.readFileSync('config.json')).RSSFeed); - let items = []; + let items = []; - // Clean up the string and replace reserved characters - const fileName = `${feed.title.replace(/\s+/g, "-").replace(/[/\\?%*:|"<>]/g, '').toLowerCase()}.json`; + // Clean up the string and replace reserved characters + const fileName = `${feed.title.replace(/\s+/g, "-").replace(/[/\\?%*:|"<>]/g, '').toLowerCase()}.json`; - 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); + if (fs.existsSync(fileName)) { + items = require(`./${fileName}`); } + let updatedArray = lodash.unionBy(feed.items, items, 'title'); + + // Save the file + console.log(updatedArray.length) + fs.writeFileSync(fileName, JSON.stringify(updatedArray)); - })); - - // Save the file - fs.writeFileSync(fileName, JSON.stringify(items)); - - // 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; -} \ No newline at end of file + // run next part + filterFeed(fileName) + })(); diff --git a/package.json b/package.json index 8802ca3..d8253c6 100644 --- a/package.json +++ b/package.json @@ -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" }