在python脚本中使用youtube-dl仅从youtube视频下载音频 [英] download only audio from youtube video using youtube-dl in python script

查看:713
本文介绍了在python脚本中使用youtube-dl仅从youtube视频下载音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很少 帖子 -使用youtube-dl从YouTube下载音频,但是它们都不是具体的或有用的.我想知道从Python脚本执行此操作的最佳方法是什么.

There's a few posts on downloading audio from YouTube using youtube-dl, but none of them are concrete or too helpful. I'm wondering what the best way to do it from a Python script is.

例如,这是用于下载视频的README示例:

For example, here's the README example for downloading videos:

import youtube_dl

ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

很显然,如果您只关心音频,则不希望下载整个视频...

Obviously if you just care about the audio, you'd rather not download the whole video...

youtube-dl 源是只是很有帮助(即不是很有帮助).

The youtube-dl source is only so helpful (ie, not very).

有人建议如何编写脚本吗?

Any suggestions how to script this?

推荐答案

如果可能/受支持,它将下载音频文件.如果文件还不是mp3,则使用 ffmpeg avconv .有关更多信息,请参见 format postprocessors youtube-dl当前版本中的文档条目.

This will download an audio file if possible/supported. If the file is not mp3 already, the downloaded file be converted to mp3 using ffmpeg or avconv. For more information, refer to the format and postprocessors documentation entries in a current version of youtube-dl.

这篇关于在python脚本中使用youtube-dl仅从youtube视频下载音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆