fixed yt.py pt3.
Some checks are pending
Build-nightly / docker (push) Waiting to run

This commit is contained in:
Umiko 2025-05-05 08:31:45 +07:00
parent adb6e075a4
commit 6047c36aa3

View File

@ -46,16 +46,21 @@ class YtService(_Service):
self._ydl_config = {
"format": "bestaudio/best",
"outtmpl": "%(title)s.%(ext)s",
"socket_timeout": 5,
"logger": logging.getLogger("root"),
"cookiefile": "/home/ttbot/data/cookies.txt",
"postprocessors": [
{ # Tambah postprocessor biar otomatis convert ke mp3
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "192",
}
],
"socket_timeout": 5,
"logger": logging.getLogger("root"),
"cookiefile": "/home/ttbot/data/cookies.txt"
"postprocessor_args": [
"-ar", "44100"
],
"prefer_ffmpeg": True,
"keepvideo": False,
}
def download(self, track: Track, file_path: str) -> None:
@ -65,13 +70,11 @@ class YtService(_Service):
super().download(track, file_path)
return
# Setting manual output template supaya filenya langsung ke file_path yang dikasih
ydl_opts = self._ydl_config.copy()
ydl_opts["outtmpl"] = file_path.rsplit(".", 1)[0] + ".mp3"
with YoutubeDL(ydl_opts) as ydl:
dl = get_suitable_downloader(info)(ydl, ydl_opts)
dl.download(file_path, info)
info = ydl.process_ie_result(info, download=True)
except Exception as e:
logging.error(f"Download error: {str(e)}", exc_info=True)
raise errors.ServiceError("Download failed")