From 2511040f847b7951bf5fce464ac8f978db4fa9bb Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Tue, 4 Nov 2025 23:07:40 +0800 Subject: [PATCH] fix youtube import last segment #2552 --- src/renderer/src/App.tsx | 2 +- src/renderer/src/dialogs/index.tsx | 9 +++++++-- src/renderer/src/edlStore.ts | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 650bae60..24f769ed 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -2245,7 +2245,7 @@ function App() { if (!checkFileOpened()) return; await withErrorHandling(async () => { - const edl = await askForEdlImport({ type, fps: detectedFps }); + const edl = await askForEdlImport({ type, fps: detectedFps, fileDuration }); if (edl.length > 0) loadCutSegments({ segments: edl, append: true, clampDuration: fileDuration }); }, i18n.t('Failed to import project file')); }, [checkFileOpened, detectedFps, fileDuration, loadCutSegments, withErrorHandling]); diff --git a/src/renderer/src/dialogs/index.tsx b/src/renderer/src/dialogs/index.tsx index 1c39ed09..52537d2d 100644 --- a/src/renderer/src/dialogs/index.tsx +++ b/src/renderer/src/dialogs/index.tsx @@ -28,7 +28,7 @@ export const showOpenDialog = async ({ dialog.showOpenDialog({ ...props, title, ...(filters != null ? { filters } : {}) }) ); -export async function askForYouTubeInput() { +export async function askForYouTubeInput({ fileDuration }: { fileDuration?: number | undefined }) { const example = i18n.t('YouTube video description\n00:00 Intro\n00:01 Chapter 2\n00:00:02.123 Chapter 3'); const { value } = await getSwal().Swal.fire({ title: i18n.t('Import text chapters / YouTube'), @@ -47,7 +47,12 @@ export async function askForYouTubeInput() { if (value == null) return []; - return parseYouTube(value); + const parsed = parseYouTube(value); + + // last segment shouldn't be a marker https://github.com/mifi/lossless-cut/discussions/2552 + return parsed.map((segment, i) => ( + i === parsed.length - 1 ? { ...segment, end: fileDuration } : segment + )); } export async function askForInputDir(defaultPath?: string | undefined) { diff --git a/src/renderer/src/edlStore.ts b/src/renderer/src/edlStore.ts index 66428774..7734d50e 100644 --- a/src/renderer/src/edlStore.ts +++ b/src/renderer/src/edlStore.ts @@ -155,8 +155,8 @@ export async function readEdlFile({ type, path, fps }: { throw new Error('Invalid EDL type'); } -export async function askForEdlImport({ type, fps }: { type: EdlImportType, fps?: number | undefined }) { - if (type === 'youtube') return askForYouTubeInput(); +export async function askForEdlImport({ type, fps, fileDuration }: { type: EdlImportType, fps?: number | undefined, fileDuration?: number | undefined }) { + if (type === 'youtube') return askForYouTubeInput({ fileDuration }); let filters; // eslint-disable-next-line unicorn/prefer-switch