Skip to content

Commit

Permalink
Added support for checking file extension of PathLikes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaden-young committed Feb 10, 2018
1 parent 1797918 commit 7de5a06
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pydub/audio_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,25 @@ def is_format(f):
return True
if isinstance(orig_file, basestring):
return orig_file.lower().endswith(".{0}".format(f))
if sys.version_info >= (3, 6):
try:
path = os.fspath(orig_file)

if isinstance(path, bytes):
try:
path = path.decode(sys.getdefaultencoding())
except Exception:
pass

return path.lower().endswith(".{0}".format(f))
except TypeError:
# Either orig_file was not a str, bytes, or PathLike
# object, or os.fspath() returned a byte string and and we
# failed to decode it, then endswith() tried to compare
# that with a regular str. In either case, we can't discern
# the file extension.
pass

return False

if is_format("wav"):
Expand Down

0 comments on commit 7de5a06

Please sign in to comment.