1
Fork 0
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:
Steffo 2019-04-20 12:57:46 +02:00
parent f49829e237
commit 969591a4e6
2 changed files with 6 additions and 10 deletions

View file

@ -1,16 +1,12 @@
import ffmpeg import ffmpeg
import os import os
import typing import typing
import logging as _logging
import time import time
from .youtubedl import YtdlFile, YtdlInfo from .youtubedl import YtdlFile, YtdlInfo
log = _logging.getLogger(__name__)
class RoyalPCMFile(YtdlFile): class RoyalPCMFile(YtdlFile):
ytdl_args = { ytdl_args = {
"logger": log, # Log messages to a logging.Logger instance.
"format": "bestaudio" # Fetch the best audio format available "format": "bestaudio" # Fetch the best audio format available
} }
@ -24,17 +20,17 @@ class RoyalPCMFile(YtdlFile):
raise FileExistsError("Can't overwrite file") raise FileExistsError("Can't overwrite file")
# Overwrite the new ytdl_args # Overwrite the new ytdl_args
self.ytdl_args = {**self.ytdl_args, **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) super().__init__(info, outtmpl=self._ytdl_filename, **self.ytdl_args)
# Find the audio_filename with a regex (should be video.opus) # 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 # Convert the video to pcm
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=not __debug__) .run(quiet=False)
# Delete the video file # 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() self.delete_video_file()
def __repr__(self): def __repr__(self):
@ -54,5 +50,5 @@ class RoyalPCMFile(YtdlFile):
return f"./downloads/{self.info.title}-{str(int(self._time))}.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}") self.ytdl_args["log"].info(f"Deleting {self.audio_filename}")
os.remove(self.audio_filename) os.remove(self.audio_filename)

View file

@ -132,7 +132,7 @@ class YtdlInfo:
return [YtdlInfo(first_info)] return [YtdlInfo(first_info)]
def download(self, outtmpl="%(title)s-%(id)s.%(ext)s", **ytdl_args) -> YtdlFile: 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): def __repr__(self):
if self.title: if self.title: