Skip to content

Commit 7aee019

Browse files
committed
refactor: use startswith() for SILK magic byte detection
Replace manual slice comparisons with startswith() — cleaner, less error-prone, and immune to off-by-one slice errors. Suggested by: sourcery-ai
1 parent 6dd54ab commit 7aee019

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

astrbot/core/utils/media_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ def _get_audio_magic_type(audio_path: str) -> str:
350350
if header[:4] == b"ftyp" and b"mp4" in header[:8]:
351351
return "mp4"
352352

353-
if header[:9] == b"#!SILK_V3":
353+
if header.startswith(b"#!SILK_V3"):
354354
return "silk"
355355

356356
# Tencent SILK: leading \x02 byte before #!SILK_V3
357-
if header[:1] == b"\x02" and header[1:10] == b"#!SILK_V3":
357+
if header.startswith(b"\x02#!SILK_V3"):
358358
return "silk"
359359

360360
return ""

0 commit comments

Comments
 (0)