我希望使用 if 和 elif 语句下载带字幕或不带字幕的视频。目前只有我的第一个选项有效,当我选择第二个选项时,尽管有第二个选项,第一个选项再次运行。
目前,我的实现是:
import youtube_dl
def switch_demo(x):
switcher = {
1: "With Subtitles",
2: "Without Subtitles",
}
return switcher.get(x,"Invalid Option")
x = int(input("Select the option\n1.With Subtitles\n2.Without Subtitles\n\n"))
print(switch_demo(x))
link=input('Please enter a url link\n')
if switch_demo(1):
ydl_opts = {"writesubtitles": True}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([link])
elif switch_demo(2):
ydl_opt = {}
with youtube_dl.YoutubeDL(ydl_opt) as ydl:
ydl.download([link])
我希望能够下载带或不带字幕的视频,这两个选项都可以工作。
海绵宝宝撒
DIEA
相关分类