Compare commits

..

3 Commits

8 changed files with 73 additions and 20 deletions

View File

@ -22,6 +22,7 @@ class Command(Enum):
RELOAD = "reload" RELOAD = "reload"
RESUME = "resume" RESUME = "resume"
SKIP = "skip" SKIP = "skip"
SPONSORBLOCK = "sponsorblock"
STATUS = "status" STATUS = "status"
UPTIME = "uptime" UPTIME = "uptime"
VOLUME = "volume" VOLUME = "volume"

View File

@ -1,18 +1,20 @@
from .channel import join, leave from .channel import join, leave
from .playback import fast_forward, pause, playing, resume, volume from .playback import fast_forward, pause, playing, resume, volume
from .queue import queue_or_play, skip from .queue import queue_or_play, skip
from .sponsorblock import sponsorblock_command
from .utils import remove_queued from .utils import remove_queued
__all__ = [ __all__ = [
"fast_forward",
"join", "join",
"leave", "leave",
"fast_forward", "pause",
"playing", "playing",
"queue_or_play", "queue_or_play",
"skip",
"resume",
"pause",
"skip",
"remove_queued", "remove_queued",
"resume",
"skip",
"skip",
"sponsorblock_command",
"volume", "volume",
] ]

View File

@ -1,11 +1,11 @@
import disnake_paginator
import arguments import arguments
import disnake_paginator
from constants import EMBED_COLOR
from state import players
import commands import commands
import sponsorblock import sponsorblock
import utils import utils
from constants import EMBED_COLOR
from state import players
from .utils import command_allowed from .utils import command_allowed
@ -89,19 +89,15 @@ async def pause(message):
async def fast_forward(message): async def fast_forward(message):
tokens = commands.tokenize(message.content) tokens = commands.tokenize(message.content)
parser = arguments.ArgumentParser(tokens[0], "fast forward audio playback") parser = arguments.ArgumentParser(
group = parser.add_mutually_exclusive_group(required=True) tokens[0], "skip current sponsorblock segment"
group.add_argument( )
parser.add_argument(
"-s", "-s",
"--seconds", "--seconds",
nargs="?",
type=lambda v: arguments.range_type(v, min=0, max=300), type=lambda v: arguments.range_type(v, min=0, max=300),
help="the amount of seconds to fast forward", help="the amount of seconds to fast forward instead",
)
group.add_argument(
"-S",
"--sponsorblock",
action="store_true",
help="go to the end of the current sponsorblock segment",
) )
if not (args := await parser.parse_args(message, tokens)): if not (args := await parser.parse_args(message, tokens)):
return return
@ -114,7 +110,7 @@ async def fast_forward(message):
return return
seconds = args.seconds seconds = args.seconds
if args.sponsorblock: if not seconds:
video = await sponsorblock.get_segments( video = await sponsorblock.get_segments(
players[message.guild.id].current.player.id players[message.guild.id].current.player.id
) )

View File

@ -0,0 +1,45 @@
import disnake
import sponsorblock
import utils
import youtubedl
from constants import EMBED_COLOR
from state import players
from .utils import command_allowed
async def sponsorblock_command(message):
if not command_allowed(message, immutable=True):
return
if not message.guild.voice_client.source:
await utils.reply(message, "nothing is playing!")
return
progress = message.guild.voice_client.source.original.progress
video = await sponsorblock.get_segments(players[message.guild.id].current.player.id)
if not video:
await utils.reply(
message, "no sponsorblock segments were found for this video!"
)
return
text = []
for segment in video["segments"]:
begin, end = map(int, segment["segment"])
category_name = sponsorblock.CATEGORY_NAMES.get(segment["category"])
current = "**" if progress >= begin and progress < end else ""
text.append(
f"{current}`{youtubedl.format_duration(begin)}` - `{youtubedl.format_duration(end)}`: {category_name if category_name else 'Unknown'}{current}"
)
await utils.reply(
message,
embed=disnake.Embed(
title="Sponsorblock segments",
description="\n".join(text),
color=EMBED_COLOR,
),
)

View File

@ -30,6 +30,7 @@ RELOADABLE_MODULES = [
"commands.voice.playback", "commands.voice.playback",
"commands.voice.playing", "commands.voice.playing",
"commands.voice.queue", "commands.voice.queue",
"commands.voice.sponsorblock",
"commands.voice.utils", "commands.voice.utils",
"constants", "constants",
"core", "core",

View File

@ -146,6 +146,8 @@ async def on_message(message, edited=False):
await commands.bot.ping(message) await commands.bot.ping(message)
case C.LOOKUP: case C.LOOKUP:
await commands.tools.lookup(message) await commands.tools.lookup(message)
case C.SPONSORBLOCK:
await commands.voice.sponsorblock_command(message)
except Exception as e: except Exception as e:
await utils.reply( await utils.reply(
message, message,

View File

@ -50,6 +50,7 @@ async def transcript(
pass pass
if (message.guild.voice_client.source.id != initial_id) or kill["transcript"]: if (message.guild.voice_client.source.id != initial_id) or kill["transcript"]:
kill["transcript"] = False
break break

View File

@ -4,6 +4,11 @@ import aiohttp
from state import sponsorblock_cache from state import sponsorblock_cache
CATEGORY_NAMES = {
"music_offtopic": "non-music",
"sponsor": "sponsored",
}
async def get_segments(videoId: str): async def get_segments(videoId: str):
if videoId in sponsorblock_cache: if videoId in sponsorblock_cache: