最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Getting the stream buffer data of a video when importing yt_dlp as library? - Stack Overflow

programmeradmin0浏览0评论

I have tried searching for my issue but have found no results similar

I have been experimenting around with yt_dlp and tried downloading to the io buffer using {'outtmpl': '-'} but unfortunately I don't know how to extract the stream buffer data from there.

My question is how would I do this in python?

Here is what I came up with

def download_video_to_buffer(url):
    buffer = io.BytesIO()
    output = StringIO()

    ydl_opts = {
        'format': 'best',
        'quiet': True, 
        'noplaylist': True, 
        'outtmpl': buffer 
    }
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])

    os.system("clear")

    print(output.read())

but unfortunately I alway get and error like this: AttributeError: '_io.BytesIO' object has no attribute 'replace'

I was expecting the function to return a bytearray of stream data but it didn't happen. My goal is to be able to do this without having to save any file to the filesystem but rather all in memory.`

发布评论

评论列表(0)

  1. 暂无评论