JDRssDownloader/FeedFilter.js

88 lines
4.2 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-18 13:44:16 +01:00
const { checkDownloadHistory } = require('./checkDownloadHistory')
2023-01-24 12:04:14 +00:00
const { retryCache } = require('./retryCache')
2022-06-09 10:06:22 +01:00
2022-06-09 10:29:05 +01:00
async function filterFeed() {
2022-06-12 16:34:37 +01:00
let hevcSwitch = JSON.parse(fs.readFileSync('config.json')).OnlyHEVC
2022-10-26 10:15:08 +01:00
let myshowlist = JSON.parse(fs.readFileSync('shows.json'))
2023-01-24 12:04:14 +00:00
let rssFeed = JSON.parse(fs.readFileSync('./cache/feedCache.json'));
let retryCacheData = retryCache()
let fullFeedToCheck = retryCacheData.concat(rssFeed)
let urlsToCheck = []
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
2023-01-24 12:04:14 +00:00
let listFilteredForShow = fullFeedToCheck.filter(item => item.title.includes(show.Name))
if (listFilteredForShow.length > 0) {
for (let match of listFilteredForShow) {
// If show is found get url then return all links on that page
let fullLinkListFromPage = await getLinksFromURL(match.link)
if (hevcSwitch) {
// Only get urls with HEVC in name
urlsToCheck = fullLinkListFromPage.filter(item => item.includes('HEVC'))
if (urlsToCheck.length == 0) {
// If no urls with HEVC check for H265
urlsToCheck = fullLinkListFromPage.filter(item => item.includes('H265'))
}
} else {
urlsToCheck = fullLinkListFromPage
2022-06-12 16:34:37 +01:00
}
// Only keep urls that match show quality
let urlsWithQualityInUrl = urlsToCheck.filter(item => item.includes(show.Quality))
// Remove any url trying to direct to a torrent site search
let urlsWithoutTorrentInUrl = urlsWithQualityInUrl.filter(item => !item.includes('torrent'))
// Remove any url that doesn't include MeGusta
if (hevcSwitch) {
preNitroflare = urlsWithoutTorrentInUrl.filter(item => item.includes('MeGusta'))
} else {
preNitroflare = urlsWithoutTorrentInUrl
}
// NitroFlare doesn't group with the rest of the links in JD, remove them.
let removeNitroflare = preNitroflare.filter(item => !item.includes('nitro'))
// Do some stuff
urlObj = checkFileName(removeNitroflare)
let downloadList = urlObj.urlList
// Send Links to JDdownloader
if (downloadList.length !== 0) {
2022-06-18 13:44:16 +01:00
if (checkDownloadHistory(urlObj)) {
log.info(urlObj.fileName + ' already downloaded, skipped.')
break
} else {
log.tele(downloadList.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.')
linkAdder(downloadList)
global.linkCheckTime = new Date();
2022-06-18 13:44:16 +01:00
}
} else {
// No HEVC links found
log.info(downloadList.length + ' links for ' + show.Name + ' have been found, will recheck next time.')
for (let feedItem of listFilteredForShow) {
2023-01-24 12:04:14 +00:00
retryCache(feedItem)
}
global.linkCheckTime = new Date();
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)
global.linkCheckTime = new Date();
2022-06-15 18:26:59 +01:00
}
2022-06-12 16:34:37 +01:00
}
log.info('Wiping feed cache')
2023-01-24 12:04:14 +00:00
fs.writeFileSync('./cache/feedCache.json', JSON.stringify([]));
global.linkCheckTime = new Date();
2022-06-09 10:06:22 +01:00
}
module.exports = {
filterFeed
}