Skip to content

Add support for filenames beginning with a dash #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def soxi(filepath: Union[str, Path], argument: str) -> str:

args = ['sox', '--i']
args.append("-{}".format(argument))
if filepath != "-n":
args.append("--")
args.append(filepath)

try:
Expand Down
9 changes: 9 additions & 0 deletions sox/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,12 @@ def build(self,
args = []
args.extend(self.globals)
args.extend(self._input_format_args(input_format))
if input_filepath != "-n":
args.append("--")
args.append(input_filepath)
args.extend(self._output_format_args(self.output_format))
if output_filepath != "-n":
args.append("--")
args.append(output_filepath)
args.extend(self.effects)

Expand Down Expand Up @@ -860,8 +864,12 @@ def build_array(self,
args = []
args.extend(self.globals)
args.extend(self._input_format_args(input_format))
if input_filepath != "-n":
args.append("--")
args.append(input_filepath)
args.extend(self._output_format_args(output_format))
if output_filepath != "-n":
args.append("--")
args.append(output_filepath)
args.extend(self.effects)

Expand Down Expand Up @@ -903,6 +911,7 @@ def preview(self, input_filepath: Union[str, Path]):
args = ["play", "--no-show-progress"]
args.extend(self.globals)
args.extend(self.input_format)
args.append("--")
args.append(input_filepath)
args.extend(self.effects)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import unittest
import shutil
import os

from sox import core
Expand All @@ -11,6 +12,7 @@ def relpath(f):


SPACEY_FILE = relpath("data/annoying filename (derp).wav")
DASHED_FILE = "-dashed.wav"
INPUT_FILE = relpath('data/input.wav')
INPUT_FILE_INVALID = relpath('data/input.xyz')
INPUT_FILE_CORRUPT = relpath('data/empty.aiff')
Expand Down Expand Up @@ -139,6 +141,13 @@ def test_spacey_wav(self):
expected = '80000'
self.assertEqual(expected, actual)

def test_dashed_wav(self):
shutil.copyfile(INPUT_FILE, DASHED_FILE)
actual = core.soxi(DASHED_FILE, 's')
expected = '441000'
self.assertEqual(expected, actual)
os.unlink(DASHED_FILE)

def test_invalid_argument(self):
with self.assertRaises(ValueError):
core.soxi(INPUT_FILE, 'booger')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_file_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import os
import shutil
import unittest

from sox import file_info
Expand All @@ -11,6 +12,7 @@ def relpath(f):


SPACEY_FILE = relpath("data/annoying filename (derp).wav")
DASHED_FILE = "-dashed.wav"
INPUT_FILE = relpath('data/input.wav')
INPUT_FILE2 = relpath('data/input.aiff')
INPUT_FILE3 = relpath('data/input.WAV')
Expand Down Expand Up @@ -135,6 +137,13 @@ def test_spacey_wav(self):
expected = 10.0
self.assertEqual(expected, actual)

def test_dashed_wav(self):
shutil.copyfile(INPUT_FILE, DASHED_FILE)
actual = file_info.duration(DASHED_FILE)
expected = 10.0
self.assertEqual(expected, actual)
os.unlink(DASHED_FILE)

def test_aiff(self):
actual = file_info.duration(INPUT_FILE2)
expected = 10.0
Expand Down Expand Up @@ -337,6 +346,13 @@ def test_valid_wspaces(self):
expected = None
self.assertEqual(expected, actual)

def test_valid_wdash(self):
shutil.copyfile(INPUT_FILE, DASHED_FILE)
actual = file_info.validate_input_file(DASHED_FILE)
expected = None
self.assertEqual(expected, actual)
os.unlink(DASHED_FILE)

def test_nonexistent(self):
with self.assertRaises(IOError):
file_info.validate_input_file('data/asdfasdfasdf.wav')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import os
import shutil
import unittest

from sox import transform, file_info
Expand All @@ -13,6 +14,8 @@ def relpath(f):


SPACEY_FILE = relpath("data/annoying filename (derp).wav")
DASHED_FILE = "-dashed.wav"
DASHED_OUTPUT_FILE = "-dashed-output.wav"
INPUT_FILE = relpath('data/input.wav')
INPUT_FILE4 = relpath('data/input4.wav')
OUTPUT_FILE = relpath('data/output.wav')
Expand Down Expand Up @@ -688,6 +691,13 @@ def test_valid_spacey(self):
status = self.tfm.build(SPACEY_FILE, OUTPUT_FILE)
self.assertTrue(status)

def test_valid_dashed(self):
shutil.copyfile(INPUT_FILE, DASHED_FILE)
status = self.tfm.build(DASHED_FILE, DASHED_OUTPUT_FILE)
self.assertTrue(status)
os.unlink(DASHED_FILE)
os.unlink(DASHED_OUTPUT_FILE)

def test_null_output(self):
status = self.tfm.build(INPUT_FILE, '-n')
self.assertTrue(status)
Expand Down Expand Up @@ -751,6 +761,12 @@ def test_valid_spacey(self):
arr_out = self.tfm.build_array(SPACEY_FILE)
self.assertTrue(isinstance(arr_out, np.ndarray))

def test_valid_dashed(self):
shutil.copyfile(INPUT_FILE, DASHED_FILE)
arr_out = self.tfm.build_array(DASHED_FILE)
self.assertTrue(isinstance(arr_out, np.ndarray))
os.unlink(DASHED_FILE)

def test_extra_arg(self):
arr_out = self.tfm.build_array(INPUT_FILE, extra_args=['norm'])
self.assertTrue(isinstance(arr_out, np.ndarray))
Expand Down