diff --git a/royalgames.py b/royalgames.py index 903a40fb..b971390b 100644 --- a/royalgames.py +++ b/royalgames.py @@ -12,9 +12,7 @@ loop = asyncio.get_event_loop() log = logging.root log.addHandler(logging.StreamHandler()) -logging.getLogger("royalnet.bots.telegram").setLevel(logging.DEBUG) logging.getLogger("royalnet.bots.discord").setLevel(logging.DEBUG) -logging.getLogger("royalnet.network.royalnetserver").setLevel(logging.DEBUG) commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand, AuthorCommand, DiarioCommand, RageCommand, DateparserCommand, ReminderCommand, KvactiveCommand, KvCommand, diff --git a/royalnet/audio/royalaudiofile.py b/royalnet/audio/royalaudiofile.py index 3617f40d..032d62dd 100644 --- a/royalnet/audio/royalaudiofile.py +++ b/royalnet/audio/royalaudiofile.py @@ -19,15 +19,19 @@ class RoyalAudioFile(YtdlFile): def __init__(self, info: "YtdlInfo", **ytdl_args): # Overwrite the new ytdl_args self.ytdl_args = {**self.ytdl_args, **ytdl_args} + log.info(f"Now downloading {info.webpage_url}") super().__init__(info, outtmpl="./opusfiles/%(title)s-%(id)s.%(ext)s", **self.ytdl_args) # Find the audio_filename with a regex (should be video.opus) + log.info(f"Starting conversion of {self.video_filename}") self.audio_filename = re.sub(rf"\.{self.info.ext}$", ".opus", self.video_filename) # Convert the video to opus # Actually not needed, but we do this anyways for compression reasons converter = ffmpeg.input(self.video_filename) \ .output(self.audio_filename) - converter.run() + converter.run(quiet=True) + log.info(f"Converted to {self.audio_filename}") # Delete the video file + log.info(f"Deleting {self.video_filename}") self.delete_video_file() @staticmethod diff --git a/royalnet/bots/discord.py b/royalnet/bots/discord.py index 6f8a3d7f..485b1225 100644 --- a/royalnet/bots/discord.py +++ b/royalnet/bots/discord.py @@ -3,6 +3,7 @@ import asyncio import typing import logging as _logging import sys +import functools from ..commands import NullCommand from ..utils import asyncify, Call, Command from ..error import UnregisteredError, NoneFoundError, TooManyFoundError @@ -235,12 +236,18 @@ class DiscordBot: await self.advance_music_data(guild) async def advance_music_data(self, guild: discord.Guild): + """Try to play the next song, while it exists. Otherwise, just return.""" guild_music_data = self.music_data[guild] - next_file = await guild_music_data.next() + voice_client = self.find_voice_client(guild) + next_file: RoyalAudioFile = await guild_music_data.next() if next_file is None: return - voice_client = self.find_voice_client(guild) - voice_client.play(next_file.as_audio_source(), after=lambda: loop.create_task(self.advance_music_data(guild))) + + def advance(error=None): + loop.create_task(self.advance_music_data(guild)) + + log.info(f"Starting to play {next_file.audio_filename}") + voice_client.play(next_file.as_audio_source(), after=advance) async def nh_play(self, message: PlayMessage): """Handle a play Royalnet request. That is, add audio to a PlayMode."""