watch: simple backend for video info
continuous-integration/drone/push Build is passing Details

nextui
Guus van Meerveld 8 months ago
parent e9d7ea3621
commit b77771029e

@ -2,6 +2,7 @@
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { useSearchParams } from "next/navigation"; import { useSearchParams } from "next/navigation";
import { useMemo } from "react";
import { useClient } from "@/hooks/useClient"; import { useClient } from "@/hooks/useClient";
@ -12,13 +13,16 @@ export const Watch: Component = () => {
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const videoId = searchParams.get("v"); const videoId = searchParams.get("v") as string;
const videoIdIsInvalid = useMemo(() => videoId === null, [videoId]);
const { data, error } = useQuery({ const { data, error } = useQuery({
queryKey: ["watch", videoId], queryKey: ["watch", videoId],
queryFn: () => { queryFn: () => {
return client.getStream(videoId ?? ""); return client.getStream(videoId);
} },
enabled: !videoIdIsInvalid
}); });
console.log(data, error); console.log(data, error);

@ -1,7 +1,7 @@
import { SearchResults } from "@/client/typings/search"; import { SearchResults } from "@/client/typings/search";
import { SearchOptions } from "@/client/typings/search/options"; import { SearchOptions } from "@/client/typings/search/options";
import { Stream } from "@/client/typings/search/stream";
import { Suggestions } from "@/client/typings/search/suggestions"; import { Suggestions } from "@/client/typings/search/suggestions";
import { Stream } from "@/client/typings/stream";
import { Video } from "@/client/typings/video"; import { Video } from "@/client/typings/video";
export interface ConnectedAdapter { export interface ConnectedAdapter {

@ -31,9 +31,7 @@ export default class Transformer {
return thumbnail?.url ?? null; return thumbnail?.url ?? null;
} }
private static recommendedVideo( private static recommendedVideo(data: InvidiousRecommendedVideo): VideoItem {
data: InvidiousRecommendedVideo
): RecommendedVideo {
const thumbnail = Transformer.findBestThumbnail(data.videoThumbnails); const thumbnail = Transformer.findBestThumbnail(data.videoThumbnails);
if (thumbnail === null) if (thumbnail === null)
@ -42,6 +40,8 @@ export default class Transformer {
); );
return { return {
type: "video",
uploaded: new Date(),
author: { id: data.authorId, name: data.author }, author: { id: data.authorId, name: data.author },
duration: data.lengthSeconds * 1000, duration: data.lengthSeconds * 1000,
live: data.liveNow, live: data.liveNow,

@ -82,7 +82,6 @@ export default class Transformer {
uploaded: new Date(data.uploaded), uploaded: new Date(data.uploaded),
thumbnail: data.thumbnail, thumbnail: data.thumbnail,
title: data.title, title: data.title,
description: "",
live: false, live: false,
author: { author: {
id: channelId, id: channelId,

@ -73,8 +73,8 @@ export const StreamModel = z.object({
uploaderAvatar: z.string().url(), uploaderAvatar: z.string().url(),
thumbnailUrl: z.string().url(), thumbnailUrl: z.string().url(),
hls: z.string().url(), hls: z.string().url(),
dash: z.null(), dash: z.string().url().nullable(),
lbryId: z.null(), lbryId: z.string().nullable(),
category: z.string(), category: z.string(),
license: z.string(), license: z.string(),
visibility: z.string(), visibility: z.string(),

@ -7,7 +7,7 @@ export interface Video {
avatar?: string; avatar?: string;
}; };
thumbnail: string; thumbnail: string;
description: string; description?: string;
/* /*
Duration in milliseconds. Duration in milliseconds.
*/ */

@ -7,8 +7,8 @@ export const useClient = (): Client => {
const [client] = useState( const [client] = useState(
() => () =>
new Client([ new Client([
// { baseUrl: "https://invidious.fdn.fr/", type: ApiType.Invidious } { baseUrl: "https://invidious.fdn.fr/", type: ApiType.Invidious }
{ baseUrl: "https://pipedapi.kavin.rocks", type: ApiType.Piped } // { baseUrl: "https://pipedapi.kavin.rocks", type: ApiType.Piped }
]) ])
); );

Loading…
Cancel
Save