C:\Users\Username\Desktop>YTMP3.py URL
使用虚拟环境:
import pytube
import os
import sys
from pathlib import Path
from pytube import YouTube
destination = 'C:/Desktop/' + str(Path.home()) + '/Downloads'
def download_audio(url):
yt = YouTube(url)
print("Title: ", yt.title)
base, ext = os.path.splitext(yt)
newfile = base + ".mp3"
print("Downloading...")
yt.streams.filter(only_audio=True).first().download(output_path=destination, filename=newfile)
print("Download complete")
if __name__ == "__main__":
download_audio(str(sys.argv[1]))