A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: live lyrics viewer
aminnausin423b87c02b70
diff --git a/app/Http/Requests/MetadataStoreRequest.php b/app/Http/Requests/MetadataStoreRequest.phpindex 5dd95f45..4560bd4f 100644--- a/app/Http/Requests/MetadataStoreRequest.php+++ b/app/Http/Requests/MetadataStoreRequest.php@@ -33,6 +33,7 @@ class MetadataStoreRequest extends FormRequest {'video_id' => 'required|integer','title' => 'required|max:255','description' => 'nullable',+ 'lyrics' => 'nullable','episode' => RequestPresets::NON_NEGATIVE_INT,'season' => RequestPresets::NON_NEGATIVE_INT,'poster_url' => 'nullable|url',diff --git a/app/Http/Requests/MetadataUpdateRequest.php b/app/Http/Requests/MetadataUpdateRequest.phpindex ad1ae3ac..413ebae4 100644--- a/app/Http/Requests/MetadataUpdateRequest.php+++ b/app/Http/Requests/MetadataUpdateRequest.php@@ -32,6 +32,7 @@ class MetadataUpdateRequest extends FormRequest {return ['title' => 'required|max:255','description' => 'nullable',+ 'lyrics' => 'nullable','episode' => RequestPresets::NON_NEGATIVE_INT,'season' => RequestPresets::NON_NEGATIVE_INT,'poster_url' => 'nullable|url',diff --git a/app/Models/Metadata.php b/app/Models/Metadata.phpindex 215fb5c3..35d5ec8a 100644--- a/app/Models/Metadata.php+++ b/app/Models/Metadata.php@@ -18,7 +18,7 @@ class Metadata extends Model {'editor_id','title','description',- 'captions',+ 'lyrics','duration','episode','season',diff --git a/database/migrations/2025_01_05_025235_add_captions_to_metadata.php b/database/migrations/2025_01_05_025235_add_captions_to_metadata.phpindex dbc55a6d..143162fd 100644--- a/database/migrations/2025_01_05_025235_add_captions_to_metadata.php+++ b/database/migrations/2025_01_05_025235_add_captions_to_metadata.php@@ -11,7 +11,7 @@ return new class extends Migration {public function up(): void {Schema::table('metadata', function (Blueprint $table) {//- $table->text('captions')->nullable();+ $table->text('lyrics')->nullable();});}@@ -21,7 +21,7 @@ return new class extends Migration {public function down(): void {Schema::table('metadata', function (Blueprint $table) {//- $table->dropColumn('captions');+ $table->dropColumn('lyrics');});}};diff --git a/resources/js/components/forms/EditVideo.vue b/resources/js/components/forms/EditVideo.vueindex 1bb6dd01..ce2259d1 100755--- a/resources/js/components/forms/EditVideo.vue+++ b/resources/js/components/forms/EditVideo.vue@@ -52,7 +52,7 @@ const fields = reactive<FormField[]>([text: `Embedded ${isAudio.value ? 'Lyrics' : 'Captions'} (Uneditable)`,type: 'textArea',value: props.video?.metadata?.lyrics,- subtext: 'Format: [mm:ss:ms] line',+ subtext: 'Format: [mm:ss] line',placeholder: `No ${isAudio.value ? 'lyrics' : 'captions'} yet.`,default: '',},diff --git a/resources/js/components/inputs/FormTextArea.vue b/resources/js/components/inputs/FormTextArea.vueindex db59515b..f6b2516f 100755--- a/resources/js/components/inputs/FormTextArea.vue+++ b/resources/js/components/inputs/FormTextArea.vue@@ -29,7 +29,7 @@ onMounted(() => {text-gray-900 dark:text-neutral-100 bg-white dark:bg-neutral-700 placeholder:text-neutral-400ring-inset focus:ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700focus:ring-[0.125rem] focus:ring-indigo-400 dark:focus:ring-indigo-500- scrollbar-thin`"+ scrollbar-minimal scrollbar-track:bg-neutral-300 scrollbar-track:dark:bg-neutral-800`":style="`max-height: ${maxHeight}px;`":name="field.name":title="field.name"diff --git a/resources/js/components/video/VideoAmbientPlayer.vue b/resources/js/components/video/VideoAmbientPlayer.vueindex e541a4a3..203809de 100755--- a/resources/js/components/video/VideoAmbientPlayer.vue+++ b/resources/js/components/video/VideoAmbientPlayer.vue@@ -202,7 +202,7 @@ watch(</Transition></span><!-- This is in place of an ambient background because audio does not have video to use for the effect -->-+ <!-- Is the poster or thumbnail at a slightly larger size compared to the video with a blur around the edges --><Transition enter-to-class="opacity-100" enter-from-class="opacity-0" leave-from-class="opacity-100" leave-to-class="opacity-0"><imgv-show="isAudio && ambientMode && !lightMode"diff --git a/resources/js/components/video/VideoLyrics.vue b/resources/js/components/video/VideoLyrics.vuenew file mode 100644index 00000000..fb27ca11--- /dev/null+++ b/resources/js/components/video/VideoLyrics.vue@@ -0,0 +1,161 @@+<script setup lang="ts">+import { computed, onMounted, onUnmounted, ref, useTemplateRef, watch } from 'vue';+import { nextTick } from 'vue';++const emit = defineEmits<{ (event: 'seek', value: number): void }>();+const props = defineProps<{ rawLyrics: string; timeElapsed: string | number; timeDuration: number; isPaused: boolean }>();++const lyrics = computed(() => {+ if (!props.rawLyrics) return [];++ return props.rawLyrics+ .split('\n')+ .map((line) => {+ const match = line.match(/\[(\d+):(\d+\.\d+)](.*)/);+ if (!match) return null;++ const [, min, sec, text] = match;+ const seconds = parseInt(min) * 60 + parseFloat(sec);+ return { time: seconds, text: text.trim(), percentage: toPercentageTime(seconds) };+ })+ .filter((line) => {+ return line !== null;+ });+});++const lyricsContainer = useTemplateRef<HTMLElement | null>('lyrics-container');+const $activeLyric = ref<HTMLElement | null>(null);+const lyricObserver = ref<IntersectionObserver>();++const activeTime = ref(0);+const isActiveLyricVisible = ref(false);+const isContainerVisible = ref(false);++const toPercentageTime = (seconds: number): number => {+ seconds = Math.min(Math.max(seconds, 0), props.timeDuration);++ return (seconds / props.timeDuration) * 100;+};++const handleClick = (id: string, seconds: number) => {+ document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'center' });+ if (!isNaN(seconds)) emit('seek', seconds);+};++function findCurrentLyric(lyrics: { percentage: number }[], currentTime: number): number {+ let low = 0,+ high = lyrics.length - 1;+ let resultIndex = -1;++ while (low <= high) {+ const mid = Math.floor((low + high) / 2);+ if (lyrics[mid].percentage <= currentTime) {+ resultIndex = mid;+ low = mid + 1;+ } else {+ high = mid - 1;+ }+ }++ return resultIndex;+}++const handleUpdate = () => {+ /**+ * Find index ...+ * Find Lyric ...+ * Find element ...+ * If last lyric is in view and container is in view, then scroll to new lyric+ * Wait for render+ * Unobserve last lyric+ * Set observer on new lyric+ */++ const currentTime = typeof props.timeElapsed === 'number' ? props.timeElapsed : parseFloat(props.timeElapsed);+ if (isNaN(currentTime)) return;++ const index = findCurrentLyric(lyrics.value, currentTime);+ if (index < 0) return;++ const current = lyrics.value[index];+ if (!current || !current.time) return;++ activeTime.value = current.time;++ const target = document.getElementById(`lyric-${current.time}`);+ if (!target) return;++ if (props.isPaused || (isContainerVisible.value && isActiveLyricVisible.value)) {+ target.scrollIntoView({ behavior: 'smooth', block: 'center' });+ }++ nextTick(() => {+ if (!lyricObserver.value) return;++ if ($activeLyric.value) lyricObserver.value.unobserve($activeLyric.value);++ if (!target) return;+ $activeLyric.value = target;+ lyricObserver.value?.observe($activeLyric.value);+ });+};++const resetComponent = () => {+ activeTime.value = 0;+ $activeLyric.value = null;+};++onMounted(() => {+ if (!lyricsContainer.value) return;++ const containerObserver = new IntersectionObserver(+ ([entry]) => {+ isContainerVisible.value = entry.isIntersecting;+ },+ {+ root: null,+ threshold: 1,+ },+ );++ containerObserver.observe(lyricsContainer.value);++ lyricObserver.value = new IntersectionObserver(+ ([entry]) => {+ isActiveLyricVisible.value = entry.isIntersecting;+ },+ {+ root: lyricsContainer.value,+ threshold: 0.5,+ },+ );++ if ($activeLyric.value) {+ lyricObserver.value.observe($activeLyric.value);+ }+});++onUnmounted(() => {+ lyricObserver.value?.disconnect();+});++watch(() => props.timeElapsed, handleUpdate);+watch(() => props.isPaused, handleUpdate);++watch(() => props.rawLyrics, resetComponent);+</script>+<template>+ <section class="relative flex flex-col h-full w-full my-auto overflow-y-scroll scrollbar-hide" ref="lyrics-container" v-show="lyrics.length > 0">+ <div class="shrink-0" style="height: 45%"></div>+ <div+ v-for="(lyric, index) in lyrics"+ @click="handleClick(`lyric-${lyric?.time ?? index}`, lyric?.time ?? NaN)"+ :class="`hover:bg-neutral-800/20 ${lyric?.time === activeTime || index === activeTime ? 'bg-neutral-800/40' : ''} w-full drop-shadow-lg text-center text-lg pointer-events-auto cursor-pointer`"+ :id="`lyric-${lyric?.time ?? index}`"+ :title="`${lyric.time}`"+ >+ {{ lyric?.text || '-' }}+ </div>+ <div class="shrink-0" style="height: 45%"></div>+ </section>+</template>diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vueindex 279b1c89..7234c15d 100755--- a/resources/js/components/video/VideoPlayer.vue+++ b/resources/js/components/video/VideoPlayer.vue@@ -25,6 +25,7 @@ import VideoPopover from '@/components/video/VideoPopover.vue';import VideoTooltip from '@/components/video/VideoTooltip.vue';import VideoButton from '@/components/video/VideoButton.vue';import VideoSlider from '@/components/video/VideoSlider.vue';+import VideoLyrics from '@/components/video/VideoLyrics.vue';import ProiconsPictureInPictureEnter from '~icons/proicons/picture-in-picture-enter';import ProiconsFullScreenMaximize from '~icons/proicons/full-screen-maximize';@@ -34,6 +35,7 @@ import ProiconsFastForward from '~icons/proicons/fast-forward';import ProiconsVolumeMute from '~icons/proicons/volume-mute';import ProiconsVolumeLow from '~icons/proicons/volume-low';import ProiconsCheckmark from '~icons/proicons/checkmark';+import TablerMicrophone2 from '~icons/tabler/microphone-2';import ProiconsSparkle2 from '~icons/proicons/sparkle-2';import ProiconsSettings from '~icons/proicons/settings';import ProiconsSpinner from '~icons/proicons/spinner';@@ -44,6 +46,9 @@ import ProiconsPlay from '~icons/proicons/play';import MagePlaylist from '~icons/mage/playlist';import CircumTimer from '~icons/circum/timer';+import ProiconsClosedCaptions from '~icons/proicons/closed-captions';+import LucideCaptionsOff from '~icons/lucide/captions-off';+import LucideCaptions from '~icons/lucide/captions';/*** Z Index Layout:*@@ -85,7 +90,7 @@ const createPlayback = UseCreatePlayback().mutate;const timeDuration = computed(() => {return stateVideo.value?.metadata?.duration ?? 1;});-const timeElapsed = ref(0);+const timeElapsed = ref(0); // Out of 100const timeSeeking = ref('');const timeAutoSeek = ref(10);const currentVolume = ref(0.5);@@ -100,6 +105,7 @@ const volumeChangeTimeout = ref<number>();const controls = ref(false);const isPictureInPicture = ref(false);const isChangingVolume = ref(false);+const isLyricsEnabled = ref(false);const isShowingParty = ref(false);const isShowingStats = ref(false);const isMediaSession = ref(false);@@ -219,6 +225,17 @@ const videoPopoverItems = computed(() => {playbackHeatmap.value = !playbackHeatmap.value;},},+ {+ text: isAudio.value ? 'Lyrics' : 'Captions',+ title: `Toggle ${isAudio.value ? 'Lyrics' : 'Captions'}`,+ icon: isAudio.value ? TablerMicrophone2 : isLyricsEnabled.value ? LucideCaptions : LucideCaptionsOff,+ selectedIcon: ProiconsCheckmark,+ selected: isLyricsEnabled.value ?? false,+ selectedIconStyle: 'text-purple-600',+ action: () => {+ isLyricsEnabled.value = !isLyricsEnabled.value;+ },+ },{text: 'Playlist',title: 'Toggle Autoplay',@@ -623,6 +640,16 @@ const handlePositionState = () => {navigator.mediaSession.setPositionState(data);};+const handleManualSeek = async (seconds: number) => {+ if (!player.value) return;++ seconds = Math.min(Math.max(seconds, 0), timeDuration.value);++ timeElapsed.value = (seconds / timeDuration.value) * 100;++ handleSeek();+};+const handleSeek = async () => {if (!player.value || timeElapsed.value < 0 || timeElapsed.value > 100) return;@@ -926,9 +953,9 @@ defineExpose({<track kind="captions" />Your browser does not support the video tag.</video>- <section style="z-index: 4" :class="`player-controls text-white pointer-events-none font-mono text-xs ${controls ? 'cursor-auto' : 'cursor-none'}`">- <!-- Video Stats (Z-6) -->- <section class="absolute p-1 sm:p-4 top-0 left-0 pointer-events-auto" v-show="isShowingStats" style="z-index: 6">+ <section style="z-index: 4" :class="`player-controls text-white pointer-events-none font-mono text-xs ${controls ? 'cursor-auto' : 'cursor-none'}`" id="player-controls">+ <!-- Video Stats (Z-7) -->+ <section class="absolute p-1 sm:p-4 top-0 left-0 pointer-events-auto" v-show="isShowingStats" style="z-index: 7"><div class="flex gap-2 bg-neutral-900/80 border-slate-700/20 border rounded-md p-2 w-fit sm:min-w-52"><span class="[&>*]:line-clamp-1 [&>*]:break-all text-right"><p title="Dropped Frames vs Total Frames" v-if="!isAudio">Dropped Frames:</p>@@ -954,8 +981,8 @@ defineExpose({</div></section>- <!-- Watch Party (Z-6) -->- <section class="absolute p-1 sm:p-4 top-0 right-0 pointer-events-auto" v-show="isShowingParty" style="z-index: 6">+ <!-- Watch Party (Z-7) -->+ <section class="absolute p-1 sm:p-4 top-0 right-0 pointer-events-auto" v-show="isShowingParty" style="z-index: 7"><VideoPartyPanel :player="player ?? undefined" /></section>@@ -988,7 +1015,7 @@ defineExpose({></div></Transition>- <!-- Controls (Z-6) -->+ <!-- Controls (Z-7) --><Transitionenter-active-class="transition ease-out duration-300"enter-from-class="translate-y-full"@@ -1001,7 +1028,7 @@ defineExpose({v-cloakv-show="controls":class="`absolute bottom-0 left-0 w-full ${isFullScreen ? 'p-2 ' : ''}h-12 flex flex-col justify-end bg-gradient-to-b from-neutral-900/0 to-neutral-900/30 !pointer-events-none`"- style="z-index: 6"+ style="z-index: 7"><!-- Heatmap and Timeline --><section class="flex-1 w-full rounded-full flex flex-col-reverse px-2 h-8 relative">@@ -1135,7 +1162,7 @@ defineExpose({/></section><VideoPopover- popoverClass="!max-w-40 rounded-lg h-20 md:h-fit "+ popoverClass="!max-w-40 rounded-lg h-32 md:h-fit "ref="popover":margin="80":player="player ?? undefined"@@ -1145,7 +1172,7 @@ defineExpose({<ProiconsSettings class="w-4 h-4 hover:rotate-180 transition-transform ease-in-out duration-500" /></template><template #content>- <section class="flex flex-col h-16 md:h-fit overflow-y-auto scrollbar-minimal transition-transform">+ <section class="flex flex-col h-28 md:h-fit overflow-y-auto scrollbar-minimal transition-transform"><VideoPopoverItem v-for="(item, index) in videoPopoverItems" :key="index" v-bind="item" /><VideoPopoverSliderv-model="currentSpeed"@@ -1193,6 +1220,26 @@ defineExpose({</div></Transition>+ <!-- Lyrics / Captions (Z-6) -->+ <Transition+ enter-active-class="transition ease-out duration-300"+ enter-from-class="translate-y-full opacity-0"+ enter-to-class="translate-y-0 opacity-100"+ 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: 6" v-show="isLyricsEnabled">+ <VideoLyrics+ v-if="isAudio"+ @seek="handleManualSeek"+ :raw-lyrics="stateVideo?.metadata?.lyrics ?? ''"+ v-bind:time-duration="timeDuration"+ v-bind:time-elapsed="timeElapsed"+ v-bind:is-paused="isPaused"+ />+ </div>+ </Transition>+<!-- Title (Z-5) --><section v-show="controls && isFullScreen" :class="`w-fit h-fit absolute top-0 left-0 flex flex-col px-4 p-2 text-xl drop-shadow-md`" style="z-index: 5"><h2 class="line-clamp-1">{{ stateVideo.title }}</h2>@@ -1305,7 +1352,19 @@ defineExpose({</Transition></span></section>++ <!-- Lyrics / Captions blur (Z-4) -->+ <Transition+ enter-active-class="transition ease-out duration-300"+ enter-from-class="opacity-0"+ enter-to-class="opacity-100"+ 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 flex transition-all backdrop-blur-sm`" style="z-index: 3" v-show="isLyricsEnabled"></div>+ </Transition></section>+ <!-- Is a blurred copy of the thumbnail or poster as a backdrop to the clear poster --><divv-if="isAudio"id="audio-poster"