1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Do some stuff

This commit is contained in:
Steffo 2019-04-20 02:19:40 +02:00
parent 34f3c290d3
commit 4ed802ff43
4 changed files with 16 additions and 10 deletions

View file

@ -39,7 +39,7 @@ tg_bot = TelegramBot(telegram_config=TelegramConfig(os.environ["TG_AK"]),
database_config=DatabaseConfig(os.environ["DB_PATH"], Royal, Telegram, "tg_id"),
commands=commands,
error_command=ErrorHandlerCommand)
loop.run_until_complete(master.run())
loop.run_until_complete(master.start())
loop.create_task(tg_bot.run())
loop.create_task(ds_bot.run())
print("Starting loop...")

View file

@ -14,9 +14,6 @@ class RoyalPCMAudio(AudioSource):
rpf_list = RoyalPCMFile.create_from_url(url)
return [RoyalPCMAudio(rpf) for rpf in rpf_list]
def cleanup(self):
self._file.close()
def is_opus(self):
return False
@ -28,3 +25,7 @@ class RoyalPCMAudio(AudioSource):
def __repr__(self):
return f"<RoyalPCMAudio {self.rpf.audio_filename}>"
def __del__(self):
self._file.close()
del self.rpf

View file

@ -2,6 +2,7 @@ import ffmpeg
import os
import typing
import logging as _logging
import time
from .youtubedl import YtdlFile, YtdlInfo
log = _logging.getLogger(__name__)
@ -16,6 +17,8 @@ class RoyalPCMFile(YtdlFile):
def __init__(self, info: "YtdlInfo", **ytdl_args):
# Preemptively initialize info to be able to generate the filename
self.info = info
# Set the time to generate the filename
self._time = time.time()
# Ensure the file doesn't already exist
if os.path.exists(self._ytdl_filename) or os.path.exists(self.audio_filename):
raise FileExistsError("Can't overwrite file")
@ -29,10 +32,10 @@ class RoyalPCMFile(YtdlFile):
ffmpeg.input(f"./{self.video_filename}") \
.output(self.audio_filename, format="s16le", ac=2, ar="48000") \
.overwrite_output() \
.run(quiet=True)
.run(quiet=not __debug__)
# Delete the video file
log.info(f"Deleting {self.video_filename}")
self.delete_video_file()
# log.info(f"Deleting {self.video_filename}")
# self.delete_video_file()
def __repr__(self):
return f"<RoyalPCMFile {self.audio_filename}>"
@ -44,11 +47,11 @@ class RoyalPCMFile(YtdlFile):
@property
def _ytdl_filename(self):
return f"./downloads/{self.info.title}-{self.info.id}.ytdl"
return f"./downloads/{self.info.title}-{str(int(self._time))}.ytdl"
@property
def audio_filename(self):
return f"./downloads/{self.info.title}-{self.info.id}.pcm"
return f"./downloads/{self.info.title}-{str(int(self._time))}.pcm"
def __del__(self):
log.info(f"Deleting {self.audio_filename}")

View file

@ -206,11 +206,11 @@ class DiscordBot(GenericBot):
log.debug(f"Adding {audio_source} to music_data")
guild_music_data.add(audio_source)
if guild_music_data.now_playing is None:
log.debug(f"Starting playback chain")
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."""
log.debug(f"Starting playback chain")
guild_music_data = self.music_data[guild]
voice_client = self.client.find_voice_client_by_guild(guild)
next_source: RoyalPCMAudio = await guild_music_data.next()
@ -219,6 +219,8 @@ class DiscordBot(GenericBot):
return
def advance(error=None):
if error:
raise Exception(f"Error while advancing music_data: {error}")
loop.create_task(self.advance_music_data(guild))
log.debug(f"Starting playback of {next_source}")