diff --git a/materialious/src/lib/Api/index.ts b/materialious/src/lib/Api/index.ts index 01d055a7..8c16fc0a 100644 --- a/materialious/src/lib/Api/index.ts +++ b/materialious/src/lib/Api/index.ts @@ -1,6 +1,6 @@ import { get } from 'svelte/store'; import { invidiousInstance, returnYTDislikesInstance } from '../../store'; -import type { Comments, ReturnYTDislikes, Video, VideoPlay } from './model'; +import type { Channel, Comments, ReturnYTDislikes, Video, VideoPlay } from './model'; export function buildPath(path: string): string { return `${get(invidiousInstance)}/api/v1/${path}`; @@ -26,4 +26,9 @@ export async function getComments(videoId: string, parameters: { sortBy: "top" | path.search = new URLSearchParams(parameters).toString(); const resp = await fetch(path); return await resp.json(); +} + +export async function getChannel(channelId: string): Promise { + const resp = await fetch(buildPath(`channels/${channelId}`)); + return await resp.json(); } \ No newline at end of file diff --git a/materialious/src/lib/Api/model.ts b/materialious/src/lib/Api/model.ts index 2d831d8c..5d931bf8 100644 --- a/materialious/src/lib/Api/model.ts +++ b/materialious/src/lib/Api/model.ts @@ -72,12 +72,6 @@ export interface Captions { url: string; }; -export interface AuthorThumbnails { - url: string; - width: string; - height: string; -} - export interface VideoPlay extends Video { keywords: string[]; likeCount: number; @@ -94,7 +88,7 @@ export interface VideoPlay extends Video { adaptiveFormats: AdaptiveFormats[]; formatStreams: FormatStreams[]; recommendedVideos: VideoBase[]; - authorThumbnails: AuthorThumbnails[]; + authorThumbnails: Image[]; captions: Captions[]; } @@ -110,7 +104,7 @@ export interface ReturnYTDislikes { export interface Comment { author: string; - authorThumbnails: AuthorThumbnails[]; + authorThumbnails: Image[]; authorID: string; authorUrl: string; isEdited: boolean; @@ -136,4 +130,23 @@ export interface Comments { videoId: string; continuation?: string; comments: Comment[]; +} + +export interface Channel { + author: string; + authorId: string; + authorUrl: string; + authorVerified: boolean; + authorBanners: Image[]; + authorThumbnails: Image[]; + subCount: number; + totalViews: number; + joined: number; + autoGenerated: boolean; + isFamilyFriendly: boolean; + description: string; + descriptionHml: string; + allowedRegions: string[]; + tabs: string[]; + latestVideos: Video[]; } \ No newline at end of file diff --git a/materialious/src/lib/misc.ts b/materialious/src/lib/misc.ts index e9fa7648..e40ad63d 100644 --- a/materialious/src/lib/misc.ts +++ b/materialious/src/lib/misc.ts @@ -1,7 +1,13 @@ +import humanNumber from "human-number"; + export function truncate(value: string, maxLength: number = 50): string { return value.length > maxLength ? `${value.substring(0, maxLength)}...` : value; } export function numberWithCommas(number: number) { return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); +} + +export function cleanNumber(number: number): string { + return humanNumber(number, (number: number) => Number.parseFloat(number.toString()).toFixed(1)); } \ No newline at end of file diff --git a/materialious/src/routes/channel/[slug]/+page.svelte b/materialious/src/routes/channel/[slug]/+page.svelte index e69de29b..53a3668e 100644 --- a/materialious/src/routes/channel/[slug]/+page.svelte +++ b/materialious/src/routes/channel/[slug]/+page.svelte @@ -0,0 +1,44 @@ + + +
+ {#if data.channel.authorBanners.length > 0} + Channel banner + {/if} +
+ Channel profile +
+

{data.channel.author}

+

{cleanNumber(data.channel.subCount)} subscribers

+

{data.channel.description}

+
+ +
+ +
+ +
+ {#each data.channel.latestVideos as video} +
+ +
+ {/each} +
+
+ + diff --git a/materialious/src/routes/channel/[slug]/+page.ts b/materialious/src/routes/channel/[slug]/+page.ts index e69de29b..28228442 100644 --- a/materialious/src/routes/channel/[slug]/+page.ts +++ b/materialious/src/routes/channel/[slug]/+page.ts @@ -0,0 +1,7 @@ +import { getChannel } from '$lib/Api/index.js'; + +export async function load({ params }) { + return { + channel: await getChannel(params.slug) + }; +} \ No newline at end of file diff --git a/materialious/src/routes/watch/[slug]/+page.svelte b/materialious/src/routes/watch/[slug]/+page.svelte index 9a4f5036..bdb1af21 100644 --- a/materialious/src/routes/watch/[slug]/+page.svelte +++ b/materialious/src/routes/watch/[slug]/+page.svelte @@ -1,22 +1,17 @@