@@ -276,9 +276,26 @@ def _define_library_prototypes(cls, lib: Any) -> Any:
276
276
lib .MediaInfo_Close .argtypes = [ctypes .c_void_p ]
277
277
lib .MediaInfo_Close .restype = None
278
278
279
+ @staticmethod
280
+ def _get_library_paths (os_is_nt : bool ) -> Tuple [str ]:
281
+ if os_is_nt :
282
+ library_paths = ("MediaInfo.dll" ,)
283
+ elif sys .platform == "darwin" :
284
+ library_paths = ("libmediainfo.0.dylib" , "libmediainfo.dylib" )
285
+ else :
286
+ library_paths = ("libmediainfo.so.0" ,)
287
+ script_dir = os .path .dirname (__file__ )
288
+ # Look for the library file in the script folder
289
+ for library in library_paths :
290
+ absolute_library_path = os .path .join (script_dir , library )
291
+ if os .path .isfile (absolute_library_path ):
292
+ # If we find it, don't try any other filename
293
+ library_paths = (absolute_library_path ,)
294
+ break
295
+ return library_paths
296
+
279
297
@classmethod
280
298
def _get_library (
281
- # pylint: disable=too-many-branches
282
299
cls ,
283
300
library_file : Optional [str ] = None ,
284
301
) -> Tuple [Any , Any , str , Tuple [int , ...]]:
@@ -288,25 +305,13 @@ def _get_library(
288
305
else :
289
306
lib_type = ctypes .CDLL
290
307
if library_file is None :
291
- if os_is_nt :
292
- library_names = ("MediaInfo.dll" ,)
293
- elif sys .platform == "darwin" :
294
- library_names = ("libmediainfo.0.dylib" , "libmediainfo.dylib" )
295
- else :
296
- library_names = ("libmediainfo.so.0" ,)
297
- script_dir = os .path .dirname (__file__ )
298
- # Look for the library file in the script folder
299
- for library in library_names :
300
- lib_path = os .path .join (script_dir , library )
301
- if os .path .isfile (lib_path ):
302
- # If we find it, don't try any other filename
303
- library_names = (lib_path ,)
304
- break
308
+ library_paths = cls ._get_library_paths (os_is_nt )
305
309
else :
306
- library_names = (library_file ,)
307
- for library in library_names :
310
+ library_paths = (library_file ,)
311
+ exceptions = []
312
+ for library_path in library_paths :
308
313
try :
309
- lib = lib_type (library )
314
+ lib = lib_type (library_path )
310
315
cls ._define_library_prototypes (lib )
311
316
# Without a handle, there might be problems when using concurrent threads
312
317
# https://github.com/sbraz/pymediainfo/issues/76#issuecomment-574759621
@@ -319,9 +324,13 @@ def _get_library(
319
324
else :
320
325
raise RuntimeError ("Could not determine library version" )
321
326
return (lib , handle , lib_version_str , lib_version )
322
- except OSError :
323
- pass
324
- raise OSError ("Failed to load library" )
327
+ except OSError as exc :
328
+ exceptions .append (str (exc ))
329
+ raise OSError (
330
+ "Failed to load library from {} - {}" .format (
331
+ ", " .join (library_paths ), ", " .join (exceptions )
332
+ )
333
+ )
325
334
326
335
@classmethod
327
336
def can_parse (cls , library_file : Optional [str ] = None ) -> bool :
0 commit comments