mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Fix some more bugs
This commit is contained in:
parent
f49829e237
commit
969591a4e6
2 changed files with 6 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue