如何让它询问用户是否想要转换另一个视频?
我有以下代码,这是一个简单的 YouTube 到 MP4 转换器,但我想实现询问用户是否要转换另一个视频的功能,而不仅仅是“按按钮退出”
from pytube import YouTube
from pytube.cli import on_progress
from click import pause
# ask for the link from user
link = input("Enter the link of the YouTube video you want to download: ")
yt = YouTube(link, on_progress_callback=on_progress)
print("\n---------------------Video Details---------------------------------------")
# Showing details
print("\nTitle: ", yt.title, "\n")
print("Number of views: ", yt.views, "\n")
print("Length of video: ", yt.length, "\n")
print("Rating of video: ", yt.rating, "\n")
print("-----------------------Video Download---------------------------------------")
# Getting the highest resolution possible
ys = yt.streams.get_highest_resolution()
# Starting download and exiting
print("\n")
pause("Press any key to download...")
print("Downloading...")
ys.download()
print("Download completed!!")
print("\n")
pause("Thank you! Press any key to exit...")`
I have the following code, which is a simple YouTube to MP4 Converter, but I would like to implement the function that asks the user if they want to convert another video, not just "Press a button to exit"
from pytube import YouTube
from pytube.cli import on_progress
from click import pause
# ask for the link from user
link = input("Enter the link of the YouTube video you want to download: ")
yt = YouTube(link, on_progress_callback=on_progress)
print("\n---------------------Video Details---------------------------------------")
# Showing details
print("\nTitle: ", yt.title, "\n")
print("Number of views: ", yt.views, "\n")
print("Length of video: ", yt.length, "\n")
print("Rating of video: ", yt.rating, "\n")
print("-----------------------Video Download---------------------------------------")
# Getting the highest resolution possible
ys = yt.streams.get_highest_resolution()
# Starting download and exiting
print("\n")
pause("Press any key to download...")
print("Downloading...")
ys.download()
print("Download completed!!")
print("\n")
pause("Thank you! Press any key to exit...")`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,您可以做的是有一个 while 循环,其中包含您的代码,然后您可以询问用户是否希望继续。
您可以按照要求用户提供 YouTube 链接的方式,使用输入来完成此操作。然后您可以检查答案是是还是否,以及他们是否不想继续退出 while 循环并完成您的程序。
一个例子是:
what you can do in this case is to have a while loop that has your code inside of it and then you can ask the user if they wish to continue.
You can do that the same way you ask from the user to give you the youtube link, using input. Then you can check if the answer is yes or no and if they don't wish to continue exit the while loop and finish your program.
an example would be:
将整个代码放在
while True
中,在过程结束时,询问用户是否转换另一个视频,如果用户说否
,则中断循环。< br>最终的代码应该是这样的:
这是这个想法的简单实现!:)
也许你会带来更好的!
Put the whole code in a
while True
, at the end of the process, ask the user for converting another video, and if the user saidno
, break the loop.The final code should be sth like this:
It's a simple implementation of the idea!:)
Maybe you come with a better one!