擅长:python、mysql、java
<p>您可以使用<a href="https://github.com/rg3/youtube-dl" rel="nofollow noreferrer">youtube-dl</a>,它是用Python编写的,因此您可以从代码中导入它,下面是<a href="https://github.com/rg3/youtube-dl#embedding-youtube-dl" rel="nofollow noreferrer">readme</a>中的一个片段:</p>
<pre><code>from __future__ import unicode_literals
import youtube_dl
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])
</code></pre>
<p>然后可以在<code>ydl_opts</code>中设置<code>'preferredcodec': 'mp3'</code>。</p>