Youtube-dl API: 'h' 不是有效的 URL
Youtube-dl API: 'h' is not a valid URL
大家好,我正在使用 youtube-dl 下载通用音频 MP4 文件,但我想使用 ffmpeg 将 mp4 文件转换为 mp3,我可以在 ytdl post 处理选项中执行此操作吗?
正如我上面提到的,该文件不是 YouTube 视频,它是一个通用的 link 我还将粘贴我的代码和我遇到的错误
import youtube_dl
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
url = "https://aac.saavncdn.com/372/16275cb323c0a13951a08c27660f0500_320.mp4"
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(url)
但是我收到一条错误消息说 'h' 不是有效的 URL
ERROR: 'h' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:h" ) to search YouTube
Traceback (most recent call last):
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 806, in wrapper
return func(self, *args, **kwargs)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 827, in __extract_info
ie_result = ie.extract(url)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/extractor/common.py", line 534, in extract
ie_result = self._real_extract(url)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/extractor/generic.py", line 2381, in _real_extract
raise ExtractorError(
youtube_dl.utils.ExtractorError: 'h' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:h" ) to search YouTube
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2059, in download
res = self.extract_info(
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 799, in extract_info
return self.__extract_info(url, ie, download, extra_info, process)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper
self.report_error(compat_str(e), e.format_traceback())
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 628, in report_error
self.trouble(error_message, tb)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 598, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: 'h' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:h" ) to search YouTube
谢谢
任何时候当你看到一个错误,你给它一个字符串,而 API 只看到一个字符,你需要怀疑 API 实际上需要一个列表或元组。这里就是这种情况。做:
ydl.download((url,))
大家好,我正在使用 youtube-dl 下载通用音频 MP4 文件,但我想使用 ffmpeg 将 mp4 文件转换为 mp3,我可以在 ytdl post 处理选项中执行此操作吗?
正如我上面提到的,该文件不是 YouTube 视频,它是一个通用的 link 我还将粘贴我的代码和我遇到的错误
import youtube_dl
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
url = "https://aac.saavncdn.com/372/16275cb323c0a13951a08c27660f0500_320.mp4"
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(url)
但是我收到一条错误消息说 'h' 不是有效的 URL
ERROR: 'h' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:h" ) to search YouTube
Traceback (most recent call last):
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 806, in wrapper
return func(self, *args, **kwargs)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 827, in __extract_info
ie_result = ie.extract(url)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/extractor/common.py", line 534, in extract
ie_result = self._real_extract(url)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/extractor/generic.py", line 2381, in _real_extract
raise ExtractorError(
youtube_dl.utils.ExtractorError: 'h' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:h" ) to search YouTube
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2059, in download
res = self.extract_info(
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 799, in extract_info
return self.__extract_info(url, ie, download, extra_info, process)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper
self.report_error(compat_str(e), e.format_traceback())
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 628, in report_error
self.trouble(error_message, tb)
File "/home/anishgowda/.local/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 598, in trouble
raise DownloadError(message, exc_info)
youtube_dl.utils.DownloadError: ERROR: 'h' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:h" ) to search YouTube
谢谢
任何时候当你看到一个错误,你给它一个字符串,而 API 只看到一个字符,你需要怀疑 API 实际上需要一个列表或元组。这里就是这种情况。做:
ydl.download((url,))