Skip to content
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

Cannot open files whose file names begin with dash - #765

Open
nukemiko opened this issue Dec 19, 2023 · 0 comments
Open

Cannot open files whose file names begin with dash - #765

nukemiko opened this issue Dec 19, 2023 · 0 comments

Comments

@nukemiko
Copy link

nukemiko commented Dec 19, 2023

Steps to reproduce

  1. Prefix the file name with a minus sign or dash -
  2. Try to open it with pydub.AudioSegment.from_file(filename)

Expected behavior

File can be opened.

Actual behavior

In [2]: segment = AudioSegment.from_file('-you-can\'t-open-this.flac')
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
Cell In[2], line 1
----> 1 segment = AudioSegment.from_file('-you-can\'t-open-this.flac')

File /usr/lib/python3.11/site-packages/pydub/audio_segment.py:728, in AudioSegment.from_file(cls, file, format, codec, parameters, start_second, duration, **kwargs)
    726     info = None
    727 else:
--> 728     info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
    729 if info:
    730     audio_streams = [x for x in info['streams']
    731                      if x['codec_type'] == 'audio']

File /usr/lib/python3.11/site-packages/pydub/utils.py:279, in mediainfo_json(filepath, read_ahead_limit)
    276 output = output.decode("utf-8", 'ignore')
    277 stderr = stderr.decode("utf-8", 'ignore')
--> 279 info = json.loads(output)
    281 if not info:
    282     # If ffprobe didn't give any information, just return it
    283     # (for example, because the file doesn't exist)
    284     return info

File /usr/lib/python3.11/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    341     s = s.decode(detect_encoding(s), 'surrogatepass')
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:
    348     cls = JSONDecoder

File /usr/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
    332 def decode(self, s, _w=WHITESPACE.match):
    333     """Return the Python representation of ``s`` (a ``str`` instance
    334     containing a JSON document).
    335 
    336     """
--> 337     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338     end = _w(s, end).end()
    339     if end != len(s):

File /usr/lib/python3.11/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    353     obj, end = self.scan_once(s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Your System configuration

  • Python version: 3.11.6
  • Pydub version: 0.25.1
  • ffmpeg or avlib?: ffmpeg
  • ffmpeg/avlib version: 2:6.1-3
@nukemiko nukemiko changed the title Cannot open files whose file names begin with a minus sign - Cannot open files whose file names begin with dash - Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant