A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
<script setup lang="ts">
import type { MediaInfoResource } from '@/contracts/mediaInfo.ts';
import type { VideoResource } from '@/contracts/media';
import { formatBitrate, formatFileSize, toFormattedDate, toFormattedDuration } from '@/service/util';
import { buildStreamCards, type FfprobeStream } from '@/service/media/ffprobe';
import { MediaType } from '@/types/types';
import { computed } from 'vue';
import StreamInfoCard from '@/components/cards/data/attachments/StreamInfoCard.vue';
import MediaTag from '@/components/labels/MediaTag.vue';
import ProiconsChevronRight from '~icons/proicons/chevron-right';
const props = defineProps<{ data: VideoResource; mediaInfo: MediaInfoResource }>();
const isAudio = computed(() => props.data.metadata?.media_type === MediaType.AUDIO);
const sumBy = <T,>(arr: T[] | undefined, fn: (item: T) => number): number => (arr ?? []).reduce((acc, item) => acc + fn(item), 0);
const metadataItems = computed<{ label: string; items: { label: string; value: any; to?: string }[] }[]>(() => {
if (!props.data.metadata) return [];
const mediaImages = props.data.metadata.images ?? [];
const mediaImageSize = sumBy(mediaImages, (img) => img.size ?? 0);
return [
{
label: 'Metadata',
items: [
{ label: 'UUID', value: props.data.metadata.uuid },
{ label: 'Metadata ID', value: props.data.metadata.id },
{ label: 'Video ID', value: props.data.id },
{ label: 'Title', value: props.data.title },
props.data.title !== props.data.name && { label: 'Name', value: props.data.name },
props.data.duration && { label: 'Duration', value: `${toFormattedDuration(props.data.duration)} (${props.data.duration}s)` },
props.data.metadata.bitrate && { label: 'Bitrate', value: formatBitrate(props.data.metadata.bitrate) },
{ label: 'Framerate', value: `${props.data.metadata.frame_rate} fps` },
{ label: 'Container', value: props.data.path.split('.').at(-1) },
{ label: 'Codec', value: props.data.metadata.codec },
...(isAudio?.value
? [
{ label: 'Artist', value: props.data.artist },
{ label: 'Album', value: props.data.album },
{ label: 'Disc', value: props.data.season },
{ label: 'Track', value: props.data.episode },
]
: [
{ label: 'Season', value: props.data.season },
{ label: 'Episode', value: props.data.episode },
]),
props.data.released_at && { label: 'Released', value: props.data.released_at },
{ label: 'Views', value: props.data.view_count },
].filter(Boolean) as { label: string; value: any; to?: string }[],
},
{
label: 'Attachments',
items: [
{ label: 'Images', value: props.data.metadata.images?.length },
{ label: 'Images Size', value: formatFileSize(mediaImageSize) },
...(!isAudio?.value
? [
{ label: 'Subtitles', value: props.data.subtitles.length },
{ label: 'Fonts', value: props.data.fonts?.length },
]
: []),
],
},
{
label: 'Timestamps',
items: [
{ label: 'Created', value: toFormattedDate(props.data.created_at) },
{ label: 'Last Updated', value: toFormattedDate(props.data.updated_at) },
{ label: 'Last Edited', value: props.data.edited_at ? toFormattedDate(props.data.edited_at) : 'Never' },
],
},
].filter(Boolean) as { label: string; items: { label: string; value: any; to?: string }[] }[];
});
const ffprobe = computed(() => {
return props.mediaInfo.raw_metadata as { format: { filename: string; format_name: string; size: string }; streams: FfprobeStream[] };
});
const cards = computed(() => buildStreamCards(ffprobe.value?.streams ?? []));
</script>
<template>
<div class="flex flex-col gap-4 text-sm">
<template v-for="(group, index) in metadataItems" :key="index">
<div class="flex flex-col gap-0.5">
<p class="">{{ group.label }}</p>
<div class="ms-4 flex flex-col gap-x-6">
<div v-for="item in group.items" :key="item.label" class="whitespace-pre-wrap">
<span class="text-foreground-1">{{ item.label }}: </span>	<span class="text-foreground-0">{{ item.value ?? '—' }}</span>
</div>
<div v-if="group.label === 'Metadata' && data.video_tags.length" title="Tags" class="flex gap-1 pt-4">
<span class="text-foreground-1">Tags: </span>
<span class="flex flex-wrap gap-1" v-if="data.video_tags.length">
<MediaTag v-for="tag in data.video_tags" :key="tag.id" class="text-foreground-0 pointer-events-none py-0.5 text-xs">
{{ tag.name }}
</MediaTag>
</span>
</div>
<details v-if="group.label === 'Metadata' && data.description" class="group flex w-full flex-col open:gap-2" hidden>
<summary class="hover:text-foreground-0 flex w-fit cursor-pointer items-center gap-1.5 transition-colors">
<ProiconsChevronRight class="-ms-1 size-3 transition-transform duration-200 group-open:rotate-90" />
Description
</summary>
<p class="scrollbar-minimal bg-surface-2 text-foreground-1 overflow-x-auto rounded-lg p-3 text-xs leading-relaxed whitespace-pre-wrap shadow-sm">
{{ data.description }}
</p>
</details>
</div>
</div>
</template>
<div class="space-y-0.5" v-if="data && cards.length > 0">
<p>Streams</p>
<div class="ms-4 grid grid-cols-[repeat(auto-fill,minmax(240px,1fr))] gap-4">
<StreamInfoCard v-for="card in cards" :key="card.key" :title="card.title" :fields="card.fields" />
</div>
</div>
</div>
</template>