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)
|
2022-10-25 17:09:29 +01:00
|
|
|
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))
|
2022-10-25 17:09:29 +01:00
|
|
|
if (listFilteredForShow.length > 0) {
|
|
|
|
for (let match of listFilteredForShow) {
|
2022-06-18 10:08:05 +01:00
|
|
|
// If show is found get url then return all links on that page
|
2022-10-25 17:09:29 +01:00
|
|
|
let fullLinkListFromPage = await getLinksFromURL(match.link)
|
2022-06-18 10:08:05 +01:00
|
|
|
if (hevcSwitch) {
|
|
|
|
// Only get urls with HEVC in name
|
2022-10-25 17:09:29 +01:00
|
|
|
urlsToCheck = fullLinkListFromPage.filter(item => item.includes('HEVC'))
|
|
|
|
if (urlsToCheck.length == 0) {
|
2022-06-18 10:08:05 +01:00
|
|
|
// If no urls with HEVC check for H265
|
2022-10-25 17:09:29 +01:00
|
|
|
urlsToCheck = fullLinkListFromPage.filter(item => item.includes('H265'))
|
2022-06-18 10:08:05 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-25 17:09:29 +01:00
|
|
|
urlsToCheck = fullLinkListFromPage
|
2022-06-12 16:34:37 +01:00
|
|
|
}
|
2022-06-18 10:08:05 +01:00
|
|
|
// Only keep urls that match show quality
|
2022-10-25 17:09:29 +01:00
|
|
|
let urlsWithQualityInUrl = urlsToCheck.filter(item => item.includes(show.Quality))
|
2022-06-18 10:08:05 +01:00
|
|
|
// Remove any url trying to direct to a torrent site search
|
2022-10-25 17:09:29 +01:00
|
|
|
let urlsWithoutTorrentInUrl = urlsWithQualityInUrl.filter(item => !item.includes('torrent'))
|
2022-06-18 10:08:05 +01:00
|
|
|
// Remove any url that doesn't include MeGusta
|
|
|
|
if (hevcSwitch) {
|
2022-10-25 17:09:29 +01:00
|
|
|
preNitroflare = urlsWithoutTorrentInUrl.filter(item => item.includes('MeGusta'))
|
2022-06-18 10:08:05 +01:00
|
|
|
} else {
|
2022-10-25 17:09:29 +01:00
|
|
|
preNitroflare = urlsWithoutTorrentInUrl
|
2022-06-18 10:08:05 +01:00
|
|
|
}
|
|
|
|
// NitroFlare doesn't group with the rest of the links in JD, remove them.
|
2022-10-25 17:09:29 +01:00
|
|
|
let removeNitroflare = preNitroflare.filter(item => !item.includes('nitro'))
|
2022-06-18 10:08:05 +01:00
|
|
|
// Do some stuff
|
2022-10-25 17:09:29 +01:00
|
|
|
urlObj = checkFileName(removeNitroflare)
|
|
|
|
let downloadList = urlObj.urlList
|
2022-06-18 10:08:05 +01:00
|
|
|
// Send Links to JDdownloader
|
2022-10-25 17:09:29 +01:00
|
|
|
if (downloadList.length !== 0) {
|
2022-06-18 13:44:16 +01:00
|
|
|
if (checkDownloadHistory(urlObj)) {
|
|
|
|
log.info(urlObj.fileName + ' already downloaded, skipped.')
|
|
|
|
break
|
|
|
|
} else {
|
2022-10-25 17:09:29 +01:00
|
|
|
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
|
|
|
}
|
2022-06-18 10:08:05 +01:00
|
|
|
} else {
|
|
|
|
// No HEVC links found
|
2022-10-25 17:09:29 +01:00
|
|
|
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)
|
2022-06-18 10:08:05 +01:00
|
|
|
}
|
2022-10-25 17:09:29 +01:00
|
|
|
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)
|
2022-10-25 17:09:29 +01:00
|
|
|
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([]));
|
2022-10-25 17:09:29 +01:00
|
|
|
global.linkCheckTime = new Date();
|
2022-06-09 10:06:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
filterFeed
|
|
|
|
}
|
|
|
|
|