updating to use invidious for some stuff instead of piped
This commit is contained in:
parent
3302de2430
commit
e023b92c28
|
@ -79,9 +79,9 @@ exports.getChannel = async (req, res) => {
|
||||||
allVideos.sort((a, b) => new Date(b.published) - new Date(a.published))
|
allVideos.sort((a, b) => new Date(b.published) - new Date(a.published))
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
name: channel.name,
|
name: channel.author,
|
||||||
avatar: channel.avatarUrl,
|
avatar: channel.authorThumbnails[1].url,
|
||||||
verified: channel.verified,
|
verified: channel.authorVerified,
|
||||||
videos: allVideos
|
videos: allVideos
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,18 @@
|
||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
|
|
||||||
async function getInstance() {
|
async function getInstance() {
|
||||||
const instances = [
|
return 'https://invidious.lain.la'
|
||||||
'https://pipedapi.kavin.rocks',
|
|
||||||
'https://pipedapi-libre.kavin.rocks',
|
|
||||||
'https://piped-api.privacy.com.de',
|
|
||||||
'https://api.piped.projectsegfau.lt',
|
|
||||||
'https://pipedapi.in.projectsegfau.lt',
|
|
||||||
'https://pipedapi.us.projectsegfau.lt',
|
|
||||||
'https://watchapi.whatever.social',
|
|
||||||
'https://api.piped.privacydev.net',
|
|
||||||
'https://pipedapi.palveluntarjoaja.eu',
|
|
||||||
'https://pipedapi.smnz.de',
|
|
||||||
'https://pipedapi.adminforge.de',
|
|
||||||
'https://pipedapi.qdi.fi',
|
|
||||||
'https://piped-api.hostux.net',
|
|
||||||
'https://api.piped.yt',
|
|
||||||
'https://pipedapi.osphost.fi',
|
|
||||||
'https://pipedapi.simpleprivacy.fr'
|
|
||||||
]
|
|
||||||
|
|
||||||
return instances[Math.floor(Math.random() * instances.length)]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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,error&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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,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)
|
||||||
|
@ -61,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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue