fix: handle missing sponsorblock category names

This commit is contained in:
Ryan 2025-02-26 16:21:29 -05:00
parent 5430f7c632
commit 062676df26
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 4 additions and 2 deletions

View File

@ -28,11 +28,12 @@ async def sponsorblock_command(message):
text = [] text = []
for segment in video["segments"]: for segment in video["segments"]:
begin, end = map(int, segment["segment"]) begin, end = map(int, segment["segment"])
category_name = SPONSORBLOCK_CATEGORY_NAMES.get(segment["category"]) if (category := segment["category"]) in SPONSORBLOCK_CATEGORY_NAMES:
category = SPONSORBLOCK_CATEGORY_NAMES[category]
current = "**" if progress >= begin and progress < end else "" current = "**" if progress >= begin and progress < end else ""
text.append( text.append(
f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category_name if category_name else 'Unknown'}{current}" f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category}{current}"
) )
await utils.reply( await utils.reply(

View File

@ -21,6 +21,7 @@ OWNERS = [531392146767347712]
PREFIX = "%" PREFIX = "%"
SPONSORBLOCK_CATEGORY_NAMES = { SPONSORBLOCK_CATEGORY_NAMES = {
"music_offtopic": "non-music", "music_offtopic": "non-music",
"selfpromo": "self promotion",
"sponsor": "sponsored", "sponsor": "sponsored",
} }
RELOADABLE_MODULES = [ RELOADABLE_MODULES = [