Skip to content

Commit

Permalink
Remove unnecessary copying functionality (#78)
Browse files Browse the repository at this point in the history
When the path is quoted, the api properly handles arbitrary allowed characters in the path
with the new handling
  • Loading branch information
Numerlor authored Aug 6, 2021
1 parent cff129a commit 9cf4af2
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions playsound.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,7 @@ def _playsoundWin(sound, block = True):
I never would have tried using windll.winmm without seeing his code.
'''
sound = _canonicalizePath(sound)

if any((c in sound for c in ' "\'()')):
from os import close, remove
from os.path import splitext
from shutil import copy
from tempfile import mkstemp

fd, tempPath = mkstemp(prefix = 'PS', suffix = splitext(sound)[1]) # Avoid generating files longer than 8.3 characters.
logger.info('Made a temporary copy of {} at {} - use other filenames with only safe characters to avoid this.'.format(sound, tempPath))
copy(sound, tempPath)
close(fd) # mkstemp opens the file, but it must be closed before MCI can open it.
try:
_playsoundWin(tempPath, block)
finally:
remove(tempPath)
return
sound = '"' + _canonicalizePath(sound) + '"'

from ctypes import create_unicode_buffer, windll, wintypes
from time import sleep
Expand All @@ -66,9 +50,6 @@ def winCommand(*command):
raise PlaysoundException(exceptionMessage)
return buf.value

if '\\' in sound:
sound = '"' + sound + '"'

try:
logger.debug('Starting')
winCommand(u'open {}'.format(sound))
Expand Down

0 comments on commit 9cf4af2

Please sign in to comment.