Fix from https://github.com/zorbaTheRainy for images throwing segfaults on has_audio

This commit is contained in:
McCloudS
2024-08-12 08:21:19 -06:00
committed by GitHub
parent c71defc05b
commit 59fa01afce

View File

@@ -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