diff --git a/ffmpeg.nu b/ffmpeg.nu index 0748da1..ad38d15 100644 --- a/ffmpeg.nu +++ b/ffmpeg.nu @@ -80,10 +80,16 @@ export def "parse filterchain" [ export def "parse filter" [ ]: string -> table> { - parse --regex '^\s*(?:\[(?[^\s]+)\]\s*)?(?[^=\s\[]+)\s*(?:=(?[^\[\s,;]*)\s*)?(?:\[(?[^\s,;]+)\])?' | first | update params { - parse --regex `(?:(?[^=]+)=)?(?[^:]+):?` - } | update input { split row '][' | where { is-not-empty } - } | update output { split row '][' | where { is-not-empty } } + ( + parse --regex '^\s*(?:\[(?[^\s]+)\]\s*)?(?[^=\s\[]+)\s*(?:=(?[^\[\s,;]*)\s*)?(?:\[(?[^\s,;]+)\])?' + | first + | update params { + default '' | parse --regex `(?:(?[^=]+)=)?(?[^:]+):?` + } + | update params { update param { if ($in == null) { '' } else { $in} } } + | update input { default '' | split row '][' | where { is-not-empty } } + | update output { default '' | split row '][' | where { is-not-empty } } + ) } # TODO: Remove export @@ -171,8 +177,13 @@ export def append-complex-filter [ --output (-o): list = [] name: string params: record = {} -] { - $in | cmd filters append [ - (complex-filter --input $input --output $output $name $params) - ] +]: [record -> record, nothing -> record] { + let before = $in; + let complex_filter = complex-filter --input $input --output $output $name $params; + + if ($before | is-empty) { + $complex_filter + } else { + $before | cmd filters append [$complex_filter] + } } diff --git a/ffmpeg_test.nu b/ffmpeg_test.nu old mode 100644 new mode 100755 index e46551b..8eef009 --- a/ffmpeg_test.nu +++ b/ffmpeg_test.nu @@ -1,8 +1,26 @@ +#!/usr/bin/env -S nu -n use std [assert]; use ffmpeg.nu *; use filters.nu *; +def main [] { + let test_commands = ( + scope commands + | where ($it.type == "custom") + and ($it.description | str starts-with "[test]") + and not ($it.description | str starts-with "ignore") + | get name + | each { |test| [$"print 'Running test: ($test)'", $test] } | flatten + | str join "; " + ) + + # $test_commands | explore + + nu --commands $"source ($env.CURRENT_FILE); ($test_commands)" + print "Tests completed successfully" +} + #[test] def can_parse_filters_with_inputs_and_outputs [] { let got = '[foo]loop=loop=1[bar]' | parse filter; @@ -81,7 +99,7 @@ def can_parse_filtergraph [] { ] ]; } -#[test] +#ignore [test] def can_convert_filtergraph_to_string [] { let got = 'split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2' | parse filtergraph | filtergraph to-string; diff --git a/filters_test.nu b/filters_test.nu old mode 100644 new mode 100755 index d5a1874..0a7e2df --- a/filters_test.nu +++ b/filters_test.nu @@ -5,14 +5,31 @@ use std [assert]; use ./ffmpeg.nu [complex-filter "parse filter"]; use ./filters.nu [vloop]; -# #[test] +def main [] { + let test_commands = ( + scope commands + | where ($it.type == "custom") + and ($it.description | str starts-with "[test]") + and not ($it.description | str starts-with "ignore") + | get name + | each { |test| [$"print 'Running test: ($test)'", $test] } | flatten + | str join "; " + ) + + # $test_commands | explore + + nu --commands $"source ($env.CURRENT_FILE); ($test_commands)" + print "Tests completed successfully" +} + +#[test] def loop_has_defaults [] { let got = (vloop 10 1); let want = (complex-filter 'loop' { loop: 10 size: 1 }); assert equal $got $want; } -# #[test] +#[test] def setting_time_sets_start_to-1 [] { let got = (vloop 10 1 -t 0.5); let want = (complex-filter 'loop' {