|
8 | 8 | For further information, see https://python-soundfile.readthedocs.io/.
|
9 | 9 |
|
10 | 10 | """
|
11 |
| -__version__ = "0.10.3" |
| 11 | +__version__ = "0.11.0" |
12 | 12 |
|
13 | 13 | import os as _os
|
14 | 14 | import sys as _sys
|
15 |
| -from platform import machine as _machine |
16 | 15 | from os import SEEK_SET, SEEK_CUR, SEEK_END
|
17 | 16 | from ctypes.util import find_library as _find_library
|
18 | 17 | from _soundfile import ffi as _ffi
|
|
144 | 143 | _snd = _ffi.dlopen(_libname)
|
145 | 144 | except OSError:
|
146 | 145 | if _sys.platform == 'darwin':
|
| 146 | + from platform import machine as _machine |
| 147 | + _packaged_libname = 'libsndfile_' + machine() + '.dylib' |
147 | 148 | _libname = 'libsndfile.dylib'
|
148 | 149 | elif _sys.platform == 'win32':
|
149 | 150 | from platform import architecture as _architecture
|
150 |
| - _libname = 'libsndfile' + _architecture()[0] + '.dll' |
| 151 | + _packaged_libname = 'libsndfile_' + _architecture()[0] + '.dll' |
| 152 | + _libname = 'libsndfile.dll' |
| 153 | + elif _sys.platform == 'linux': |
| 154 | + _packaged_libname = 'libsndfile.so' # not provided! |
| 155 | + _libname = 'libsndfile.so' |
151 | 156 | else:
|
152 | 157 | raise
|
153 | 158 |
|
|
160 | 165 | while not _os.path.isdir(_path):
|
161 | 166 | _path = _os.path.abspath(_os.path.join(_path, '..'))
|
162 | 167 |
|
163 |
| - # Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of |
164 |
| - # `/usr/local/lib`. We are making sure we pick that up. |
165 |
| - if _sys.platform == 'darwin' and _machine() == 'arm64': |
166 |
| - _hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \ |
167 |
| - else '/usr/local/lib/' |
168 |
| - _snd = _ffi.dlopen(_os.path.join( |
169 |
| - _hbrew_path, _libname)) |
170 |
| - else: |
171 |
| - _snd = _ffi.dlopen(_os.path.join( |
172 |
| - _path, '_soundfile_data', _libname)) |
| 168 | + try: # packaged libsndfile: |
| 169 | + _snd = _ffi.dlopen(_os.path.join(_path, '_soundfile_data', _packaged_libname)) |
| 170 | + except OSError: # try system-wide libsndfile: |
| 171 | + # Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of |
| 172 | + # `/usr/local/lib`. We are making sure we pick that up. |
| 173 | + from platform import machine as _machine |
| 174 | + if _sys.platform == 'darwin' and _machine() == 'arm64': |
| 175 | + _hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \ |
| 176 | + else '/usr/local/lib/' |
| 177 | + _snd = _ffi.dlopen(_os.path.join(_hbrew_path, _libname)) |
| 178 | + else: |
| 179 | + # Try explicit file name, if the general does not work (e.g. on nixos) |
| 180 | + _snd = _ffi.dlopen(_libname) |
173 | 181 |
|
174 | 182 | __libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
|
175 | 183 | if __libsndfile_version__.startswith('libsndfile-'):
|
@@ -1368,9 +1376,9 @@ def copy_metadata(self):
|
1368 | 1376 | -------
|
1369 | 1377 |
|
1370 | 1378 | metadata: dict[str, str]
|
1371 |
| - A dict with all metadata. Possible keys are: 'title', 'copyright', |
1372 |
| - 'software', 'artist', 'comment', 'date', 'album', 'license', |
1373 |
| - 'tracknumber' and 'genre'. |
| 1379 | + A dict with all metadata. Possible keys are: 'title', 'copyright', |
| 1380 | + 'software', 'artist', 'comment', 'date', 'album', 'license', |
| 1381 | + 'tracknumber' and 'genre'. |
1374 | 1382 | """
|
1375 | 1383 | strs = {}
|
1376 | 1384 | for strtype, strid in _str_types.items():
|
|
0 commit comments