This commit is contained in:
parent
adb6e075a4
commit
6047c36aa3
@ -46,16 +46,21 @@ class YtService(_Service):
|
|||||||
self._ydl_config = {
|
self._ydl_config = {
|
||||||
"format": "bestaudio/best",
|
"format": "bestaudio/best",
|
||||||
"outtmpl": "%(title)s.%(ext)s",
|
"outtmpl": "%(title)s.%(ext)s",
|
||||||
|
"socket_timeout": 5,
|
||||||
|
"logger": logging.getLogger("root"),
|
||||||
|
"cookiefile": "/home/ttbot/data/cookies.txt",
|
||||||
"postprocessors": [
|
"postprocessors": [
|
||||||
{ # Tambah postprocessor biar otomatis convert ke mp3
|
{
|
||||||
"key": "FFmpegExtractAudio",
|
"key": "FFmpegExtractAudio",
|
||||||
"preferredcodec": "mp3",
|
"preferredcodec": "mp3",
|
||||||
"preferredquality": "192",
|
"preferredquality": "192",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"socket_timeout": 5,
|
"postprocessor_args": [
|
||||||
"logger": logging.getLogger("root"),
|
"-ar", "44100"
|
||||||
"cookiefile": "/home/ttbot/data/cookies.txt"
|
],
|
||||||
|
"prefer_ffmpeg": True,
|
||||||
|
"keepvideo": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
def download(self, track: Track, file_path: str) -> None:
|
def download(self, track: Track, file_path: str) -> None:
|
||||||
@ -65,13 +70,11 @@ class YtService(_Service):
|
|||||||
super().download(track, file_path)
|
super().download(track, file_path)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Setting manual output template supaya filenya langsung ke file_path yang dikasih
|
|
||||||
ydl_opts = self._ydl_config.copy()
|
ydl_opts = self._ydl_config.copy()
|
||||||
ydl_opts["outtmpl"] = file_path.rsplit(".", 1)[0] + ".mp3"
|
ydl_opts["outtmpl"] = file_path.rsplit(".", 1)[0] + ".mp3"
|
||||||
|
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
with YoutubeDL(ydl_opts) as ydl:
|
||||||
dl = get_suitable_downloader(info)(ydl, ydl_opts)
|
info = ydl.process_ie_result(info, download=True)
|
||||||
dl.download(file_path, info)
|
|
||||||
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user