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) {
|
||||
const data = await metadata.getVideoMetadata(id)
|
||||
const uploaderAvatar = await upload.uploadImage((data.uploaderUrl).replace('/channel/', ''), data.uploaderAvatar)
|
||||
const thumbnailUrl = await upload.uploadImage(id, data.thumbnailUrl)
|
||||
const channelData = await metadata.getChannel(data.authorId)
|
||||
|
||||
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({
|
||||
data: {
|
||||
id: id,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
description: (data.descriptionHtml).replaceAll('\n', '<br>'),
|
||||
thumbnail: thumbnailUrl,
|
||||
source: videoUrl,
|
||||
published: data.uploadDate,
|
||||
published: (new Date(data.published*1000)).toISOString().slice(0,10),
|
||||
archived: (new Date()).toISOString().slice(0,10),
|
||||
channel: data.uploader,
|
||||
channelId: (data.uploaderUrl).replace('/channel/', ''),
|
||||
channel: channelData.author,
|
||||
channelId: channelData.authorId,
|
||||
channelAvatar: uploaderAvatar,
|
||||
channelVerified: data.uploaderVerified,
|
||||
channelVerified: channelData.authorVerified,
|
||||
playlist: playlistId
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,51 +1,18 @@
|
|||
const fetch = require('node-fetch')
|
||||
|
||||
async function getInstance() {
|
||||
for (let i = 0; i < 5; i++) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return 'https://invidious.lain.la'
|
||||
}
|
||||
|
||||
async function getVideoMetadata(id) {
|
||||
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
|
||||
}
|
||||
|
||||
async function getChannel(id) {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -53,7 +20,7 @@ async function getChannelVideos(id) {
|
|||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const videos = []
|
||||
const instance = await getInstance()
|
||||
const instance = 'https://pipedapi.kavin.rocks'
|
||||
const json = await (await fetch(`${instance}/channel/${id}`)).json()
|
||||
videos.push(...json.relatedStreams)
|
||||
if (json.nextpage) await getNextPage(json.nextpage)
|
||||
|
@ -75,7 +42,7 @@ async function getChannelVideos(id) {
|
|||
}
|
||||
|
||||
async function getPlaylistVideos(id) {
|
||||
const instance = await getInstance()
|
||||
const instance = 'https://pipedapi.kavin.rocks'
|
||||
const json = await (await fetch(`${instance}/playlists/${id}`)).json()
|
||||
return json
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue