improve html5ified detection

pull/716/head
Mikael Finstad 5 years ago
parent 6031ee8647
commit d2f1994319
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -52,7 +52,7 @@ import {
getOutPath, toast, errorToast, showFfmpegFail, setFileNameTitle, getOutDir, withBlur, getOutPath, toast, errorToast, showFfmpegFail, setFileNameTitle, getOutDir, withBlur,
checkDirWriteAccess, dirExists, openDirToast, isMasBuild, isStoreBuild, dragPreventer, doesPlayerSupportFile, checkDirWriteAccess, dirExists, openDirToast, isMasBuild, isStoreBuild, dragPreventer, doesPlayerSupportFile,
isDurationValid, isWindows, filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate, isDurationValid, isWindows, filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate,
hasDuplicates, havePermissionToReadFile, isMac, hasDuplicates, havePermissionToReadFile, isMac, getFileBaseName,
} from './util'; } from './util';
import { formatDuration } from './util/duration'; import { formatDuration } from './util/duration';
import { askForOutDir, askForImportChapters, createNumSegments, createFixedDurationSegments, promptTimeOffset, askForHtml5ifySpeed, askForYouTubeInput, askForFileOpenAction, confirmExtractAllStreamsDialog, cleanupFilesDialog, showDiskFull, showCutFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, showMergeDialog, showOpenAndMergeDialog, openAbout } from './dialogs'; import { askForOutDir, askForImportChapters, createNumSegments, createFixedDurationSegments, promptTimeOffset, askForHtml5ifySpeed, askForYouTubeInput, askForFileOpenAction, confirmExtractAllStreamsDialog, cleanupFilesDialog, showDiskFull, showCutFailedDialog, labelSegmentDialog, openYouTubeChaptersDialog, showMergeDialog, showOpenAndMergeDialog, openAbout } from './dialogs';
@ -67,8 +67,8 @@ import loadingLottie from './7077-magic-flow.json';
const isDev = window.require('electron-is-dev'); const isDev = window.require('electron-is-dev');
const electron = window.require('electron'); // eslint-disable-line const electron = window.require('electron'); // eslint-disable-line
const trash = window.require('trash'); const trash = window.require('trash');
const { unlink, exists } = window.require('fs-extra'); const { unlink, exists, readdir } = window.require('fs-extra');
const { extname, parse: parsePath, sep: pathSep, join: pathJoin, normalize: pathNormalize, resolve: pathResolve, isAbsolute: pathIsAbsolute } = window.require('path'); const { extname, parse: parsePath, sep: pathSep, join: pathJoin, normalize: pathNormalize, resolve: pathResolve, isAbsolute: pathIsAbsolute, basename } = window.require('path');
const { dialog } = electron.remote; const { dialog } = electron.remote;
@ -802,6 +802,10 @@ const App = memo(() => {
if (!hideAllNotifications) toast.fire({ timer: 13000, text: i18n.t('File not natively supported. Preview may have no audio or low quality. The final export will however be lossless with audio. You may convert it from the menu for a better preview with audio.') }); if (!hideAllNotifications) toast.fire({ timer: 13000, text: i18n.t('File not natively supported. Preview may have no audio or low quality. The final export will however be lossless with audio. You may convert it from the menu for a better preview with audio.') });
}, [hideAllNotifications]); }, [hideAllNotifications]);
const showPreviewFileLoadedMessage = useCallback((fileName) => {
if (!hideAllNotifications) toast.fire({ text: i18n.t('Loaded existing preview file: {{ fileName }}', { fileName }) });
}, [hideAllNotifications]);
const createDummyVideo = useCallback(async (cod, fp) => { const createDummyVideo = useCallback(async (cod, fp) => {
const html5ifiedDummyPathDummy = getOutPath(cod, fp, 'html5ified-dummy.mkv'); const html5ifiedDummyPathDummy = getOutPath(cod, fp, 'html5ified-dummy.mkv');
try { try {
@ -1125,10 +1129,12 @@ const App = memo(() => {
} }
}, [playing, canvasPlayerEnabled]); }, [playing, canvasPlayerEnabled]);
const html5ifiedPrefix = 'html5ified-';
const getHtml5ifiedPath = useCallback((cod, fp, type) => { const getHtml5ifiedPath = useCallback((cod, fp, type) => {
// See also inside ffmpegHtml5ify // See also inside ffmpegHtml5ify
const ext = (isMac && ['slowest', 'slow', 'slow-audio'].includes(type)) ? 'mp4' : 'mkv'; const ext = (isMac && ['slowest', 'slow', 'slow-audio'].includes(type)) ? 'mp4' : 'mkv';
return getOutPath(cod, fp, `html5ified-${type}.${ext}`); return getOutPath(cod, fp, `${html5ifiedPrefix}${type}.${ext}`);
}, []); }, []);
const firstSegmentAtCursorIndex = useMemo(() => { const firstSegmentAtCursorIndex = useMemo(() => {
@ -1200,21 +1206,39 @@ const App = memo(() => {
setWorking(i18n.t('Loading file')); setWorking(i18n.t('Loading file'));
async function checkAndSetExistingHtml5FriendlyFile(speed) { async function checkAndSetExistingHtml5FriendlyFile() {
const existing = getHtml5ifiedPath(cod, fp, speed); const speeds = ['slowest', 'slow-audio', 'slow', 'fast-audio', 'fast', 'fastest-audio'];
const ret = existing && await exists(existing); const prefix = `${getFileBaseName(fp)}-${html5ifiedPrefix}`;
if (ret) {
console.log('Found existing supported file', existing); const outDir = getOutDir(cod, fp);
const dirEntries = await readdir(outDir);
let speed;
let path;
// eslint-disable-next-line no-restricted-syntax
for (const entry of dirEntries) {
const html5Match = entry.startsWith(prefix);
if (html5Match) {
path = pathJoin(outDir, entry);
const speedMatch = speeds.find((s) => new RegExp(`${s}\\..*$`).test(entry.replace(prefix, '')));
if (speedMatch) {
speed = speedMatch;
}
break;
}
}
if (!path) return false;
console.log('Found existing supported file', path, speed);
if (speed === 'fastest-audio') { if (speed === 'fastest-audio') {
setDummyVideoPath(existing); setDummyVideoPath(path);
setHtml5FriendlyPath(); setHtml5FriendlyPath();
} else { } else {
setHtml5FriendlyPath(existing); setHtml5FriendlyPath(path);
} }
showUnsupportedFileMessage(); showPreviewFileLoadedMessage(basename(path));
} return true;
return ret;
} }
try { try {
@ -1275,7 +1299,7 @@ const App = memo(() => {
setHtml5FriendlyPath(); setHtml5FriendlyPath();
showUnsupportedFileMessage(); showUnsupportedFileMessage();
} else if ( } else if (
!(await checkAndSetExistingHtml5FriendlyFile('slowest') || await checkAndSetExistingHtml5FriendlyFile('slow-audio') || await checkAndSetExistingHtml5FriendlyFile('slow') || await checkAndSetExistingHtml5FriendlyFile('fast-audio') || await checkAndSetExistingHtml5FriendlyFile('fast') || await checkAndSetExistingHtml5FriendlyFile('fastest-audio')) !(await checkAndSetExistingHtml5FriendlyFile())
&& !doesPlayerSupportFile(streams) && !doesPlayerSupportFile(streams)
&& validDuration && validDuration
) { ) {

@ -13,11 +13,15 @@ export function getOutDir(customOutDir, filePath) {
return undefined; return undefined;
} }
export function getOutPath(customOutDir, filePath, nameSuffix) { export function getFileBaseName(filePath) {
if (!filePath) return undefined; if (!filePath) return undefined;
const parsed = path.parse(filePath); const parsed = path.parse(filePath);
return parsed.name;
}
return path.join(getOutDir(customOutDir, filePath), `${parsed.name}-${nameSuffix}`); export function getOutPath(customOutDir, filePath, nameSuffix) {
if (!filePath) return undefined;
return path.join(getOutDir(customOutDir, filePath), `${getFileBaseName(filePath)}-${nameSuffix}`);
} }
export async function havePermissionToReadFile(filePath) { export async function havePermissionToReadFile(filePath) {

Loading…
Cancel
Save