mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Create AudioSource from RoyalAudioFile
This commit is contained in:
parent
6af6984380
commit
5d2eebd118
2 changed files with 13 additions and 10 deletions
|
@ -20,7 +20,7 @@ class RoyalAudioFile(YtdlFile):
|
|||
}
|
||||
|
||||
def __init__(self, info: "YtdlInfo", **ytdl_args):
|
||||
super().__init__(info, outtmpl="%(id)s-%(title)s.%(ext)s", **ytdl_args)
|
||||
super().__init__(info, outtmpl="%(title)s-%(id)s.%(ext)s", **ytdl_args)
|
||||
# Find the audio_filename with a regex (should be video.opus)
|
||||
self.audio_filename = re.sub(rf"\.{self.info.ext}$", ".opus", self.video_filename)
|
||||
# Convert the video to opus
|
||||
|
@ -30,11 +30,14 @@ class RoyalAudioFile(YtdlFile):
|
|||
# Delete the video file
|
||||
self.delete_video_file()
|
||||
|
||||
def delete_audio_file(self):
|
||||
# TODO: _might_ be unsafe, test this
|
||||
os.remove(self.audio_filename)
|
||||
|
||||
@staticmethod
|
||||
def create_from_url(url, **ytdl_args) -> typing.List["RoyalAudioFile"]:
|
||||
info_list = YtdlInfo.create_from_url(url)
|
||||
return [RoyalAudioFile(info) for info in info_list]
|
||||
|
||||
def delete_audio_file(self):
|
||||
# TODO: _might_ be unsafe, test this
|
||||
os.remove(self.audio_filename)
|
||||
|
||||
def as_audio_source(self):
|
||||
return discord.FFmpegPCMAudio(self.audio_filename)
|
||||
|
|
|
@ -39,14 +39,14 @@ class YtdlFile:
|
|||
# Final checks
|
||||
assert os.path.exists(self.video_filename)
|
||||
|
||||
@staticmethod
|
||||
def create_from_url(url, outtmpl="%(title)s-%(id)s.%(ext)s", **ytdl_args) -> typing.List["YtdlFile"]:
|
||||
info_list = YtdlInfo.create_from_url(url)
|
||||
return [info.download(outtmpl, **ytdl_args) for info in info_list]
|
||||
|
||||
def _stop_download(self):
|
||||
raise InterruptDownload()
|
||||
|
||||
@staticmethod
|
||||
def create_from_url(url, outtmpl="%(title)s-%(id)s.%(ext)s", progress_hooks=None, **ytdl_args) -> typing.List["YtdlFile"]:
|
||||
info_list = YtdlInfo.create_from_url(url)
|
||||
return [info.download(outtmpl, progress_hooks, **ytdl_args) for info in info_list]
|
||||
|
||||
def delete_video_file(self):
|
||||
# TODO: _might_ be unsafe, test this
|
||||
os.remove(self.video_filename)
|
||||
|
|
Loading…
Reference in a new issue