Added functionality to trending page
parent
ee1bab191f
commit
9c1a95e3ff
@ -0,0 +1,45 @@
|
||||
import { Video } from "@interfaces/video";
|
||||
|
||||
export interface Channel {
|
||||
author: string;
|
||||
authorId: string;
|
||||
authorUrl: string;
|
||||
authorBanners: AuthorBanner[];
|
||||
authorThumbnails: AuthorBanner[];
|
||||
subCount: number;
|
||||
totalViews: number;
|
||||
joined: number;
|
||||
autoGenerated: boolean;
|
||||
isFamilyFriendly: boolean;
|
||||
description: string;
|
||||
descriptionHtml: string;
|
||||
allowedRegions: string[];
|
||||
latestVideos: Video[];
|
||||
relatedChannels: RelatedChannel[];
|
||||
}
|
||||
|
||||
export interface AuthorBanner {
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
quality?: Quality;
|
||||
}
|
||||
|
||||
export enum Quality {
|
||||
Default = "default",
|
||||
End = "end",
|
||||
High = "high",
|
||||
Maxres = "maxres",
|
||||
Maxresdefault = "maxresdefault",
|
||||
Medium = "medium",
|
||||
Middle = "middle",
|
||||
Sddefault = "sddefault",
|
||||
Start = "start"
|
||||
}
|
||||
|
||||
export interface RelatedChannel {
|
||||
author: string;
|
||||
authorId: string;
|
||||
authorUrl: string;
|
||||
authorThumbnails: AuthorBanner[];
|
||||
}
|
@ -1,6 +1,46 @@
|
||||
export interface Video {
|
||||
thumbnail: string;
|
||||
title: string;
|
||||
description: string;
|
||||
description: {
|
||||
text: string;
|
||||
html: string;
|
||||
};
|
||||
id: string;
|
||||
author: {
|
||||
name: string;
|
||||
id: string;
|
||||
url: string;
|
||||
};
|
||||
views: number;
|
||||
published: {
|
||||
time: number;
|
||||
text: string;
|
||||
};
|
||||
length: number;
|
||||
}
|
||||
|
||||
export interface Trending {
|
||||
type: string;
|
||||
title: string;
|
||||
videoId: string;
|
||||
author: string;
|
||||
authorId: string;
|
||||
authorUrl: string;
|
||||
videoThumbnails: VideoThumbnail[];
|
||||
description: string;
|
||||
descriptionHtml: string;
|
||||
viewCount: number;
|
||||
published: number;
|
||||
publishedText: string;
|
||||
lengthSeconds: number;
|
||||
liveNow: boolean;
|
||||
premium: boolean;
|
||||
isUpcoming: boolean;
|
||||
}
|
||||
|
||||
interface VideoThumbnail {
|
||||
quality: string;
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
import { Trending, Video } from "@interfaces/video";
|
||||
|
||||
export const trendingToVideo = (item: Trending): Video => {
|
||||
return {
|
||||
title: item.title,
|
||||
description: {
|
||||
text: item.description,
|
||||
html: item.descriptionHtml
|
||||
},
|
||||
id: item.videoId,
|
||||
author: {
|
||||
name: item.author,
|
||||
id: item.authorId,
|
||||
url: item.authorUrl
|
||||
},
|
||||
length: item.lengthSeconds,
|
||||
published: {
|
||||
time: item.published,
|
||||
text: item.publishedText
|
||||
},
|
||||
views: item.viewCount,
|
||||
thumbnail: item.videoThumbnails.find(
|
||||
(thumbnail) => thumbnail.quality == "maxresdefault"
|
||||
)?.url as string
|
||||
};
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
export const abbreviateNumber = (value: number): string => {
|
||||
const suffixes = ["", "K", "M", "B", "T"];
|
||||
|
||||
let suffixNum = 0;
|
||||
|
||||
while (value >= 1000) {
|
||||
value /= 1000;
|
||||
suffixNum++;
|
||||
}
|
||||
|
||||
value = parseInt(value.toPrecision(3));
|
||||
|
||||
return `${value}${suffixes[suffixNum]}`;
|
||||
};
|
Loading…
Reference in new issue