0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-08 12:35:06 +00:00
VueTube/NUXT/plugins/renderers.js

88 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-03-21 23:47:11 +00:00
import Innertube from "./innertube";
import constants from "./constants";
// Pointer object, give a key and it will return with a method
2022-03-21 23:47:11 +00:00
function useRender(video, renderer) {
switch (renderer) {
case "videoWithContextRenderer":
return videoWithContextRenderer(video);
case "gridVideoRenderer":
return gridVideoRenderer(video);
case "compactAutoplayRenderer":
return compactAutoplayRenderer(video);
case "compactVideoRenderer":
return compactVideoRenderer(video);
2022-03-21 23:47:11 +00:00
default:
return undefined;
}
}
function gridVideoRenderer(video) {
2022-03-21 23:47:11 +00:00
return {
id: video.videoId,
title: video.title?.runs[0].text,
thumbnail: Innertube.getThumbnail(video.videoId, "max"),
channel: video.shortBylineText?.runs[0]
? video.shortBylineText.runs[0].text
: video.longBylineText?.runs[0].text,
channelId: (video.shortBylineText?.runs[0]
? video.shortBylineText.runs[0]
: video.longBylineText?.runs[0]
).navigationEndpoint?.browseEndpoint?.browseId,
channelURL: `${constants.YT_URL}/${
(video.shortBylineText?.runs[0]
? video.shortBylineText.runs[0]
: video.longBylineText?.runs[0]
).navigationEndpoint?.browseEndpoint?.canonicalBaseUrl
}`,
channelThumbnail: video.channelThumbnail?.thumbnails[0],
metadata: {
published: video.publishedTimeText?.runs[0].text,
views: video.shortViewCountText?.runs[0].text,
length: video.lengthText?.runs[0].text,
overlayStyle: video.thumbnailOverlays?.map(
(overlay) => overlay.thumbnailOverlayTimeStatusRenderer?.style
),
overlay: video.thumbnailOverlays?.map(
(overlay) =>
overlay.thumbnailOverlayTimeStatusRenderer?.text.runs[0].text
),
},
};
}
function compactAutoplayRenderer(video) {
video = video.contents;
let item;
if (video) item = video[0];
if (item) return useRender(item[Object.keys(item)[0]], Object.keys(item)[0]);
else return undefined;
}
function compactVideoRenderer(video) {
2022-03-21 23:47:11 +00:00
return {
id: video.videoId,
title: video.title?.runs[0].text,
2022-03-21 23:47:11 +00:00
thumbnail: Innertube.getThumbnail(video.videoId, "max"),
channel: video.shortBylineText?.runs[0].text,
channelURL:
video.shortBylineText?.runs[0].navigationEndpoint?.browseEndpoint
?.canonicalBaseUrl,
channelThumbnail: video.channelThumbnail?.thumbnails[0].url,
2022-03-21 23:47:11 +00:00
metadata: {
views: video.viewCountText?.runs[0].text,
2022-03-21 23:47:11 +00:00
length: video.lengthText?.runs[0].text,
publishedTimeText: video.publishedTimeText.runs[0].text,
2022-03-21 23:47:11 +00:00
overlayStyle: video.thumbnailOverlays?.map(
(overlay) => overlay.thumbnailOverlayTimeStatusRenderer?.style
),
overlay: video.thumbnailOverlays?.map(
(overlay) =>
overlay.thumbnailOverlayTimeStatusRenderer?.text.runs[0].text
),
},
};
}
2022-03-21 23:47:11 +00:00
export default useRender;