pushing old yt.py instead due to always error.

This commit is contained in:
Umiko 2025-05-05 10:06:38 +07:00
parent 167389067d
commit 6458f19226
2 changed files with 7 additions and 28 deletions

View File

@ -44,43 +44,23 @@ class YtService(_Service):
def initialize(self): def initialize(self):
self._ydl_config = { self._ydl_config = {
"format": "bestaudio/best", "skip_download": True,
"outtmpl": "%(title)s.%(ext)s", "format": "m4a/bestaudio/best[protocol!=m3u8_native]/best",
"socket_timeout": 5, "socket_timeout": 5,
"logger": logging.getLogger("root"), "logger": logging.getLogger("root"),
"cookiefile": "/home/ttbot/data/cookies.txt", "cookiefile": "/home/ttbot/data/cookies.txt"
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "192",
}
],
"postprocessor_args": [
"-ar", "44100"
],
"prefer_ffmpeg": True,
"keepvideo": False,
} }
def download(self, track: Track, file_path: str) -> None: def download(self, track: Track, file_path: str) -> None:
try: try:
info = track.extra_info info = track.extra_info
if not info: if not info:
# fallback ke parent class kalo gak ada info
super().download(track, file_path) super().download(track, file_path)
return return
ydl_opts = self._ydl_config.copy() with YoutubeDL(self._ydl_config) as ydl:
ydl_opts["outtmpl"] = file_path.rsplit(".", 1)[0] + ".mp3" dl = get_suitable_downloader(info)(ydl, self._ydl_config)
dl.download(file_path, info)
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])
except Exception as e: except Exception as e:
logging.error(f"Download error: {str(e)}", exc_info=True) logging.error(f"Download error: {str(e)}", exc_info=True)
raise errors.ServiceError("Download failed") raise errors.ServiceError("Download failed")

View File

@ -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. 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 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. 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... Fix user rights to upload file, hopefully...