pycharm安装pytube工具包,可以参考github:https://github.com/nficano/pytube
from pytube import YouTube link = input("enter link of youtube vadio:") yt = YouTube(link) videos = yt.streams.filter(subtype='mp4').all() i = 1 for stream in videos: print(str(i) + " " + str(stream)) i += 1 stream_number = int(input("enter number:")) video = videos[stream_number-1]
# vadio文件夹必须存在,否则报错 video.download("D:/vadio") print("downloaded")
控制台操作:
enter link of youtube vadio:https://www.youtube.com/watch?v=BH7D2aLPekc 1 <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2"> 2 <Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2"> 3 <Stream: itag="136" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.4d401f"> 4 <Stream: itag="135" mime_type="video/mp4" res="480p" fps="30fps" vcodec="avc1.4d4014"> 5 <Stream: itag="134" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.4d401e"> 6 <Stream: itag="133" mime_type="video/mp4" res="240p" fps="30fps" vcodec="avc1.4d400c"> 7 <Stream: itag="160" mime_type="video/mp4" res="144p" fps="30fps" vcodec="avc1.4d400b"> 8 <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2"> enter number:1 downloaded