From 5d2eebd1183c1be45568c3b50458bc38caeb4721 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 15 Apr 2019 21:05:49 +0200 Subject: [PATCH] Create AudioSource from RoyalAudioFile --- royalnet/audio/royalaudiofile.py | 13 ++++++++----- royalnet/audio/youtubedl.py | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/royalnet/audio/royalaudiofile.py b/royalnet/audio/royalaudiofile.py index d58aaf01..135942f2 100644 --- a/royalnet/audio/royalaudiofile.py +++ b/royalnet/audio/royalaudiofile.py @@ -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) diff --git a/royalnet/audio/youtubedl.py b/royalnet/audio/youtubedl.py index 40ced1f8..bd2476d4 100644 --- a/royalnet/audio/youtubedl.py +++ b/royalnet/audio/youtubedl.py @@ -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)