YouTube-dl的安装与使用:ytdl-org/youtube-dl: Command-line program to download videos from YouTube.com and other video sites (github.com)
下面是以m4a格式下载音频以及对应中文字幕的代码,下载音频需要电脑已安装ffmpeg
import youtube_dl import os import webbrowser // 保存有youtube链接的文件 with open("F:/work/youtube/url.txt",'r',encoding = "utf8") as f: quanbuURLS = f.readlines() print(len(quanbuURLS)) count = 1 for url in quanbuURLS: print('开始下载第{}个'.format(count)) os.chdir(r"F:/work/youtube/audio") #os.system("youtube-dl --write-auto-sub #--sub-lang es --write-auto-sub -f m4a " + url) # 下载音频 os.system("youtube-dl -f m4a " + url) # 下载中文字幕 os.system("youtube-dl --write-sub --sub-lang zh-CN --skip-download " + url) os.system("youtube-dl --write-sub --sub-lang zh-Hans --skip-download " + url) os.system("youtube-dl --write-sub --sub-lang zh-Hant --skip-download " + url) os.system("youtube-dl --write-sub --sub-lang zh --skip-download " + url) print('第{}个下载完成,已完成{:.3f}'.format(count, count / len(quanbuURLS))) count += 1