How to store yt-dlp mp3 inside a memory object python

问题描述 投票:0回答:0
import yt_dlp
import io


def download(url):
    with yt_dlp.YoutubeDL() as ydl:
        info = ydl.extract_info(url, download=False)

    title = info["title"]
    ydl_opts = {
        'extract-audio': True,
        'format': "bestaudio/best",
        'audio-format': 'mp3',
        'outtmpl': '%(title)s.mp3',  # i don't want to store it here
    }

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download(url)

        # mp3_file = io.BytesIO()  #store it something like this

    # return mp3_files


download("YT-URL")

我想将 mp3_file 存储在 python 内存对象中,而不是将其下载并写入文件系统我如何实现此功能下载(url)应该返回包含 mp3file 的内存对象

提前感谢任何愿意提供帮助的人

python-3.x youtube-dl ytdl yt-dlp
© www.soinside.com 2019 - 2024. All rights reserved.