- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我希望使用 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])
我希望能够下载带或不带字幕的视频,并且这两个选项都有效。
最佳答案
您没有将 x
传递给函数,因此您永远不会改变结果,也就是说我已经重写了您的代码。
import youtube_dl
switcher = {
1: "With Subtitles",
2: "Without Subtitles",
}
def switch_demo(x):
return switcher.get(x, False)
print("Select an option")
print(*["#{} {}".format(i + 1, switcher[i + 1]) for i in range(max(switcher.keys()))], sep = "\n")
option = int(input("> "))
link = input('Please enter a url link\n')
useSubtitles = switch_demo(x)
ydl_opts = {"writesubtitles": useSubtitles}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([link])
关于python - 使用 youtube_dl 通过 if 和 elif 语句下载 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54834055/
如何防止打印 youtube_dl 错误日志? [tls @ 0x5599ebcc8d00] Error in the pull function. [https @ 0x5599ebcc65c0]
当我使用 youtube_dl Python 脚本中的库来下载视频,它会在控制台中打印以下内容: [youtube] [video]: Downloading webpage [youtube] Do
我正在寻找使用 Youtube_dl 库下载带字幕的视频。目前,我可以一次下载一个视频,但无法下载字幕。 目前,我的实现是: import youtube_dl link = input('Pleas
从youtube 中提取的自动英文字幕包含不可读形式的信息和重复的文本信息。 welcome my name is Helga Vieira and this 00:00:04.670 --> 00:
代码如下: from __future__ import unicode_literals import youtube_dl ydl_opts = { 'format': 'bestaudi
from __future__ import unicode_literals import youtube_dl print('Hello, please insert the url of the
在阅读 Youtube_DL 文档时,我看到了一个用于 format 的选项,但不太明白它的含义,而且我也找不到 options.py 文件。 | format: Video
我正在尝试使用 youtube_dl 检索 youtube 上纯音频文件的链接。我想知道是否有可能这样做。我在 python 代码中使用 youtube_dl 而不是终端。 非常感谢 最佳答案 只有极
如何获取我正在使用 youtube_dl 下载的视频的 URL? 我可以使用进度 Hook 获取下载的其他特征,例如文件路径: def progress_hook(response): if
我正在使用 python 嵌入式 youtube_dl,我想将视频内容直接下载到一个临时文件中。我试图创建一个 NamedTemporaryFile 并将 youtube_dl 写入其中,但我总是收到
我的目标:将播客下载为 MP3 在 Ubuntu 18.04 和 Nginx 上使用了 Python、Flask 和 Youtube_dl 我按照本教程设置了我的服务器:Flask app with
我一直在修改youtube_dl并且在将其实现到我的 Python 3.4 脚本中时遇到问题。 我只是想创建一个存储输出的变量(通过一些选项进行调整。) 但是,我似乎无法弄清楚如何向函数添加选项,并且
我正在用 python 制作一个 discord 音乐机器人,当我在我的电脑上运行该机器人时一切正常,但是当我通过 Replit.com 运行它时它返回一个错误。 Traceback (most re
我正在寻找一个 MPEG DASH 下载器,而 youtube_dl 刚刚找到了我。 给定一个 .mpd URL , 那么可以使用 youtube_dl 下载所有媒体片段吗? 最佳答案 要下载所有视频
我正在用 Python 3 制作一个小图形界面,它应该下载一个带有 URL 的 youtube 视频。 我用了youtube_dl模块。 这是我的代码: import youtube_dl # You
上下文:我正在尝试创建一个 ;play 我的 disord.py 机器人的命令 问题:我无法播放音乐 代码: ytdl_format_options = { 'format': 'bestau
我希望使用 if 和 elif 语句下载带字幕或不带字幕的视频。目前只有我的第一个选项有效,当我选择第二个选项时,尽管有第二个选项,第一个选项将再次运行。 目前,我的实现是: import youtu
我有一个 python 脚本来下载和保存 MP3,我想添加代码以从 MP3 的开头删除 5 秒。 def download(): ydl_opts = { 'format':
我正在尝试使用 pafy (0.5.4) 和 youtube_dl 从 youtube 流式传输选定的视频,但无论我使用什么网址,现在都会收到不可用的错误。 我的代码几周前可以正常工作,但是当我今天尝
我一直在为不和谐开发一个简单的音乐机器人,我的 friend 们要求提供一个功能,您可以在其中流式传输来自 youtube 直播的音频。这让我很困惑,我找不到任何好的资源来解决这个问题。这是重要的代码
我是一名优秀的程序员,十分优秀!