From 1656c388da9e27ca962ded031fdc7b6612b56361 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 29 Jan 2024 01:30:04 -0800 Subject: add support for remote query params and .info.json files --- pages/index.tsx | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 9 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 316e16a..82e3381 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import Head from "next/head"; import ChatReplayPanel from "../modules/ChatReplay/ChatReplayPanel"; import { useWindowSize } from "../modules/hooks/useWindowSize"; @@ -6,15 +6,56 @@ import PageBase from "../modules/PageBase"; import VideoPlayer2 from "../modules/VideoPlayer/VideoPlayer2"; import { buttonStyle } from "../modules/VideoActionButtons"; import { IconCheck } from "../modules/icons"; +import { useRouter } from "next/router"; +import Linkify from "linkify-react"; const CustomPlayerPage = () => { + const router = useRouter(); const [isChatVisible, setIsChatVisible] = React.useState(false); const { innerWidth, innerHeight } = useWindowSize(); const [playbackProgress, setPlaybackProgress] = React.useState(0); const [urlVideo, setUrlVideo] = React.useState(""); const [urlChat, setUrlChat] = React.useState(""); const [urlYtt, setUrlYtt] = React.useState(""); + const [urlInfoJson, setUrlInfoJson] = React.useState(""); + const [infoJson, setInfoJson] = React.useState({} as any); const [showPlayer, setShowPlayer] = React.useState(false); + const { query } = router; + + const videoUrl = query.vid as string; + const chatUrl = query.chat as string; + const infoJsonUrl = query.info as string; + const srv3Url = query.ytt as string; + + if (videoUrl && videoUrl !== urlVideo) { + setUrlVideo(videoUrl); + } + if (chatUrl && chatUrl !== urlChat) { + setUrlChat(chatUrl); + } + + if (srv3Url && srv3Url !== urlYtt) { + setUrlYtt(srv3Url); + } + + if (infoJsonUrl && infoJsonUrl !== urlInfoJson) { + setUrlInfoJson(infoJsonUrl); + } + + if (videoUrl && !showPlayer) { + setShowPlayer(true); + } + + useEffect(() => { + if (urlInfoJson) { + fetch(urlInfoJson) + .then((res) => res.json()) + .then((data) => { + setInfoJson(data); + }); + } + }), + [urlChat]; const handleFile = ( e: React.ChangeEvent, @@ -36,7 +77,7 @@ const CustomPlayerPage = () => { Custom Player - Ragtag Archive {showPlayer ? ( -
+
{ )}
- + {infoJson && infoJson.description ? ( +
+

{infoJson.title}

+

+ {infoJson.view_count.toLocaleString()} views ·{" "} + {infoJson.upload_date.slice(0, 4) + + "-" + + infoJson.upload_date.slice(4, 6) + + "-" + + infoJson.upload_date.slice(6, 8)} +

+
+

+ {infoJson.uploader} +

+

Description

+
+ {infoJson.description} +
+
+
+ ) : null} + {!videoUrl ? ( + + ) : null}
) : (
@@ -166,6 +231,19 @@ const CustomPlayerPage = () => { onChange={(e) => handleFile(e, setUrlYtt)} /> +