From 969591a4e61f16b64fbe1cb192923e0c99709dfa Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 20 Apr 2019 12:57:46 +0200 Subject: [PATCH] Fix some more bugs --- royalnet/audio/royalpcmfile.py | 14 +++++--------- royalnet/audio/youtubedl.py | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/royalnet/audio/royalpcmfile.py b/royalnet/audio/royalpcmfile.py index 844acfac..ef407a45 100644 --- a/royalnet/audio/royalpcmfile.py +++ b/royalnet/audio/royalpcmfile.py @@ -1,16 +1,12 @@ import ffmpeg import os import typing -import logging as _logging import time from .youtubedl import YtdlFile, YtdlInfo -log = _logging.getLogger(__name__) - class RoyalPCMFile(YtdlFile): ytdl_args = { - "logger": log, # Log messages to a logging.Logger instance. "format": "bestaudio" # Fetch the best audio format available } @@ -24,17 +20,17 @@ class RoyalPCMFile(YtdlFile): raise FileExistsError("Can't overwrite file") # Overwrite the new ytdl_args self.ytdl_args = {**self.ytdl_args, **ytdl_args} - log.info(f"Now downloading {info.webpage_url}") + self.ytdl_args["log"].info(f"Now downloading {info.webpage_url}") super().__init__(info, outtmpl=self._ytdl_filename, **self.ytdl_args) # Find the audio_filename with a regex (should be video.opus) - log.info(f"Preparing {self.video_filename}...") + self.ytdl_args["log"].info(f"Preparing {self.video_filename}...") # Convert the video to pcm ffmpeg.input(f"./{self.video_filename}") \ .output(self.audio_filename, format="s16le", ac=2, ar="48000") \ .overwrite_output() \ - .run(quiet=not __debug__) + .run(quiet=False) # Delete the video file - log.info(f"Deleting {self.video_filename}") + self.ytdl_args["log"].info(f"Deleting {self.video_filename}") self.delete_video_file() def __repr__(self): @@ -54,5 +50,5 @@ class RoyalPCMFile(YtdlFile): return f"./downloads/{self.info.title}-{str(int(self._time))}.pcm" def __del__(self): - log.info(f"Deleting {self.audio_filename}") + self.ytdl_args["log"].info(f"Deleting {self.audio_filename}") os.remove(self.audio_filename) diff --git a/royalnet/audio/youtubedl.py b/royalnet/audio/youtubedl.py index 523e07de..2ee38c38 100644 --- a/royalnet/audio/youtubedl.py +++ b/royalnet/audio/youtubedl.py @@ -132,7 +132,7 @@ class YtdlInfo: return [YtdlInfo(first_info)] def download(self, outtmpl="%(title)s-%(id)s.%(ext)s", **ytdl_args) -> YtdlFile: - return YtdlFile(self, outtmpl) + return YtdlFile(self, outtmpl, **ytdl_args) def __repr__(self): if self.title: