From c29052ca617674cdf6c72aa9c4af8c78b7af2236 Mon Sep 17 00:00:00 2001 From: Guus van Meerveld Date: Thu, 4 Apr 2024 00:09:36 +0200 Subject: [PATCH] watch: very basic video player --- package.json | 1 + src/app/watch/Description.tsx | 33 +-- src/app/watch/Player.tsx | 11 - src/app/watch/Player/index.tsx | 209 +++++++++++++++++++ src/app/watch/Watch.tsx | 15 +- src/client/adapters/index.ts | 4 +- src/client/adapters/invidious/index.ts | 2 +- src/client/adapters/invidious/transformer.ts | 46 ++-- src/client/adapters/piped/index.ts | 2 +- src/client/adapters/piped/transformer.ts | 13 +- src/client/index.ts | 6 +- src/client/typings/stream.ts | 38 +++- src/client/typings/watchable.ts | 13 ++ src/components/Author.tsx | 6 +- src/hooks/useClient.ts | 4 +- yarn.lock | 30 ++- 16 files changed, 357 insertions(+), 76 deletions(-) delete mode 100644 src/app/watch/Player.tsx create mode 100644 src/app/watch/Player/index.tsx create mode 100644 src/client/typings/watchable.ts diff --git a/package.json b/package.json index 8504c23..c342491 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "react": "^18", "react-dom": "^18", "react-icons": "^5.0.1", + "react-player": "^2.15.1", "reactjs-visibility": "^0.1.4", "sanitize-html": "^2.13.0", "use-debounce": "^10.0.0", diff --git a/src/app/watch/Description.tsx b/src/app/watch/Description.tsx index b046948..40559b4 100644 --- a/src/app/watch/Description.tsx +++ b/src/app/watch/Description.tsx @@ -30,13 +30,16 @@ export const Description: Component<{ data: string }> = ({ data }) => { [data] ); - const descriptionCut = useMemo( - () => - expandedDescription - ? sanitizedDescription - : sanitizedDescription.substring(0, shortenedDescriptionLength) + "...", - [sanitizedDescription, expandedDescription] - ); + const descriptionAlreadyShort = sanitizedDescription.length <= 200; + + const descriptionCut = useMemo(() => { + if (descriptionAlreadyShort) return sanitizedDescription; + else if (expandedDescription) return sanitizedDescription; + else + return ( + sanitizedDescription.substring(0, shortenedDescriptionLength) + "..." + ); + }, [sanitizedDescription, descriptionAlreadyShort, expandedDescription]); const description = useMemo( () => highlight(descriptionCut), @@ -48,13 +51,15 @@ export const Description: Component<{ data: string }> = ({ data }) => {

- + {!descriptionAlreadyShort && ( + + )} ); }; diff --git a/src/app/watch/Player.tsx b/src/app/watch/Player.tsx deleted file mode 100644 index 392967f..0000000 --- a/src/app/watch/Player.tsx +++ /dev/null @@ -1,11 +0,0 @@ -"use client"; - -import { Component } from "@/typings/component"; - -export const Player: Component = () => { - return ( - <> -