From dfd9e258c133a4c4ce84646dc70ebf072fa171b2 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 1 Aug 2026 17:21:19 -0700 Subject: allow for pasting in a b64 encoded json --- pages/index.tsx | 114 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 36 deletions(-) (limited to 'pages') diff --git a/pages/index.tsx b/pages/index.tsx index ee80836..fc6dbc9 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -21,6 +21,7 @@ const CustomPlayerPage = () => { const [infoJson, setInfoJson] = React.useState({} as any); const [showPlayer, setShowPlayer] = React.useState(false); const [dataSet, setDataSet] = React.useState(false); + const [base64Input, setBase64Input] = React.useState(""); const { query } = router; const jsonDataUrl = query.data as string; @@ -33,47 +34,66 @@ const CustomPlayerPage = () => { }, [timeSeconds]); - if(jsonDataUrl && !dataSet) { + const applyJsonData = (data: any) => { + const { info, video, chat, srv3, srt, captions } = data; + if (info) { + fetch(info) + .then((res) => res.json()) + .then((data) => { + setInfoJson(data); + }); + } + if (video) { + setUrlVideo(video); + } + if (chat) { + setUrlChat(chat); + } + if (srv3) { + setUrlYtt(srv3); + setCaptionFormat("srv3"); + } else if (srt) { + setUrlYtt(srt); + setCaptionFormat("srt"); + } else if (captions) { + const cap = Array.isArray(captions) ? captions[0] : captions; + if (cap?.src) { + setUrlYtt(cap.src); + setCaptionFormat(cap.format || (cap.src.toLowerCase().endsWith(".srt") ? "srt" : "srv3")); + } + } + setDataSet(true); + setShowPlayer(true); + }; + + if (jsonDataUrl && !dataSet) { fetch(jsonDataUrl) .then((res) => res.json()) - .then((data) => { - const { info, video, chat, srv3, srt, captions } = data; - if (info) { - fetch(info) - .then((res) => res.json()) - .then((data) => { - setInfoJson(data); - }); - } - if (video) { - setUrlVideo(video); - } - if (chat) { - setUrlChat(chat); - } - if (srv3) { - setUrlYtt(srv3); - setCaptionFormat("srv3"); - } else if (srt) { - setUrlYtt(srt); - setCaptionFormat("srt"); - } else if (captions) { - const cap = Array.isArray(captions) ? captions[0] : captions; - if (cap?.src) { - setUrlYtt(cap.src); - setCaptionFormat(cap.format || (cap.src.toLowerCase().endsWith(".srt") ? "srt" : "srv3")); - } - } - setDataSet(true); - setShowPlayer(true); - }) + .then((data) => applyJsonData(data)) .catch((error) => { - console.error("Error fetching JSON data:", error); - setDataSet(true); - setShowPlayer(true); + console.error("Error fetching JSON data:", error); + setDataSet(true); + setShowPlayer(true); }); } + const handleLoadBase64 = () => { + try { + let trimmed = base64Input.trim(); + const base64Match = trimmed.match(/^data:[^;]+;base64,(.*)$/); + if (base64Match) { + trimmed = base64Match[1]; + } + const jsonStr = atob(trimmed); + const data = JSON.parse(jsonStr); + applyJsonData(data); + } catch (error) { + console.error("Error decoding base64 JSON:", error); + setDataSet(true); + setShowPlayer(true); + } + }; + const handleFile = ( e: React.ChangeEvent, @@ -221,7 +241,7 @@ const CustomPlayerPage = () => {


- This is a specialized version of the player that allows you to pass in a json data file. + This is a specialized version of the player that allows you to pass in a JSON data file.

@@ -282,6 +302,24 @@ const CustomPlayerPage = () => { Launch player +
+ +