mirror of https://github.com/preservetube/auto.git
updating to use invidious for some stuff instead of piped
This commit is contained in:
parent
6e2ebdc7a4
commit
fb1487e960
|
@ -6,22 +6,24 @@ const upload = require('./upload.js')
|
||||||
|
|
||||||
async function createDatabaseVideo(id, videoUrl, playlistId) {
|
async function createDatabaseVideo(id, videoUrl, playlistId) {
|
||||||
const data = await metadata.getVideoMetadata(id)
|
const data = await metadata.getVideoMetadata(id)
|
||||||
const uploaderAvatar = await upload.uploadImage((data.uploaderUrl).replace('/channel/', ''), data.uploaderAvatar)
|
const channelData = await metadata.getChannel(data.authorId)
|
||||||
const thumbnailUrl = await upload.uploadImage(id, data.thumbnailUrl)
|
|
||||||
|
const uploaderAvatar = await upload.uploadImage(data.authorId, channelData.authorThumbnails[1].url)
|
||||||
|
const thumbnailUrl = await upload.uploadImage(id, data.videoThumbnails.find(o => o.quality == 'maxresdefault').url)
|
||||||
|
|
||||||
await prisma.videos.create({
|
await prisma.videos.create({
|
||||||
data: {
|
data: {
|
||||||
id: id,
|
id: id,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: (data.descriptionHtml).replaceAll('\n', '<br>'),
|
||||||
thumbnail: thumbnailUrl,
|
thumbnail: thumbnailUrl,
|
||||||
source: videoUrl,
|
source: videoUrl,
|
||||||
published: data.uploadDate,
|
published: (new Date(data.published*1000)).toISOString().slice(0,10),
|
||||||
archived: (new Date()).toISOString().slice(0,10),
|
archived: (new Date()).toISOString().slice(0,10),
|
||||||
channel: data.uploader,
|
channel: channelData.author,
|
||||||
channelId: (data.uploaderUrl).replace('/channel/', ''),
|
channelId: channelData.authorId,
|
||||||
channelAvatar: uploaderAvatar,
|
channelAvatar: uploaderAvatar,
|
||||||
channelVerified: data.uploaderVerified,
|
channelVerified: channelData.authorVerified,
|
||||||
playlist: playlistId
|
playlist: playlistId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,51 +1,18 @@
|
||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
|
|
||||||
async function getInstance() {
|
async function getInstance() {
|
||||||
for (let i = 0; i < 5; i++) {
|
return 'https://invidious.lain.la'
|
||||||
const test = await actualRequest()
|
|
||||||
if (test) return test
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getActualInstance() {
|
|
||||||
const instances = await (await fetch('https://piped-instances.kavin.rocks/')).json()
|
|
||||||
return (instances[Math.floor(Math.random() * instances.length)]).api_url
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testInstance(instance) {
|
|
||||||
try {
|
|
||||||
const videoRequest = await fetch(`${instance}/streams/dQw4w9WgXcQ`)
|
|
||||||
const videoJson = await videoRequest.json()
|
|
||||||
const thumbnailRequest = await fetch(videoJson.thumbnailUrl)
|
|
||||||
|
|
||||||
return (videoRequest.status == 200) && (thumbnailRequest.status == 200)
|
|
||||||
} catch (e) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function actualRequest() {
|
|
||||||
try {
|
|
||||||
const instance = await getActualInstance()
|
|
||||||
const instanceTest = await testInstance(instance)
|
|
||||||
|
|
||||||
if (instanceTest) return instance
|
|
||||||
else return false
|
|
||||||
} catch (e) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVideoMetadata(id) {
|
async function getVideoMetadata(id) {
|
||||||
const instance = await getInstance()
|
const instance = await getInstance()
|
||||||
const json = await (await fetch(`${instance}/streams/${id}`)).json()
|
const json = await (await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId&pretty=1`)).json()
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannel(id) {
|
async function getChannel(id) {
|
||||||
const instance = await getInstance()
|
const instance = await getInstance()
|
||||||
const json = await (await fetch(`${instance}/channel/${id}`)).json()
|
const json = await (await fetch(`${instance}/api/v1/channels/${id}?pretty=1`)).json()
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +20,7 @@ async function getChannelVideos(id) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const videos = []
|
const videos = []
|
||||||
const instance = await getInstance()
|
const instance = 'https://pipedapi.kavin.rocks'
|
||||||
const json = await (await fetch(`${instance}/channel/${id}`)).json()
|
const json = await (await fetch(`${instance}/channel/${id}`)).json()
|
||||||
videos.push(...json.relatedStreams)
|
videos.push(...json.relatedStreams)
|
||||||
if (json.nextpage) await getNextPage(json.nextpage)
|
if (json.nextpage) await getNextPage(json.nextpage)
|
||||||
|
@ -75,7 +42,7 @@ async function getChannelVideos(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPlaylistVideos(id) {
|
async function getPlaylistVideos(id) {
|
||||||
const instance = await getInstance()
|
const instance = 'https://pipedapi.kavin.rocks'
|
||||||
const json = await (await fetch(`${instance}/playlists/${id}`)).json()
|
const json = await (await fetch(`${instance}/playlists/${id}`)).json()
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue