diff --git a/bot/services/yt.py b/bot/services/yt.py index 620033b..f2b23da 100644 --- a/bot/services/yt.py +++ b/bot/services/yt.py @@ -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")