JDRssDownloader/FeedFilter.js

76 lines
3.6 KiB
JavaScript
Raw Normal View History

2022-06-09 10:06:22 +01:00
const fs = require('fs')
const { linkAdder } = require('./JDLinkAdder');
const { getLinksFromURL } = require('./LinkGrabber')
2022-06-12 16:34:37 +01:00
const { checkFileName } = require('./checkFileName')
2022-06-09 10:06:22 +01:00
2022-06-09 10:29:05 +01:00
async function filterFeed() {
2022-06-09 10:06:22 +01:00
let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows
2022-06-12 16:34:37 +01:00
let hevcSwitch = JSON.parse(fs.readFileSync('config.json')).OnlyHEVC
2022-06-11 18:46:24 +01:00
let feed = JSON.parse(fs.readFileSync('./feedCache.json'));
2022-06-15 18:26:59 +01:00
let retry_show_cache = []
2022-06-16 11:17:56 +01:00
let urls_to_check = []
2022-06-09 10:06:22 +01:00
2022-06-12 16:34:37 +01:00
2022-06-16 07:41:15 +01:00
for (let show of myshowlist) {
try {
// Find show on feed
let list_filtered_for_show = feed.filter(item => item.title.includes(show.Name))
if (list_filtered_for_show.length > 0) {
for (let match of list_filtered_for_show) {
// If show is found get url then return all links on that page
let full_link_list_from_page = await getLinksFromURL(match.link)
if (hevcSwitch) {
// Only get urls with HEVC in name
urls_to_check = full_link_list_from_page.filter(item => item.includes('HEVC'))
if (urls_to_check.length == 0) {
// If no urls with HEVC check for H265
urls_to_check = full_link_list_from_page.filter(item => item.includes('H265'))
}
} else {
urls_to_check = full_link_list_from_page
2022-06-12 16:34:37 +01:00
}
// Only keep urls that match show quality
let urls_with_quality_in_url = urls_to_check.filter(item => item.includes(show.Quality))
// Remove any url trying to direct to a torrent site search
let urls_without_torrent_in_url = urls_with_quality_in_url.filter(item => !item.includes('torrent'))
// Remove any url that doesn't include MeGusta
if (hevcSwitch) {
pre_nitroFlare = urls_without_torrent_in_url.filter(item => item.includes('MeGusta'))
} else {
pre_nitroFlare = urls_without_torrent_in_url
}
// NitroFlare doesn't group with the rest of the links in JD, remove them.
let remove_nitroflare = pre_nitroFlare.filter(item => !item.includes('nitro'))
// Do some stuff
urlObj = checkFileName(remove_nitroflare)
let download_list = urlObj.urlList
// Send Links to JDdownloader
if (download_list.length !== 0) {
log.info(download_list.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader')
linkAdder(download_list)
} else {
// No HEVC links found
log.info(download_list.length + ' links for ' + show.Name + ' have been found, will recheck next time.')
for (let feed_item of list_filtered_for_show) {
retry_show_cache.push(feed_item)
}
2022-06-16 07:41:15 +01:00
}
2022-06-12 16:34:37 +01:00
}
2022-06-16 07:41:15 +01:00
} else {
// Show not found on the current feed cache
log.info(show.Name + ' not on feed')
2022-06-09 10:06:22 +01:00
}
2022-06-16 07:41:15 +01:00
} catch (error) {
log.error('Something went wrong ' + error)
2022-06-15 18:26:59 +01:00
}
2022-06-12 16:34:37 +01:00
}
log.info('Wiping feed cache')
2022-06-15 18:26:59 +01:00
fs.writeFileSync('./feedCache.json', JSON.stringify(retry_show_cache));
2022-06-09 10:06:22 +01:00
}
module.exports = {
filterFeed
}