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;