From c6aa70a64731b608fade3acab48c1d1d2df280b6 Mon Sep 17 00:00:00 2001 From: 0t4u <61939142+0t4u@users.noreply.github.com> Date: Mon, 5 Dec 2022 20:33:28 +0000 Subject: Add files via upload --- modules/VideoActionButtons.tsx | 144 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 modules/VideoActionButtons.tsx (limited to 'modules/VideoActionButtons.tsx') diff --git a/modules/VideoActionButtons.tsx b/modules/VideoActionButtons.tsx new file mode 100644 index 0000000..572ded2 --- /dev/null +++ b/modules/VideoActionButtons.tsx @@ -0,0 +1,144 @@ +import Link from "next/link"; +import React from "react"; +import { VideoMetadata } from "./database.d"; +import { formatBytes } from "./format"; +import { + IconChartBar, + IconChevronDown, + IconDownload, + IconYouTube, +} from "./icons"; + +type VideoActionButtonsProps = { + video: VideoMetadata; + full?: boolean; +}; + +export const buttonStyle = ` + bg-gray-800 + hover:bg-gray-700 + focus:bg-gray-900 focus:outline-none + px-4 py-2 mb-2 md:mb-0 rounded + transition duration-200 + flex flex-row items-center`.replace(/\s+/, " "); + +const getFile = (videoInfo: VideoMetadata, suffix: string) => + videoInfo.files.find((file) => file.name.endsWith(suffix)); + +const VideoActionButtons = React.memo( + ({ video, full }: VideoActionButtonsProps) => { + const [isMenuOpen, setIsMenuOpen] = React.useState(false); + + const mkv = getFile(video, ".mkv"); + const mkvURL = mkv?.url; + const mkvSize = mkv?.size || -1; + + const [fmtVideo, fmtAudio] = video.format_id.split("+"); + + const handleToggleMenu = ( + e: React.MouseEvent + ) => { + e.preventDefault(); + setIsMenuOpen((now) => !now); + }; + + const fileURLs = video.files + ?.filter(({ name }) => !name.endsWith(".mkv")) + .map(({ name, size, url }) => ({ + label: name.includes(".f" + fmtVideo + ".") + ? "Video only" + : name.includes(".f" + fmtAudio + ".") + ? "Audio only" + : name.endsWith(".vtt") + ? "Captions (vtt, " + name.split(".")[1] + ")" + : name.endsWith(".ytt") + ? "Captions (srv3, " + name.split(".")[1] + ")" + : name.endsWith(".chat.json") + ? "Chat logs (json)" + : name.endsWith(".info.json") + ? "Metadata (json)" + : name.endsWith(".webp") + ? "Thumbnail (webp)" + : name.endsWith(".jpg") + ? "Thumbnail (jpeg)" + : name, + name, + size, + url, + })) + .sort((a, b) => (a.label > b.label ? 1 : -1)); + + // Account for aspect ratio wider than 16:9 + const videoHeight = Math.max(video.height, 0.5625 * video.width); + + return ( + <> + {isMenuOpen && ( +
setIsMenuOpen(false)} + /> + )} +
+ + + Download ({videoHeight}p{video.fps}, {formatBytes(mkvSize)}) + + + + More download options + + {isMenuOpen && ( +
+ {fileURLs.map((file) => ( + + {file.label} + + ))} +
+ )} + + + Watch on YouTube + + {full && ( + <> +
+ {video.files.findIndex((file) => + file.name.endsWith(".chat.json") + ) > -1 && ( + + + + Chat explorer + + + )} + + )} +
+ + ); + } +); + +export default VideoActionButtons; -- cgit v1.2.3