identifying myself + making the gap bigger between scans

This commit is contained in:
localhost 2023-10-19 18:12:19 +02:00
parent df6416aec8
commit 9b93242ff4
2 changed files with 36 additions and 8 deletions

View File

@ -137,4 +137,4 @@ channelQueue.process(10, async function (job, done) {
check()
setInterval(() => {
check()
}, 300000)
}, 15 * 60000)

View File

@ -2,13 +2,21 @@ const fetch = require('node-fetch')
const maxRetries = 5
async function getInstance() {
const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1')).json()
const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1', {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})).json()
const sorted = instances.filter(o => o[1].type == 'https' && o[0] != 'invidious.io.lol' && o[0] != 'invidious.0011.lt')
return `https://${sorted[Math.floor(Math.random() * sorted.length)][0]}`
}
async function getPipedInstance() {
const instances = await (await fetch('https://piped-instances.kavin.rocks/')).json()
const instances = await (await fetch('https://piped-instances.kavin.rocks/', {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})).json()
return (instances[Math.floor(Math.random() * instances.length)]).api_url
}
@ -16,7 +24,11 @@ async function getVideoMetadata(id) {
for (let retries = 0; retries < maxRetries; retries++) {
try {
const instance = await getInstance()
const response = await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId&pretty=1`)
const response = await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId&pretty=1`, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})
if (response.ok) {
const json = await response.json()
@ -36,7 +48,11 @@ async function getChannel(id) {
for (let retries = 0; retries < maxRetries; retries++) {
try {
const instance = await getInstance()
const response = await fetch(`${instance}/api/v1/channels/${id}?pretty=1`)
const response = await fetch(`${instance}/api/v1/channels/${id}?pretty=1`, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})
if (response.ok) {
const json = await response.json()
@ -57,13 +73,21 @@ async function getChannelVideos(id) {
try {
const videos = []
const instance = await getPipedInstance()
const json = await (await fetch(`${instance}/channel/${id}`)).json()
const json = await (await fetch(`${instance}/channel/${id}`, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})).json()
videos.push(...json.relatedStreams)
if (json.nextpage) await getNextPage(json.nextpage)
else resolve(videos)
async function getNextPage(payload) {
const page = await (await fetch(`${instance}/nextpage/channel/${id}?nextpage=${encodeURIComponent(payload)}`)).json()
const page = await (await fetch(`${instance}/nextpage/channel/${id}?nextpage=${encodeURIComponent(payload)}`, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})).json()
videos.push(...page.relatedStreams)
if (videos.length >= 120) return resolve(videos)
@ -79,7 +103,11 @@ async function getChannelVideos(id) {
async function getPlaylistVideos(id) {
const instance = await getPipedInstance()
const json = await (await fetch(`${instance}/playlists/${id}`)).json()
const json = await (await fetch(`${instance}/playlists/${id}`, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; PreserveTube/0.0; +https://preservetube.com)'
}
})).json()
return json
}