A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: video card thumbnails and preview
aminnausin120e337fa294
diff --git a/resources/js/components/cards/data/VideoCard.vue b/resources/js/components/cards/data/VideoCard.vueindex 6071c4eb..3c692fdd 100644--- a/resources/js/components/cards/data/VideoCard.vue+++ b/resources/js/components/cards/data/VideoCard.vue@@ -2,9 +2,9 @@import type { ContextMenuItem } from '@/types/types';import type { VideoResource } from '@/types/resources';-import { formatFileSize, toFormattedDate, toPlural } from '@/service/util';+import { formatFileSize, handleStorageURL, toFormattedDate, toPlural } from '@/service/util';import { getMediaDateDescription } from '@/service/media/mediaFormatter';-import { computed, toRef } from 'vue';+import { computed, provide, toRef, type HTMLAttributes } from 'vue';import { useContentStore } from '@/stores/ContentStore';import { useAuthStore } from '@/stores/AuthStore';import { storeToRefs } from 'pinia';@@ -15,7 +15,9 @@ import { MediaType } from '@/types/types';import { cn } from '@aminnausin/cedar-ui';import TablerSubtitles from '@/components/icons/TablerSubtitles.vue';+import VideoPreview from '@/components/video/VideoPreview.vue';import useMetaData from '@/composables/useMetaData';+import LazyImage from '@/components/lazy/LazyImage.vue';import MediaTag from '@/components/labels/MediaTag.vue';import TablerMicrophone2 from '~icons/tabler/microphone-2';@@ -38,6 +40,13 @@ const isAudio = computed(() => {return videoData.metadata?.media_type === MediaType.AUDIO;});+const posterUrl = computed(() => {+ const url = videoData.metadata?.poster_image?.path ?? handleStorageURL(videoData?.metadata?.poster_url);+ const audioFallback = handleStorageURL(stateFolder.value.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp';++ return isAudio.value ? (url ?? audioFallback) : url;+});+const resumeOffset = computed(() => (videoData.progress_offset && videoData.progress_percentage < 95 && !isAudio.value ? `&t=${videoData.progress_offset}` : ''));const contextMenuItems = computed(() => {@@ -70,144 +79,211 @@ const contextMenuItems = computed(() => {});const dateInformation = computed(() => getMediaDateDescription(videoData));++const generatePosterStyle = (): HTMLAttributes['style'] => {+ if (!posterUrl.value) return {};++ return {+ backgroundImage: `url("${posterUrl.value}")`,+ backgroundPosition: 'center',+ backgroundSize: 'cover',+ backgroundRepeat: 'no-repeat',+ };+};++provide('isAudio', isAudio);</script><template><RouterLink- :class="[- 'dark:hover:bg-primary-active/70 dark:bg-primary-dark-800/70 dark:odd:bg-primary-dark-600 hover:bg-primary/5 bg-neutral-50 odd:bg-neutral-100',- 'relative flex w-full flex-col gap-x-8 gap-y-4 rounded-md',- 'data-card hover:data-card-hover overflow-clip p-3 shadow-sm focus-within:outline-none',- ]":to="encodeURI(`/${stateDirectory.name}/${stateFolder.name}?video=${videoData.id}${resumeOffset}`)"@contextmenu="(e: any) => {setContextMenu(e, { items: contextMenuItems });}"+ :class="+ cn(+ 'dark:hover:bg-primary-active/70 dark:bg-primary-dark-800/70 dark:odd:bg-primary-dark-600 hover:bg-primary/5 bg-neutral-50 odd:bg-neutral-100',+ 'relative flex rounded-md',+ 'data-card hover:data-card-hover overflow-clip shadow-sm focus-within:outline-none',+ )+ ">- <div class="flex w-full items-center justify-between gap-4 overflow-hidden">- <h3 class="line-clamp-1 min-w-8 break-all" :title="`Title: ${videoData.title}${videoData.name !== videoData.title ? `\nFile: ${videoData.name}` : ''}`">- {{ title }}- </h3>- <div class="-ms-2 flex flex-1 gap-1">- <HoverCard- class="items-end"- v-if="videoData.description"- :content="videoData.description"- :content-title="`${videoData.title}`"- :hover-card-delay="400"- :hover-card-leave-delay="300"- >- <template #trigger>- <ProiconsComment class="my-auto size-5 shrink-0 opacity-100 transition-opacity duration-300 hover:opacity-20" title="Description" />- </template>- </HoverCard>- <HoverCard class="xs:block hidden" v-if="videoData.metadata?.lyrics" :content-title="'Has Lyrics'" :hover-card-delay="400" :hover-card-leave-delay="300">- <template #trigger>- <TablerMicrophone2 class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Has Lyrics" />- </template>- </HoverCard>- <HoverCard- class="xs:block hidden"- v-if="videoData.subtitles.length > 0 && !isAudio"- :content-title="'Has Subtitles'"- :hover-card-delay="400"- :hover-card-leave-delay="300"- >- <template #trigger>- <TablerSubtitles class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Has Subtitles" />- </template>- </HoverCard>-- <HoverCard- class="xs:block hidden"- v-if="videoData.progress_percentage === 100 || videoData.completion_count > 0"- :content-title="`Completed ${videoData.completion_count || 1} time${toPlural(videoData.completion_count || 1)}`"- :hover-card-delay="400"- :hover-card-leave-delay="300"- >- <template #trigger>- <ProiconsCheckmark class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Completed" />- </template>- </HoverCard>+ <template v-if="posterUrl">+ <div v-if="isAudio" :class="['pointer-events-none relative z-0 size-24 overflow-clip']">+ <div id="audio-poster" :class="['transition-scale absolute inset-0 -z-1 scale-105 blur-sm ease-in-out']" :style="generatePosterStyle()"></div>+ <LazyImage+ :src="posterUrl"+ alt="album art"+ wrapper-class="flex items-center justify-center"+ :class="['mx-auto object-contain select-none md:h-screen']"+ loading="eager"+ fetchpriority="high"+ /></div>-- <div class="text-foreground-1 flex min-w-fit gap-1 text-sm uppercase *:text-nowrap">- <span v-if="videoData.file_size" :title="`File Size: ${formatFileSize(videoData.file_size)}`">- {{ formatFileSize(videoData.file_size) }}- </span>- <span v-if="(videoData.metadata?.codec && isAudio) || (!isAudio && videoData.metadata?.resolution_height)">|</span>- <span v-if="isAudio && videoData?.metadata?.codec" :title="`File Codec: ${videoData.metadata.codec}`">- {{ videoData.metadata.codec }}- </span>- <span- v-else-if="videoData.metadata?.resolution_height && !isAudio"- :title="`Resolution: ${videoData.metadata.resolution_width}x${videoData.metadata.resolution_height}${videoData.metadata.codec && `\nFile Codec: ${videoData.metadata.codec}`}`"- >- {{ videoData.metadata.resolution_height }}P{{ videoData.metadata.codec ? ` | ${videoData.metadata.codec}` : '' }}- </span>+ <div v-else :class="cn('relative flex items-center overflow-clip')">+ <img :src="posterUrl" class="absolute top-0 h-full object-cover blur-xs" />+ <VideoPreview+ :data="data"+ :data-active="currentID === videoData.id"+ :poster-url="data.metadata?.poster_image?.path ?? data.metadata?.poster_url"+ class="aspect-video h-24 shrink-0"+ /></div>- </div>- <div class="group text-foreground-1 flex w-full flex-wrap items-start justify-between gap-x-4 gap-y-2 overflow-x-clip text-sm sm:w-auto">- <div class="flex items-center gap-2">- <div class="flex gap-1">- <span class="min-w-fit" :title="`View Count: ${views}`">- {{ views }}- </span>+ </template>- <span>|</span>- <span class="text-nowrap" :title="`Duration: ${duration}`">- {{ duration }}+ <div class="flex flex-1 flex-col">+ <div class="flex flex-1 flex-col justify-between gap-x-8 gap-y-4 p-3">+ <div class="flex w-full items-center justify-between gap-4 overflow-hidden">+ <h3 class="line-clamp-1 min-w-8 break-all" :title="`Title: ${videoData.title}${videoData.name !== videoData.title ? `\nFile: ${videoData.name}` : ''}`">+ {{ title }}+ </h3>+ <div class="-ms-2 flex flex-1 gap-1">+ <HoverCard+ class="items-end"+ v-if="videoData.description"+ :content="videoData.description"+ :content-title="`${videoData.title}`"+ :hover-card-delay="400"+ :hover-card-leave-delay="300"+ >+ <template #trigger>+ <ProiconsComment class="my-auto size-5 shrink-0 opacity-100 transition-opacity duration-300 hover:opacity-20" title="Description" />+ </template>+ </HoverCard>+ <HoverCard class="xs:block hidden" v-if="videoData.metadata?.lyrics" :content-title="'Has Lyrics'" :hover-card-delay="400" :hover-card-leave-delay="300">+ <template #trigger>+ <TablerMicrophone2 class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Has Lyrics" />+ </template>+ </HoverCard>+ <HoverCard+ class="xs:block hidden"+ v-if="videoData.subtitles.length > 0 && !isAudio"+ :content-title="'Has Subtitles'"+ :hover-card-delay="400"+ :hover-card-leave-delay="300"+ >+ <template #trigger>+ <TablerSubtitles class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Has Subtitles" />+ </template>+ </HoverCard>++ <HoverCard+ class="xs:block hidden"+ v-if="videoData.progress_percentage === 100 || videoData.completion_count > 0"+ :content-title="`Completed ${videoData.completion_count || 1} time${toPlural(videoData.completion_count || 1)}`"+ :hover-card-delay="400"+ :hover-card-leave-delay="300"+ >+ <template #trigger>+ <ProiconsCheckmark class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Completed" />+ </template>+ </HoverCard>+ </div>++ <div class="text-foreground-1 flex min-w-fit gap-1 text-sm uppercase *:text-nowrap">+ <span v-if="videoData.file_size" :title="`File Size: ${formatFileSize(videoData.file_size)}`">+ {{ formatFileSize(videoData.file_size) }}+ </span>+ <span v-if="(videoData.metadata?.codec && isAudio) || (!isAudio && videoData.metadata?.resolution_height)">|</span>+ <span v-if="isAudio && videoData?.metadata?.codec" :title="`File Codec: ${videoData.metadata.codec}`">+ {{ videoData.metadata.codec }}+ </span>+ <span+ v-else-if="videoData.metadata?.resolution_height && !isAudio"+ :title="`Resolution: ${videoData.metadata.resolution_width}x${videoData.metadata.resolution_height}${videoData.metadata.codec && `\nFile Codec: ${videoData.metadata.codec}`}`"+ >+ {{ videoData.metadata.resolution_height }}P{{ videoData.metadata.codec ? ` | ${videoData.metadata.codec}` : '' }}+ </span>+ </div>+ </div>+ <div class="group text-foreground-1 flex w-full flex-wrap items-start justify-between gap-x-4 gap-y-2 overflow-x-clip text-sm sm:w-auto">+ <div class="flex items-center gap-2">+ <div class="flex gap-1">+ <span class="min-w-fit" :title="`View Count: ${views}`">+ {{ views }}+ </span>++ <span>|</span>+ <span class="text-nowrap" :title="`Duration: ${duration}`">+ {{ duration }}+ </span>+ </div>+ </div>+ <span+ v-if="videoData.video_tags.length"+ class="order-3 flex w-full flex-wrap gap-1 overflow-clip [overflow-clip-margin:4px] sm:order-0 sm:h-5.5 sm:flex-1 sm:gap-y-2"+ title="Tags"+ >+ <MediaTag v-for="(tag, index) in videoData.video_tags" :key="index" :label="tag.name" /></span>++ <HoverCard class="text-end text-nowrap" :hover-card-delay="400" :hover-card-leave-delay="300" :content="dateInformation">+ <template #trigger>+ {{ toFormattedDate(videoData.file_modified_at) }}+ </template>+ </HoverCard>+ </div>++ <div+ v-if="videoData.progress_percentage && 0"+ :class="+ cn(+ 'playback-progress-bar absolute bottom-0 left-0 flex h-1 w-full',+ 'duration-input bg-neutral-300 opacity-80 transition-[translate,opacity] dark:bg-neutral-700 dark:opacity-60',+ {+ '-translate-y-0.5 opacity-100 dark:opacity-100': currentID === videoData.id,+ 'in-focus:-translate-y-0.5': currentID !== videoData.id,+ },+ )+ "+ :title="`Progress: ${videoData.progress_percentage}s`"+ >+ <div+ :class="+ cn('bg-foreground-3 duration-input mt-auto h-full w-full transition-[background-color]', {+ 'bg-primary-muted dark:in-focus:bg-primary dark:bg-primary-active': currentID === videoData.id,+ 'playback-progress-fill': currentID !== videoData.id,+ })+ "+ :style="{ width: `${videoData.progress_percentage}%` }"+ ></div></div></div>- <span- v-if="videoData.video_tags.length"- class="order-3 flex w-full flex-wrap gap-1 overflow-clip [overflow-clip-margin:4px] sm:order-0 sm:h-5.5 sm:flex-1 sm:gap-y-2"- title="Tags"+ <div+ v-if="videoData.progress_percentage"+ :class="+ cn(+ 'playback-progress-bar flex h-1',+ 'duration-input mt-auto bg-neutral-300 opacity-80 transition-[translate,opacity,margin] dark:bg-neutral-700 dark:opacity-60',+ {+ 'me-0.5 -translate-y-0.5 opacity-100 dark:opacity-100': currentID === videoData.id,+ 'in-focus:me-0.5 in-focus:-translate-y-0.5': currentID !== videoData.id,+ },+ )+ "+ :title="`Progress: ${videoData.progress_percentage}s`">- <MediaTag v-for="(tag, index) in videoData.video_tags" :key="index" :label="tag.name" />- </span>-- <HoverCard class="text-end text-nowrap" :hover-card-delay="400" :hover-card-leave-delay="300" :content="dateInformation">- <template #trigger>- {{ toFormattedDate(videoData.file_modified_at) }}- </template>- </HoverCard>- </div>- <div- v-if="videoData.progress_percentage"- :class="- cn(- 'playback-progress-bar absolute bottom-0 left-0 flex h-1 w-full',- 'duration-input bg-neutral-300 opacity-80 transition-[translate,opacity] dark:bg-neutral-700 dark:opacity-60',- {- '-translate-y-0.5 opacity-100 dark:opacity-100': currentID === videoData.id,- 'in-focus:-translate-y-0.5': currentID !== videoData.id,- },- )- "- :title="`Progress: ${videoData.progress_percentage}s`"- >+ <div+ :class="+ cn('bg-foreground-3 duration-input mt-auto h-full w-full transition-[background-color]', {+ 'bg-primary-muted dark:in-focus:bg-primary dark:bg-primary-active': currentID === videoData.id,+ 'playback-progress-fill': currentID !== videoData.id,+ })+ "+ :style="{ width: `${videoData.progress_percentage}%` }"+ ></div>+ </div><div:class="- cn('bg-foreground-3 duration-input mt-auto h-full w-full transition-[background-color]', {- 'bg-primary-muted dark:in-focus:bg-primary dark:bg-primary-active': currentID === videoData.id,- 'playback-progress-fill': currentID !== videoData.id,+ cn('pointer-events-none absolute inset-0 rounded-md', 'transition-input duration-input', 'z-4 ring-transparent ring-inset', {+ 'ring-primary-muted dark:ring-primary-active in-focus:ring-primary ring-2': currentID === videoData.id,+ 'in-focus:ring-foreground-0 in-focus:ring-2': currentID !== videoData.id,})"- :style="{ width: `${videoData.progress_percentage}%` }"></div></div>- <div- :class="- cn('pointer-events-none absolute inset-0 rounded-md', 'transition-input duration-input', 'ring-transparent ring-inset', {- 'ring-primary-muted dark:ring-primary-active in-focus:ring-primary ring-2': currentID === videoData.id,- 'in-focus:ring-foreground-0 in-focus:ring-2': currentID !== videoData.id,- })- "- ></div></RouterLink></template><style lang="css" scoped>diff --git a/resources/js/components/video/VideoPreview.vue b/resources/js/components/video/VideoPreview.vuenew file mode 100644index 00000000..19bbaf5b--- /dev/null+++ b/resources/js/components/video/VideoPreview.vue@@ -0,0 +1,123 @@+<script setup lang="ts">+import type { StoryboardCue } from '@/service/storyboard/types';+import type { VideoResource } from '@/contracts/media';++import { computed, ref, useTemplateRef } from 'vue';+import { buildStoryboardCues } from '@/service/storyboard';+import { toFormattedDuration } from '@/service/util';+import { cn } from '@aminnausin/cedar-ui';++import VideoControlWrapper from '@/components/video/VideoControlWrapper.vue';+import LazyImage from '@/components/lazy/LazyImage.vue';++const PREVIEW_FRAME_COUNT = 10;++const props = defineProps<{+ data: VideoResource;+ dataActive: boolean;+ posterUrl?: string;+}>();++const scrubContainer = useTemplateRef('scrubContainer');+const hoverProgress = ref(0);+const hovered = ref(false);++const previewCues = computed<StoryboardCue[]>(() => {+ const uuid = props.data.metadata?.uuid;+ const durationSeconds = props.data.duration;+ const storyboard = props.data.storyboard;++ if (!storyboard || !uuid || !durationSeconds) return [];++ const storyboardCues = buildStoryboardCues(uuid, durationSeconds, storyboard);++ if (!storyboardCues.length) return [];++ const frameCount = Math.min(storyboardCues.length, PREVIEW_FRAME_COUNT);+ const sliceSize = (props.data.duration ?? 0) / frameCount;+ const step = Math.floor(storyboardCues.length / frameCount);++ return Array.from({ length: frameCount }, (_, i) => ({+ ...storyboardCues[i * step],+ start: i * sliceSize,+ end: (i + 1) * sliceSize,+ })).filter(Boolean);+});++const activeCue = computed<StoryboardCue | undefined>(() => {+ if (!previewCues.value.length) return undefined;+ const duration = props.data.duration ?? 0;+ const index = Math.min(Math.floor((hoverProgress.value / duration) * PREVIEW_FRAME_COUNT), PREVIEW_FRAME_COUNT - 1);+ return previewCues.value[index];+});++const spriteStyle = computed(() => {+ const c = activeCue.value;+ const storyboard = props.data.storyboard;++ if (!c || c.x === undefined || !storyboard || !scrubContainer.value) return undefined;++ const containerWidth = scrubContainer.value.getBoundingClientRect().width;+ const scale = containerWidth / c.w;++ return {+ backgroundImage: `url(${c.image})`,+ backgroundPosition: `-${c.x * scale}px -${c.y * scale}px`,+ backgroundSize: `${c.w * storyboard.tile_cols * scale}px ${c.h * storyboard.tile_rows * scale}px`,+ };+});++const timestamp = computed(() => {+ if (!props.data.duration) return '';+ return `${toFormattedDuration(hoverProgress.value, false, 'digital', true)}`;+});++// Could debounce+function onMouseMove(e: MouseEvent) {+ const el = e.currentTarget as HTMLElement;+ const rect = el.getBoundingClientRect();+ const ratio = (e.clientX - rect.left) / rect.width;+ const duration = props.data.duration ?? 0;+ hoverProgress.value = ratio * duration;+}+</script>++<template>+ <div+ :class="['group relative aspect-video size-full', $attrs.class]"+ :style="spriteStyle"+ @mouseenter="hovered = true"+ @mouseleave="hovered = false"+ @mousemove="onMouseMove"+ ref="scrubContainer"+ >+ <LazyImage+ :src="posterUrl"+ alt="poster"+ :class="+ cn('absolute inset-0 size-full cursor-crosshair object-cover opacity-100', {+ 'transition-opacity group-hover:opacity-0': activeCue,+ })+ "+ />+ </div>++ <div+ v-if="hovered && activeCue && data.duration"+ :class="+ cn('duration-input pointer-events-none absolute inset-0 z-3 flex flex-col justify-end gap-1 opacity-0 transition-[translate,opacity,margin]', {+ 'opacity-100': hovered,+ 'ms-0.5 -translate-y-0.5': dataActive,+ })+ "+ >+ <VideoControlWrapper class="ml-1 w-fit">+ <p :class="cn('font-figtree px-1 text-xs text-white tabular-nums text-shadow-lg')">+ {{ timestamp }}+ </p>+ </VideoControlWrapper>+ <div :class="cn('h-1 w-full bg-white/20')">+ <div class="h-full bg-white" :style="{ width: `${(hoverProgress / data.duration) * 100}%` }" />+ </div>+ </div>+</template>