From 30c65a4def3d76a99c328411560f09a8ff22da72 Mon Sep 17 00:00:00 2001 From: James Ding Date: Mon, 29 Jun 2026 16:14:56 -0700 Subject: [PATCH 1/2] refactor(backend): extract a shared ffmpeg-gate helper for the extract* RPCs --- .../twango/jetplay/rpc/MediaAccessorImpl.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt b/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt index e749c37a..caafc724 100644 --- a/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt +++ b/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt @@ -108,24 +108,24 @@ class MediaAccessorImpl : MediaAccessor { send(TranscodeEvent.Done) } + // Shared shell for the extract* RPCs: ffmpeg gate, then file resolve, then a guarded extract. + private suspend fun withFfmpegResolvedFile( + fileId: VirtualFileId, + projectId: ProjectId, + default: T, + extract: (File) -> T, + ): T = withContext(Dispatchers.IO) { + if (!FfmpegAvailability.available) return@withContext default + val file = resolveFile(fileId, projectId) ?: return@withContext default + runCatching { extract(file) }.getOrDefault(default) + } + override suspend fun extractWaveform(fileId: VirtualFileId, projectId: ProjectId): List = - withContext(Dispatchers.IO) { - if (!FfmpegAvailability.available) return@withContext emptyList() - val file = resolveFile(fileId, projectId) ?: return@withContext emptyList() - runCatching { WaveformExtractor.extract(file) }.getOrDefault(emptyList()) - } + withFfmpegResolvedFile(fileId, projectId, emptyList()) { WaveformExtractor.extract(it) } override suspend fun extractMediaInfo(fileId: VirtualFileId, projectId: ProjectId): MediaInfo? = - withContext(Dispatchers.IO) { - if (!FfmpegAvailability.available) return@withContext null - val file = resolveFile(fileId, projectId) ?: return@withContext null - runCatching { MediaInfoExtractor.extract(file) }.getOrNull() - } + withFfmpegResolvedFile(fileId, projectId, null) { MediaInfoExtractor.extract(it) } override suspend fun extractSpectrogram(fileId: VirtualFileId, projectId: ProjectId): Spectrogram? = - withContext(Dispatchers.IO) { - if (!FfmpegAvailability.available) return@withContext null - val file = resolveFile(fileId, projectId) ?: return@withContext null - runCatching { SpectrogramExtractor.extract(file) }.getOrNull() - } + withFfmpegResolvedFile(fileId, projectId, null) { SpectrogramExtractor.extract(it) } } From 14359b1f9a185b6701ab13979db189c81d0bd526 Mon Sep 17 00:00:00 2001 From: James Ding Date: Mon, 29 Jun 2026 16:39:21 -0700 Subject: [PATCH 2/2] refactor(backend): drop redundant explicit type args on extract* helper calls The override return type drives inference, so / were unnecessary (Qodana notice). --- .../main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt b/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt index caafc724..47b4ff3c 100644 --- a/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt +++ b/backend/src/main/kotlin/dev/twango/jetplay/rpc/MediaAccessorImpl.kt @@ -124,8 +124,8 @@ class MediaAccessorImpl : MediaAccessor { withFfmpegResolvedFile(fileId, projectId, emptyList()) { WaveformExtractor.extract(it) } override suspend fun extractMediaInfo(fileId: VirtualFileId, projectId: ProjectId): MediaInfo? = - withFfmpegResolvedFile(fileId, projectId, null) { MediaInfoExtractor.extract(it) } + withFfmpegResolvedFile(fileId, projectId, null) { MediaInfoExtractor.extract(it) } override suspend fun extractSpectrogram(fileId: VirtualFileId, projectId: ProjectId): Spectrogram? = - withFfmpegResolvedFile(fileId, projectId, null) { SpectrogramExtractor.extract(it) } + withFfmpegResolvedFile(fileId, projectId, null) { SpectrogramExtractor.extract(it) } }