initial commit

This commit is contained in:
karl.hudgell 2022-06-08 12:28:30 +01:00
commit 68a0be65f5
6 changed files with 138 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.env
node_modules
releasebb.json
config.json
package-lock.json

6
config-sample.json Normal file
View File

@ -0,0 +1,6 @@
{
"RSS_Feed": "",
"Quality": "720",
"Autostart": false,
"Shows": []
}

28
feed.js Normal file
View File

@ -0,0 +1,28 @@
const extractUrls = require("extract-urls");
const fs = require('fs')
const { linkAdder } = require('./jd-link-adder');
function filterFeed(fileName) {
let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows
let feed = JSON.parse(fs.readFileSync(fileName));
myshowlist.forEach(show => {
try {
let list_filtered_for_show = feed.filter(item => item.title.includes(show))
let extracted_urls_for_show = extractUrls(list_filtered_for_show[0]["content:encoded"]);
let urls_with_HEVC_in_url = extracted_urls_for_show.filter(item => item.includes('HEVC'))
let urls_with_720_in_url = urls_with_HEVC_in_url.filter(item => item.includes(JSON.parse(fs.readFileSync('config.json')).Quality))
let urls_without_torrent_in_url = urls_with_720_in_url.filter(item => !item.includes('torrent'))
console.log(urls_without_torrent_in_url)
linkAdder(urls_without_torrent_in_url)
} catch (error) {
console.log(show + ' not on feed')
}
})
}
module.exports = {
filterFeed
}

17
jd-link-adder.js Normal file
View File

@ -0,0 +1,17 @@
const { JDownloaderClient } = require('jdownloader-client')
const fs = require("fs");
async function linkAdder(links) {
const client = new JDownloaderClient(process.env.JDUSERNAME, process.env.JDPASSWORD)
await client.connect()
const devices = await client.listDevices()
const addLinks = await client.linkGrabberAddLinks(devices[0].id, {
links: links,
autostart: JSON.parse(fs.readFileSync('config.json')).Autostart
})
}
module.exports = {
linkAdder
}

65
main.js Normal file
View File

@ -0,0 +1,65 @@
// Import dependencies
require('dotenv').config()
const fs = require("fs");
const Parser = require("rss-parser");
const { filterFeed } = require("./feed");
(async function main() {
// 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')).RSS_Feed);
let items = [];
// 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);
}
}));
// 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;
}

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "jdrssdownloader",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Karl0ss",
"license": "ISC",
"dependencies": {
"dotenv": "^16.0.1",
"extract-urls": "^1.3.2",
"jdownloader-client": "^1.0.0",
"rss-parser": "^3.12.0"
}
}