trending: limited thumbnails to 1 per video
parent
61b54c4081
commit
dc9d17ec74
@ -0,0 +1,3 @@
|
||||
{
|
||||
"prettier.configPath": ".prettierrc.json"
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
import { TrendingVideo } from "@/client/typings/trending";
|
||||
import { Component } from "@/typings/component";
|
||||
import { Card, CardFooter, CardBody } from "@nextui-org/card";
|
||||
import { Image } from "@nextui-org/image";
|
||||
import { Divider } from "@nextui-org/divider";
|
||||
import Link from "next/link";
|
||||
import formatNumber from "@/utils/formatNumbers";
|
||||
|
||||
export const VideoCard: Component<{ data: TrendingVideo }> = ({
|
||||
data: video
|
||||
}) => {
|
||||
return (
|
||||
<Link key={video.id} href={`/watch?v=${video.id}`}>
|
||||
<Card radius="lg">
|
||||
<CardBody>
|
||||
<Image
|
||||
alt={video.title}
|
||||
className="object-cover"
|
||||
height={400}
|
||||
src={video.thumbnail}
|
||||
width={600}
|
||||
/>
|
||||
<p className="text-small rounded-md z-10 absolute bottom-5 right-5 bg-content2 p-1">
|
||||
{video.duration}
|
||||
</p>
|
||||
</CardBody>
|
||||
<Divider />
|
||||
<CardFooter>
|
||||
<div className="max-w-full">
|
||||
<p title={video.title} className="truncate">
|
||||
{video.title}
|
||||
</p>
|
||||
<div className="flex flex-row gap-2 justify-start overflow-scroll">
|
||||
<p className="text-small tracking-tight text-default-400">
|
||||
{video.author.name}
|
||||
</p>
|
||||
<p className="text-small tracking-tight text-default-400">
|
||||
{video.uploaded.toLocaleDateString()}
|
||||
</p>
|
||||
|
||||
<p className="text-small tracking-tight text-default-400">
|
||||
Views: {formatNumber(video.views)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</Link>
|
||||
);
|
||||
};
|
@ -1,23 +1,31 @@
|
||||
import { TrendingVideo } from "@/client/typings/trending";
|
||||
import { Thumbnail } from "@/client/typings/thumbnail";
|
||||
|
||||
import InvidiousTrending from "./typings/trending";
|
||||
import InvidiousThumbnail from "./typings/thumbnail";
|
||||
|
||||
export default class Transformer {
|
||||
public static thumbnails(data: InvidiousThumbnail[]): Thumbnail[] {
|
||||
return data.map((thumbnail) => ({ url: thumbnail.url }));
|
||||
}
|
||||
|
||||
public static trending(data: InvidiousTrending[]): TrendingVideo[] {
|
||||
return data.map((video) => ({
|
||||
author: { id: video.authorId, name: video.author },
|
||||
duration: video.lengthSeconds * 1000,
|
||||
id: video.videoId,
|
||||
title: video.title,
|
||||
thumbnails: Transformer.thumbnails(video.videoThumbnails),
|
||||
uploaded: new Date(video.published * 1000 ?? 0),
|
||||
views: video.viewCount
|
||||
}));
|
||||
return data.map((video) => {
|
||||
const thumbnail = video.videoThumbnails.find(
|
||||
(thumbnail) =>
|
||||
thumbnail.quality == "default" ||
|
||||
thumbnail.quality == "medium" ||
|
||||
thumbnail.quality == "middle"
|
||||
);
|
||||
|
||||
if (thumbnail === undefined)
|
||||
throw new Error(
|
||||
`Invidious: Missing thumbnail for video with id ${video.videoId}`
|
||||
);
|
||||
|
||||
return {
|
||||
author: { id: video.authorId, name: video.author },
|
||||
duration: video.lengthSeconds * 1000,
|
||||
id: video.videoId,
|
||||
title: video.title,
|
||||
thumbnail: thumbnail.url,
|
||||
uploaded: new Date(video.published * 1000 ?? 0),
|
||||
views: video.viewCount
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
export interface Thumbnail {
|
||||
url: string;
|
||||
}
|
Loading…
Reference in new issue