pysox icon indicating copy to clipboard operation
pysox copied to clipboard

Add support for filenames beginning with a dash

Open ideoforms opened this issue 4 years ago • 3 comments

I have a use case which requires support for filenames beginning with a dash (“-”). However, this is currently parsed as an extra argument, and causes sox/soxi to bail with an exit code of 1.

This PR addresses the issue by inserting a double-dash immediately before the filename (in input and output cases), and incorporates unit tests for these cases.

Please let me know if you have any concerns or would like any changes. Thanks for the excellent library!

ideoforms avatar Jan 16 '22 18:01 ideoforms

Coverage Status

Coverage increased (+0.009%) to 98.832% when pulling 8b77a30d2d40936ab4683ffa87a2517f8d7d253d on ideoforms:master into 0a428b88f76c41e93eecbf49bb27b97c7b3f9de7 on rabitt:master.

coveralls avatar Jan 26 '22 09:01 coveralls

@rabitt what are your thoughts?

lostanlen avatar Jan 26 '22 14:01 lostanlen

Looking at this PR again today, i feel like this program flow:

if input_filepath != "-n":
    args.append("--")
args.append(input_filepath)

appears enough times in the PR to warrant being a pysox function of its own, with a unit test. The -n case corresponds to a null filepath. Quote from the docs:

              This can be used in place of an  input  or  output  filename  to
              specify that a ‘null file’ is to be used.  Note that here, ‘null
              file’ refers to a SoX‐specific mechanism and is not  related  to
              any operating‐system mechanism with a similar name.

              Using a null file to input audio is equivalent to using a normal
              audio file that contains an infinite amount of silence,  and  as
              such  is  not  generally  useful unless used with an effect that
              specifies a finite time length (such as trim or synth).

              Using a null file to output  audio  amounts  to  discarding  the
              audio and is useful mainly with effects that produce information
              about the audio instead of affecting it (such  as  noiseprof  or
              stat).

Relatedly, does this PR support --null as filepath? (full-word synonym to -n)

lostanlen avatar Jan 05 '24 12:01 lostanlen