From 59fa01afce3e7f8f4136a4b7760dd84b4c1aa55c Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:21:19 -0600 Subject: [PATCH] Fix from https://github.com/zorbaTheRainy for images throwing segfaults on has_audio --- subgen.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subgen.py b/subgen.py index 877ff52..180b307 100644 --- a/subgen.py +++ b/subgen.py @@ -223,6 +223,15 @@ def appendLine(result): # Append the new segment to the result's segments result.segments.append(newSegment) +def has_image_extension(file_path): + valid_extensions = ['.rgb', '.gif', '.pbm', '.pgm', '.ppm', '.tiff', '.rast', '.xbm', '.jpg', '.jpeg', '.bmp', '.png', '.webp', '.exr', '.bif'] # taken from the extensions detected by the imghdr module & added Emby's '.bif' files + + if os.path.exists(file_path): + file_extension = os.path.splitext(file_path)[1].lower() + return file_extension in valid_extensions + else: + return True # return a value that causes the file to be skipped. + @app.get("/plex") @app.get("/webhook") @app.get("/jellyfin") @@ -772,6 +781,8 @@ def get_jellyfin_admin(users): def has_audio(file_path): try: with av.open(file_path) as container: + if has_image_extension(file_path): + return False return any(stream.type == 'audio' for stream in container.streams) except (av.AVError, UnicodeDecodeError): return False