fix youtube import last segment #2552

pull/2599/head
Mikael Finstad 8 months ago
parent 2511040000
commit 2511040f84
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -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]);

@ -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) {

@ -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

Loading…
Cancel
Save