1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +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"), database_config=DatabaseConfig(os.environ["DB_PATH"], Royal, Telegram, "tg_id"),
commands=commands, commands=commands,
error_command=ErrorHandlerCommand) error_command=ErrorHandlerCommand)
loop.run_until_complete(master.run()) loop.run_until_complete(master.start())
loop.create_task(tg_bot.run()) loop.create_task(tg_bot.run())
loop.create_task(ds_bot.run()) loop.create_task(ds_bot.run())
print("Starting loop...") print("Starting loop...")

View file

@ -14,9 +14,6 @@ class RoyalPCMAudio(AudioSource):
rpf_list = RoyalPCMFile.create_from_url(url) rpf_list = RoyalPCMFile.create_from_url(url)
return [RoyalPCMAudio(rpf) for rpf in rpf_list] return [RoyalPCMAudio(rpf) for rpf in rpf_list]
def cleanup(self):
self._file.close()
def is_opus(self): def is_opus(self):
return False return False
@ -28,3 +25,7 @@ class RoyalPCMAudio(AudioSource):
def __repr__(self): def __repr__(self):
return f"<RoyalPCMAudio {self.rpf.audio_filename}>" 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 os
import typing import typing
import logging as _logging import logging as _logging
import time
from .youtubedl import YtdlFile, YtdlInfo from .youtubedl import YtdlFile, YtdlInfo
log = _logging.getLogger(__name__) log = _logging.getLogger(__name__)
@ -16,6 +17,8 @@ class RoyalPCMFile(YtdlFile):
def __init__(self, info: "YtdlInfo", **ytdl_args): def __init__(self, info: "YtdlInfo", **ytdl_args):
# Preemptively initialize info to be able to generate the filename # Preemptively initialize info to be able to generate the filename
self.info = info self.info = info
# Set the time to generate the filename
self._time = time.time()
# Ensure the file doesn't already exist # Ensure the file doesn't already exist
if os.path.exists(self._ytdl_filename) or os.path.exists(self.audio_filename): if os.path.exists(self._ytdl_filename) or os.path.exists(self.audio_filename):
raise FileExistsError("Can't overwrite file") raise FileExistsError("Can't overwrite file")
@ -29,10 +32,10 @@ class RoyalPCMFile(YtdlFile):
ffmpeg.input(f"./{self.video_filename}") \ ffmpeg.input(f"./{self.video_filename}") \
.output(self.audio_filename, format="s16le", ac=2, ar="48000") \ .output(self.audio_filename, format="s16le", ac=2, ar="48000") \
.overwrite_output() \ .overwrite_output() \
.run(quiet=True) .run(quiet=not __debug__)
# Delete the video file # Delete the video file
log.info(f"Deleting {self.video_filename}") # log.info(f"Deleting {self.video_filename}")
self.delete_video_file() # self.delete_video_file()
def __repr__(self): def __repr__(self):
return f"<RoyalPCMFile {self.audio_filename}>" return f"<RoyalPCMFile {self.audio_filename}>"
@ -44,11 +47,11 @@ class RoyalPCMFile(YtdlFile):
@property @property
def _ytdl_filename(self): 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 @property
def audio_filename(self): 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): def __del__(self):
log.info(f"Deleting {self.audio_filename}") 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") log.debug(f"Adding {audio_source} to music_data")
guild_music_data.add(audio_source) guild_music_data.add(audio_source)
if guild_music_data.now_playing is None: if guild_music_data.now_playing is None:
log.debug(f"Starting playback chain")
await self.advance_music_data(guild) await self.advance_music_data(guild)
async def advance_music_data(self, guild: discord.Guild): async def advance_music_data(self, guild: discord.Guild):
"""Try to play the next song, while it exists. Otherwise, just return.""" """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] guild_music_data = self.music_data[guild]
voice_client = self.client.find_voice_client_by_guild(guild) voice_client = self.client.find_voice_client_by_guild(guild)
next_source: RoyalPCMAudio = await guild_music_data.next() next_source: RoyalPCMAudio = await guild_music_data.next()
@ -219,6 +219,8 @@ class DiscordBot(GenericBot):
return return
def advance(error=None): def advance(error=None):
if error:
raise Exception(f"Error while advancing music_data: {error}")
loop.create_task(self.advance_music_data(guild)) loop.create_task(self.advance_music_data(guild))
log.debug(f"Starting playback of {next_source}") log.debug(f"Starting playback of {next_source}")