jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.82k stars 1.04k forks source link

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

Open nukemiko opened 9 months ago

nukemiko commented 9 months ago

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