From 22e7e347b5f5110b69398585d2c42218c9623c76 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 5 Apr 2023 14:50:29 +0900 Subject: [PATCH] add more output format categories closes #1539 --- src/components/OutputFormatSelect.jsx | 38 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/components/OutputFormatSelect.jsx b/src/components/OutputFormatSelect.jsx index bdb1dce8..e6cde817 100644 --- a/src/components/OutputFormatSelect.jsx +++ b/src/components/OutputFormatSelect.jsx @@ -1,30 +1,32 @@ import React, { memo, useMemo } from 'react'; import i18n from 'i18next'; -import fromPairs from 'lodash/fromPairs'; import allOutFormats from '../outFormats'; import { withBlur } from '../util'; import Select from './Select'; -const commonFormats = ['mov', 'mp4', 'matroska', 'webm', 'mp3', 'ipod']; +const commonVideoAudioFormats = ['matroska', 'mov', 'mp4', 'mpegts', 'ogv', 'webm']; +const commonAudioFormats = ['flac', 'ipod', 'mp3', 'oga', 'ogg', 'opus', 'wav']; +const commonSubtitleFormats = ['ass', 'srt', 'sup', 'webvtt']; -function renderFormatOptions(map) { - return Object.entries(map).map(([f, name]) => ( - +function renderFormatOptions(formats) { + return formats.map((format) => ( + )); } const OutputFormatSelect = memo(({ style, detectedFileFormat, fileFormat, onOutputFormatUserChange }) => { - const commonFormatsMap = useMemo(() => fromPairs(commonFormats.map(format => [format, allOutFormats[format]]) - .filter(([f]) => f !== detectedFileFormat)), [detectedFileFormat]); + const commonVideoAudioFormatsExceptDetectedFormat = useMemo(() => commonVideoAudioFormats.filter((f) => f !== detectedFileFormat), [detectedFileFormat]); + const commonAudioFormatsExceptDetectedFormat = useMemo(() => commonAudioFormats.filter((f) => f !== detectedFileFormat), [detectedFileFormat]); + const commonSubtitleFormatsExceptDetectedFormat = useMemo(() => commonSubtitleFormats.filter((f) => f !== detectedFileFormat), [detectedFileFormat]); + const commonFormatsAndDetectedFormat = useMemo(() => new Set([...commonVideoAudioFormats, ...commonAudioFormats, commonSubtitleFormats, detectedFileFormat]), [detectedFileFormat]); - const otherFormatsMap = useMemo(() => fromPairs(Object.entries(allOutFormats) - .filter(([f]) => ![...commonFormats, detectedFileFormat].includes(f))), [detectedFileFormat]); + const otherFormats = useMemo(() => Object.keys(allOutFormats).filter((format) => !commonFormatsAndDetectedFormat.has(format)), [commonFormatsAndDetectedFormat]); return ( // eslint-disable-next-line react/jsx-props-no-spreading - onOutputFormatUserChange(e.target.value))}> + {detectedFileFormat && ( )} - - {renderFormatOptions(commonFormatsMap)} + + {renderFormatOptions(commonVideoAudioFormatsExceptDetectedFormat)} - - {renderFormatOptions(otherFormatsMap)} + + {renderFormatOptions(commonAudioFormatsExceptDetectedFormat)} + + + {renderFormatOptions(commonSubtitleFormatsExceptDetectedFormat)} + + + {renderFormatOptions(otherFormats)} ); });