diff --git a/controller/video.js b/controller/video.js index 599bec1..36b45ad 100644 --- a/controller/video.js +++ b/controller/video.js @@ -79,9 +79,9 @@ exports.getChannel = async (req, res) => { allVideos.sort((a, b) => new Date(b.published) - new Date(a.published)) res.json({ - name: channel.name, - avatar: channel.avatarUrl, - verified: channel.verified, + name: channel.author, + avatar: channel.authorThumbnails[1].url, + verified: channel.authorVerified, videos: allVideos }) } diff --git a/utils/metadata.js b/utils/metadata.js index 849fefc..e08992c 100644 --- a/utils/metadata.js +++ b/utils/metadata.js @@ -1,37 +1,18 @@ const fetch = require('node-fetch') async function getInstance() { - const instances = [ - '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)] + 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,error&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 } @@ -39,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) @@ -61,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 } diff --git a/utils/websocket.js b/utils/websocket.js index c062865..0a61ce3 100644 --- a/utils/websocket.js +++ b/utils/websocket.js @@ -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', '
'), 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 } })