From c8e38d51f48b93d7ca7738229ab72d5291dd8dd6 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 31 Oct 2026 12:00:15 +0100 Subject: [PATCH] show description and long description --- src/pages/video/[name].astro | 12 ++-- src/util/video.ts | 114 ++++++++++++++++------------------- 2 files changed, 59 insertions(+), 67 deletions(-) diff --git a/src/pages/video/[name].astro b/src/pages/video/[name].astro index a8a39d3..014a920 100644 --- a/src/pages/video/[name].astro +++ b/src/pages/video/[name].astro @@ -12,12 +12,12 @@ if (!video) return new Response(null, { status: 404 }); const metadata = await getVideoMetadata(video); if (!metadata) return new Response(null, { status: 404 }); -const { title, description } = metadata; +const { title, description, longDescription } = metadata; const streamUrl = siteUrl(`video/${encodeURIComponent(video.name)}/stream`); const thumbnailUrl = siteUrl(`video/${encodeURIComponent(video.name)}/thumbnail.jpg`); --- - + @@ -31,10 +31,14 @@ const thumbnailUrl = siteUrl(`video/${encodeURIComponent(video.name)}/thumbnail.

{title}

+ {description && ( +

{description}

+ )} + - {description && ( -

{description}

+ {longDescription && ( +

{longDescription}

)}
diff --git a/src/util/video.ts b/src/util/video.ts index 37d4a87..fff8fb6 100644 --- a/src/util/video.ts +++ b/src/util/video.ts @@ -6,49 +6,8 @@ import { createHash, randomUUID } from 'node:crypto'; import { CACHE_PATH, VIDEO_PATH } from 'astro:env/server'; import { logger } from './log'; -const videoTypes = [ - ['mp4', 'video/mp4'], - ['webm', 'video/webm'] -]; - const execFileAsync = promisify(execFile); -export interface ResolvedVideo { - name: string; - filename: string; - path: string; - contentType: string; - size: number; - modifiedAt: Date; -} - -export interface VideoRange { - start: number; - end: number; -} - -export interface VideoThumbnail { - path: string; - contentType: string; -} - -export interface VideoMetadata { - title: string; - description: string | null; -} - -interface FFprobeStream { - codec_type?: string; - tags?: Record; -} - -interface FFprobeResult { - streams?: FFprobeStream[]; - format?: { - tags?: Record; - }; -} - interface VideoMetadataCacheEntry { modifiedAtMs: number; size: number; @@ -57,6 +16,14 @@ interface VideoMetadataCacheEntry { const videoMetadataCache = new Map(); +export interface ResolvedVideo { + name: string; + filename: string; + path: string; + contentType: string; + size: number; + modifiedAt: Date; +} export async function resolveVideo(name: string): Promise { if (!VIDEO_PATH || !name) return null; @@ -65,34 +32,46 @@ export async function resolveVideo(name: string): Promise if (!safeName) return null; - for (const [extension, contentType] of videoTypes) { - const filename = `${safeName}.${extension}`; - const filePath = path.join(directory, filename); + const filename = `${safeName}.mp4`; + const filePath = path.join(directory, filename); - try { - const stats = await fs.promises.stat(filePath); - if (!stats.isFile()) continue; + try { + const stats = await fs.promises.stat(filePath); + if (!stats.isFile()) return null; - return { - name: safeName, - filename, - path: filePath, - contentType, - size: stats.size, - modifiedAt: stats.mtime - }; - } catch (e) { - // check if file doesn't exist - if ((e as NodeJS.ErrnoException).code === 'ENOENT') { - continue; - } - logger.warn({ error: e }, 'error while reading video file'); + return { + name: safeName, + filename, + path: filePath, + contentType: 'video/mp4', + size: stats.size, + modifiedAt: stats.mtime + }; + } catch (e) { + // check if file doesn't exist + if ((e as NodeJS.ErrnoException).code === 'ENOENT') { + return null; } + logger.warn({ error: e }, 'error while reading video file'); } return null; } +export interface VideoMetadata { + title: string; + description: string | null; + longDescription: string | null; +} +interface FFprobeResult { + streams?: { + codec_type?: string; + tags?: Record; + }[]; + format?: { + tags?: Record; + }; +} export async function getVideoMetadata(video: ResolvedVideo): Promise { const modifiedAtMs = video.modifiedAt.getTime(); const cached = videoMetadataCache.get(video.path); @@ -108,7 +87,7 @@ export async function getVideoMetadata(video: ResolvedVideo): Promise { if (!VIDEO_PATH) return null; @@ -184,6 +168,10 @@ export async function getVideoThumbnail(video: ResolvedVideo): Promise