From 6458f19226b27c4d1c2e8cbde665ccfdf5632f96 Mon Sep 17 00:00:00 2001 From: Umiko Date: Mon, 5 May 2025 10:06:38 +0700 Subject: [PATCH] pushing old yt.py instead due to always error. --- bot/services/yt.py | 34 +++++++--------------------------- changelog.txt | 1 - 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/bot/services/yt.py b/bot/services/yt.py index 55446aa..e75c0cd 100644 --- a/bot/services/yt.py +++ b/bot/services/yt.py @@ -44,43 +44,23 @@ class YtService(_Service): def initialize(self): self._ydl_config = { - "format": "bestaudio/best", - "outtmpl": "%(title)s.%(ext)s", + "skip_download": True, + "format": "m4a/bestaudio/best[protocol!=m3u8_native]/best", "socket_timeout": 5, "logger": logging.getLogger("root"), - "cookiefile": "/home/ttbot/data/cookies.txt", - "postprocessors": [ - { - "key": "FFmpegExtractAudio", - "preferredcodec": "mp3", - "preferredquality": "192", - } - ], - "postprocessor_args": [ - "-ar", "44100" - ], - "prefer_ffmpeg": True, - "keepvideo": False, + "cookiefile": "/home/ttbot/data/cookies.txt" } def download(self, track: Track, file_path: str) -> None: try: info = track.extra_info if not info: - # fallback ke parent class kalo gak ada info super().download(track, file_path) return - - ydl_opts = self._ydl_config.copy() - ydl_opts["outtmpl"] = file_path.rsplit(".", 1)[0] + ".mp3" - - with YoutubeDL(ydl_opts) as ydl: - # Download langsung pakai URL dari info - url = info.get("webpage_url") - if not url: - raise errors.ServiceError("Missing webpage_url in track info") - ydl.download([url]) - + + with YoutubeDL(self._ydl_config) as ydl: + dl = get_suitable_downloader(info)(ydl, self._ydl_config) + dl.download(file_path, info) except Exception as e: logging.error(f"Download error: {str(e)}", exc_info=True) raise errors.ServiceError("Download failed") diff --git a/changelog.txt b/changelog.txt index 6a1a79e..bc35152 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,5 @@ This change log is written to find out the changes that have been made by Pandora, and the source code still refers to TTMediaBot. 5/5/2025 -Change the download from m4a to mp3, if it's work. Added new command: e, to add either link or new song to the extended track. if nothing is playing, it plays the track directly. Fix user rights to upload file, hopefully...