Merge pull request #1 from karl0ss/feedUpdater

new update code
This commit is contained in:
Karl Hudgell 2022-06-08 22:11:06 +01:00 committed by GitHub
commit a3987c67bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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')
}

69
main.js
View File

@ -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;
}
// run next part
filterFeed(fileName)
})();

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"
}