擅长:python、mysql、java
<p>您可以从代码中<a href="https://docs.python.org/2/library/subprocess.html#subprocess.call" rel="nofollow noreferrer">call</a><a href="https://rg3.github.io/youtube-dl/" rel="nofollow noreferrer">youtube-dl</a>。使用--id只将视频的id限制为文件名。</p>
<pre><code>youtube-dl --extract-audio --id <link to video>
</code></pre>
<p>然后,您可以从代码中访问ID.mp3格式的音频文件。</p>
<p>示例:</p>
<pre><code>audioFile = 'Tj75Arhq5ho.mp3'
command = 'youtube-dl --extract-audio --id https://www.youtube.com/watch?v=Tj75Arhq5ho'
subprocess.call(command.split(), shell=False)
# ... do whatever you want with the audioFile here
</code></pre>