@@ -434,7 +434,7 @@ export async function createFixedDurationSegments({ fileDuration, inputPlacehold
434
434
return edl ;
435
435
}
436
436
437
- export async function createRandomSegments ( fileDuration ) {
437
+ export async function createRandomSegments ( fileDuration : number ) {
438
438
const response = await askForSegmentsRandomDurationRange ( ) ;
439
439
if ( response == null ) return undefined ;
440
440
@@ -451,14 +451,14 @@ export async function createRandomSegments(fileDuration) {
451
451
return edl ;
452
452
}
453
453
454
- const MovSuggestion = ( { fileFormat } ) => ( fileFormat === 'mp4' ? < li > < Trans > Change output < b > Format</ b > from < b > MP4</ b > to < b > MOV</ b > </ Trans > </ li > : null ) ;
454
+ const MovSuggestion = ( { fileFormat } : { fileFormat : string | undefined } ) => ( fileFormat === 'mp4' ? < li > < Trans > Change output < b > Format</ b > from < b > MP4</ b > to < b > MOV</ b > </ Trans > </ li > : null ) ;
455
455
const OutputFormatSuggestion = ( ) => < li > < Trans > Select a different output < b > Format</ b > (< b > matroska</ b > and < b > mp4</ b > support most codecs)</ Trans > </ li > ;
456
456
const WorkingDirectorySuggestion = ( ) => < li > < Trans > Set a different < b > Working directory</ b > </ Trans > </ li > ;
457
457
const DifferentFileSuggestion = ( ) => < li > < Trans > Try with a < b > Different file</ b > </ Trans > </ li > ;
458
458
const HelpSuggestion = ( ) => < li > < Trans > See < b > Help</ b > </ Trans > menu</ li > ;
459
459
const ErrorReportSuggestion = ( ) => < li > < Trans > If nothing helps, you can send an < b > Error report</ b > </ Trans > </ li > ;
460
460
461
- export async function showExportFailedDialog ( { fileFormat, safeOutputFileName } ) {
461
+ export async function showExportFailedDialog ( { fileFormat, safeOutputFileName } : { fileFormat : string | undefined , safeOutputFileName : boolean } ) {
462
462
const html = (
463
463
< div style = { { textAlign : 'left' } } >
464
464
< Trans > Try one of the following before exporting again:</ Trans >
@@ -480,7 +480,7 @@ export async function showExportFailedDialog({ fileFormat, safeOutputFileName })
480
480
return value ;
481
481
}
482
482
483
- export async function showConcatFailedDialog ( { fileFormat } ) {
483
+ export async function showConcatFailedDialog ( { fileFormat } : { fileFormat : string | undefined } ) {
484
484
const html = (
485
485
< div style = { { textAlign : 'left' } } >
486
486
< Trans > Try each of the following before merging again:</ Trans >
@@ -517,7 +517,7 @@ export function openYouTubeChaptersDialog(text: string) {
517
517
} ) ;
518
518
}
519
519
520
- export async function labelSegmentDialog ( { currentName, maxLength } ) {
520
+ export async function labelSegmentDialog ( { currentName, maxLength } : { currentName : string , maxLength : number } ) {
521
521
const { value } = await Swal . fire ( {
522
522
showCancelButton : true ,
523
523
title : i18n . t ( 'Label current segment' ) ,
@@ -528,7 +528,7 @@ export async function labelSegmentDialog({ currentName, maxLength }) {
528
528
return value ;
529
529
}
530
530
531
- export async function selectSegmentsByLabelDialog ( currentName ) {
531
+ export async function selectSegmentsByLabelDialog ( currentName : string ) {
532
532
const { value } = await Swal . fire ( {
533
533
showCancelButton : true ,
534
534
title : i18n . t ( 'Select segments by label' ) ,
@@ -538,24 +538,47 @@ export async function selectSegmentsByLabelDialog(currentName) {
538
538
return value ;
539
539
}
540
540
541
- export async function selectSegmentsByTagDialog ( ) {
542
- const { value : value1 } = await Swal . fire ( {
543
- showCancelButton : true ,
544
- title : i18n . t ( 'Select segments by tag' ) ,
545
- text : i18n . t ( 'Enter tag name (in the next dialog you\'ll enter tag value)' ) ,
546
- input : 'text' ,
547
- } ) ;
548
- if ( ! value1 ) return undefined ;
541
+ export async function selectSegmentsByExprDialog ( inputValidator : ( v : string ) => string | undefined ) {
542
+ const examples = {
543
+ duration : { name : i18n . t ( 'Segment duration less than 5 seconds' ) , code : 'segment.duration < 5' } ,
544
+ start : { name : i18n . t ( 'Segment starts after 00:60' ) , code : 'segment.start > 60' } ,
545
+ label : { name : i18n . t ( 'Segment label' ) , code : "equalText(segment.label, 'My label')" } ,
546
+ tag : { name : i18n . t ( 'Segment tag value' ) , code : "equalText(segment.tags.myTag, 'tag value')" } ,
547
+ } ;
548
+
549
+ function addExample ( type : string ) {
550
+ Swal . getInput ( ) ! . value = examples [ type ] ?. code ?? '' ;
551
+ }
549
552
550
- const { value : value2 } = await Swal . fire ( {
553
+ const { value } = await ReactSwal . fire < string > ( {
551
554
showCancelButton : true ,
552
- title : i18n . t ( 'Select segments by tag' ) ,
553
- text : i18n . t ( 'Enter tag value' ) ,
555
+ title : i18n . t ( 'Select segments by expression' ) ,
554
556
input : 'text' ,
555
- } ) ;
556
- if ( ! value2 ) return undefined ;
557
+ html : (
558
+ < div style = { { textAlign : 'left' } } >
559
+ < div style = { { marginBottom : '1em' } } >
560
+ { i18n . t ( 'Enter an expression which will be evaluated for each segment. Segments for which the expression evaluates to "true" will be selected. For available syntax, see {{url}}.' , { url : 'https://mathjs.org/' } ) }
561
+ </ div >
557
562
558
- return { tagName : value1 , tagValue : value2 } ;
563
+ < div > < b > { i18n . t ( 'Variables' ) } :</ b > </ div >
564
+
565
+ < div style = { { marginBottom : '1em' } } >
566
+ segment.label, segment.start, segment.end, segment.duration
567
+ </ div >
568
+
569
+ < div > < b > { i18n . t ( 'Examples' ) } :</ b > </ div >
570
+
571
+ { Object . entries ( examples ) . map ( ( [ key , { name } ] ) => (
572
+ < button key = { key } type = "button" onClick = { ( ) => addExample ( key ) } className = "button-unstyled" style = { { display : 'block' , marginBottom : '.1em' } } >
573
+ { name }
574
+ </ button >
575
+ ) ) }
576
+ </ div >
577
+ ) ,
578
+ inputPlaceholder : 'segment.duration < 5' ,
579
+ inputValidator,
580
+ } ) ;
581
+ return value ;
559
582
}
560
583
561
584
export function showJson5Dialog ( { title, json } : { title : string , json : unknown } ) {
@@ -631,7 +654,7 @@ export async function askForPlaybackRate({ detectedFps, outputPlaybackRate }) {
631
654
const fps = detectedFps || 1 ;
632
655
const currentFps = fps * outputPlaybackRate ;
633
656
634
- function parseValue ( v ) {
657
+ function parseValue ( v : string ) {
635
658
const newFps = parseFloat ( v ) ;
636
659
if ( ! Number . isNaN ( newFps ) ) {
637
660
return newFps / fps ;
0 commit comments