Skip to content

A self-hosted media server and file management system

feat: tentative support for clickable timestamps in descriptions

aminnausinbf15e15a510f
diff --git a/resources/js/components/video/VideoInfoPanel.vue b/resources/js/components/video/VideoInfoPanel.vue
index f2600c53..9a070fc9 100755
--- a/resources/js/components/video/VideoInfoPanel.vue
+++ b/resources/js/components/video/VideoInfoPanel.vue
@@ -8,6 +8,7 @@ import { getUserViewCount } from '@/service/mediaAPI';
import { useContentStore } from '@/stores/ContentStore';
import { useAuthStore } from '@/stores/AuthStore';
import { storeToRefs } from 'pinia';
+import { emitSeek } from '@/service/video/seekBus';
import { useRoute } from 'vue-router';
import ButtonClipboard from '@/components/pinesUI/ButtonClipboard.vue';
@@ -61,6 +62,10 @@ const handleSeriesUpdate = (res: any) => {
editFolderModal.toggleModal(false);
};
+function handleSeek(seconds: number) {
+ emitSeek(seconds);
+}
+
watch(
() => stateVideo.value,
async () => {
@@ -181,7 +186,7 @@ watch(
</span>
</span>
</section>
- <section id="mp4-folder-info" class="hidden xs:block h-32 my-auto object-cover rounded-md shadow-md aspect-2/3 mb-auto relative group">
+ <section id="mp4-folder-info" class="hidden xs:block h-32 object-cover rounded-md shadow-md aspect-2/3 relative group">
<img
id="folder-thumbnail"
class="h-full object-cover rounded-md aspect-2/3 ring-1 ring-gray-900/5"
@@ -230,10 +235,29 @@ watch(
</ButtonIcon>
</section>
</section>
- <HoverCard :content="metaData?.fields?.description" :hover-card-delay="800" :margin="10">
+ <HoverCard :content="stateVideo.description ?? defaultDescription" :hover-card-delay="800" :margin="10">
<template #trigger>
- <div :class="`h-[3.75rem] overflow-y-auto overflow-x-clip text-sm whitespace-pre-wrap scrollbar-minimal scrollbar-hover `">
- {{ metaData?.fields?.description || defaultDescription }}
+ <div :class="[`overflow-y-auto overflow-x-clip text-sm whitespace-pre-wrap scrollbar-minimal scrollbar-hover`, { 'h-[3.75rem]': false }]">
+ <template v-if="metaData?.fields?.description">
+ <span v-for="(segment, i) in metaData?.fields?.description" :key="i">
+ <template v-if="segment.type === 'timestamp' && segment.seconds !== undefined">
+ <a
+ :href="`?video=${stateVideo.id}&t=${segment.seconds}`"
+ @click.prevent="handleSeek(segment.seconds)"
+ class="text-purple-600 dark:text-white hover:underline"
+ :title="`Seek to ${segment.seconds}`"
+ >
+ {{ segment.raw }}
+ </a>
+ </template>
+ <template v-else>
+ {{ segment.text }}
+ </template>
+ </span>
+ </template>
+ <template v-else>
+ {{ metaData?.fields?.description || defaultDescription }}
+ </template>
</div>
</template>
</HoverCard>
diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vue
index 4e757ed7..6e3b005c 100755
--- a/resources/js/components/video/VideoPlayer.vue
+++ b/resources/js/components/video/VideoPlayer.vue
@@ -1,7 +1,6 @@
<script setup lang="ts">
import type { FolderResource, VideoResource } from '@/types/resources';
-import { type ContextMenuItem, type PopoverItem, MediaType } from '@/types/types';
-import type { Series } from '@/types/model';
+import type { ContextMenuItem, PopoverItem } from '@/types/types';
import { getScreenSize, handleStorageURL, isInputLikeElement, isMobileDevice, toFormattedDate, toFormattedDuration } from '@/service/util';
import { computed, nextTick, onMounted, onUnmounted, ref, useTemplateRef, watch, type ComputedRef, type Ref } from 'vue';
@@ -13,6 +12,7 @@ import { useAuthStore } from '@/stores/AuthStore';
import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
import { getMediaUrl } from '@/service/api';
+import { MediaType } from '@/types/types';
import { useRouter } from 'vue-router';
import { toast } from '@/service/toaster/toastService';
@@ -49,6 +49,7 @@ import ProiconsCancel from '~icons/proicons/cancel';
import ProiconsPlay from '~icons/proicons/play';
import MagePlaylist from '~icons/mage/playlist';
import CircumTimer from '~icons/circum/timer';
+import { onSeek } from '@/service/video/seekBus';
/**
* Z Index Layout:
@@ -73,7 +74,7 @@ const { setContextMenu } = useAppStore();
const { userData } = storeToRefs(useAuthStore());
const { stateVideo, stateFolder, nextVideoURL, previousVideoURL } = storeToRefs(useContentStore()) as unknown as {
stateVideo: Ref<VideoResource>;
- stateFolder: Ref<FolderResource | { id?: number; name?: string; series?: Series; path?: string }>;
+ stateFolder: Ref<FolderResource>;
nextVideoURL: ComputedRef<string>;
previousVideoURL: ComputedRef<string>;
};
@@ -164,7 +165,7 @@ const keyBinds = computed(() => {
play: `${isPaused.value ? 'Play' : 'Pause'}${keys.play}`,
next: `Play Next${keys.next}`,
fullscreen: `${isFullScreen.value ? 'Exit Full Screen' : 'Full Screen'}${keys.fullscreen}`,
- lyrics: `${isShowingLyrics.value ? 'Disable' : 'Enable'} ${isAudio.value ? 'Lyrics' : 'Captions'}${keys.lyrics}`,
+ lyrics: `${isShowingLyrics.value ? 'Disable' : 'Enable'} ${isAudio.value || stateFolder.value.is_majority_audio ? 'Lyrics' : 'Captions'}${keys.lyrics}`,
};
});
@@ -236,7 +237,7 @@ const videoPopoverItems = computed(() => {
selectedIcon: ProiconsCheckmark,
selected: isShowingLyrics.value ?? false,
selectedIconStyle: 'text-purple-600 stroke-none',
- disabled: getScreenSize() !== 'default' || isAudio.value,
+ disabled: getScreenSize() !== 'default' || isAudio.value || stateFolder.value.is_majority_audio,
action: () => {
isShowingLyrics.value = !isShowingLyrics.value;
},
@@ -249,7 +250,7 @@ const videoPopoverItems = computed(() => {
selectedIcon: ProiconsCheckmark,
selected: isShowingLyrics.value ?? false,
selectedIconStyle: 'text-purple-600 stroke-none',
- disabled: getScreenSize() !== 'default' || !isAudio.value,
+ disabled: getScreenSize() !== 'default' || (!isAudio.value && !stateFolder.value.is_majority_audio),
action: () => {
isShowingLyrics.value = !isShowingLyrics.value;
},
@@ -921,15 +922,19 @@ watch(isPictureInPicture, async (value) => {
watch(stateVideo, initVideoPlayer);
+let unSub: () => boolean;
+
onMounted(() => {
if (document.pictureInPictureElement) document.exitPictureInPicture();
handleLoadSavedVolume();
handleMediaSessionEvents();
window.addEventListener('keydown', handleKeyBinds);
document.addEventListener('fullscreenchange', handleFullScreenChange);
+ unSub = onSeek(handleManualSeek);
});
onUnmounted(() => {
+ unSub();
window.removeEventListener('keydown', handleKeyBinds);
document.removeEventListener('fullscreenchange', handleFullScreenChange);
debouncedCacheVolume.cancel();
@@ -1234,7 +1239,7 @@ defineExpose({
:controls="isShowingControls"
:offset="videoButtonOffset"
>
- <template #icon v-if="isAudio">
+ <template #icon v-if="isAudio || stateFolder.is_majority_audio">
<TablerMicrophone2 v-if="isShowingLyrics" class="w-4 h-4 [&>*]:stroke-[1.4px]" />
<TablerMicrophone2Off v-else class="w-4 h-4 [&>*]:stroke-[1.4px]" />
</template>
@@ -1358,9 +1363,10 @@ defineExpose({
leave-active-class="transition ease-in duration-300"
leave-from-class="translate-y-0 opacity-100"
leave-to-class="translate-y-full opacity-0"
- ><div :class="`absolute w-full h-full top-0 flex transition-all opacity-0`" style="z-index: 5" v-show="isShowingLyrics">
+ >
+ <div :class="`absolute w-full h-full top-0 flex transition-all opacity-0`" style="z-index: 5" v-show="isShowingLyrics">
<VideoLyrics
- v-if="isAudio"
+ v-if="isAudio || stateFolder.is_majority_audio"
@seek="handleManualSeek"
:raw-lyrics="stateVideo?.metadata?.lyrics ?? ''"
:time-duration="timeDuration"
@@ -1443,7 +1449,11 @@ defineExpose({
leave-active-class="transition ease-in duration-300"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
- ><div :class="`absolute w-full h-full top-0 transition-all backdrop-blur-lg bg-neutral-950/10`" style="z-index: 3" v-show="isAudio && isShowingLyrics"></div>
+ ><div
+ :class="`absolute w-full h-full top-0 transition-all backdrop-blur-lg bg-neutral-950/10`"
+ style="z-index: 3"
+ v-show="(isAudio || stateFolder.is_majority_audio) && isShowingLyrics"
+ ></div>
</Transition>
</section>
<!-- Is a blurred copy of the thumbnail or poster as a backdrop to the clear poster -->
diff --git a/resources/js/composables/useMetaData.ts b/resources/js/composables/useMetaData.ts
index 9e47b725..a56b9e33 100644
--- a/resources/js/composables/useMetaData.ts
+++ b/resources/js/composables/useMetaData.ts
@@ -6,6 +6,7 @@ import { useRoute } from 'vue-router';
import { reactive } from 'vue';
// This so does not work lol
+
export default function useMetaData(data: VideoResource, skipBaseURL: boolean = false) {
const route = useRoute();
@@ -14,7 +15,7 @@ export default function useMetaData(data: VideoResource, skipBaseURL: boolean =
title: `${generateEpisodeTag(data)}${data?.title ?? data?.name}`,
duration: toFormattedDuration(data?.duration) ?? 'N/A',
views: generateViewsTag(data?.view_count),
- description: data?.description ?? '',
+ description: generateDescription(data?.description ?? ''),
url: encodeURI((skipBaseURL ? '' : document.location.origin) + route.path + `?video=${data.id}`),
file_size: data.file_size ? formatFileSize(data.file_size) : '',
},
@@ -24,7 +25,7 @@ export default function useMetaData(data: VideoResource, skipBaseURL: boolean =
title: `${generateEpisodeTag(props)}${props?.title ?? props?.name}`,
duration: toFormattedDuration(props?.duration) ?? 'N/A',
views: generateViewsTag(props?.view_count),
- description: props?.description ?? '',
+ description: generateDescription(props?.description ?? ''),
url: encodeURI((skipBaseURL ? '' : document.location.origin) + route.path + `?video=${data.id}`),
file_size: data.file_size ? formatFileSize(data.file_size) : '',
};
@@ -39,5 +40,36 @@ export default function useMetaData(data: VideoResource, skipBaseURL: boolean =
return `${viewCount} view${viewCount !== 1 ? 's' : ''}`;
}
+ function generateDescription(description: string) {
+ const parts: { type: 'text' | 'timestamp'; text?: string; raw?: string; seconds?: number }[] = [];
+
+ let lastIndex = 0;
+ let match: RegExpExecArray | null;
+
+ const regex = /(?:(\d{1,2}):)?(\d{1,2}):(\d{2}(?:\.\d+)?)/g;
+
+ while ((match = regex.exec(description)) !== null) {
+ const [full, hour, min, sec] = match;
+ const start = match.index;
+ const end = regex.lastIndex;
+
+ if (start > lastIndex) {
+ parts.push({ type: 'text', text: description.slice(lastIndex, start) });
+ }
+
+ const seconds = parseInt(hour ?? '0') * 3600 + parseInt(min) * 60 + parseFloat(sec);
+
+ parts.push({ type: 'timestamp', raw: full, seconds });
+
+ lastIndex = end;
+ }
+
+ if (lastIndex < description.length) {
+ parts.push({ type: 'text', text: description.slice(lastIndex) });
+ }
+
+ return parts;
+ }
+
return metadata;
}
diff --git a/resources/js/service/video/seekBus.ts b/resources/js/service/video/seekBus.ts
new file mode 100644
index 00000000..01385f5a
--- /dev/null
+++ b/resources/js/service/video/seekBus.ts
@@ -0,0 +1,12 @@
+const subscribers = new Set<(seconds: number) => void>();
+
+export function onSeek(callback: (seconds: number) => void) {
+ subscribers.add(callback);
+ return () => subscribers.delete(callback); // unsubscribe
+}
+
+export function emitSeek(seconds: number) {
+ for (const callback of subscribers) {
+ callback(seconds);
+ }
+}