1

这是 ytdl 选项:

youtube_dl.utils.bug_reports_message = lambda: ''

ytdl_format_options = {
    'format': 'bestaudio/best',
    'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
    'restrictfilenames': True,
    'noplaylist': False,
    'nocheckcertificate': True,
    'ignoreerrors': False,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '0.0.0.0'  # bind to ipv4 since ipv6 addresses cause issues sometimes
}

ffmpeg_options = {
    'options': '-vn'
}

ytdl = youtube_dl.YoutubeDL(ytdl_format_options)

然后提取我尝试这样的信息:

with youtube_dl.YoutubeDL(self.YDL_OPTIONS) as ydl:
    info = ydl.extract_info(url, download=False)

像这样:

data = await self.client.loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))

但在这两种情况下,加载速度都非常慢,加载 100 首歌曲的播放列表最多需要 2 分钟。所以我想提取第一首歌并播放它,同时开始下载播放列表的其余部分,但我不知道该怎么做,我不知道如何用 ytdl 说停在第一首。我听说 ytdlp 更快,但我在安装时遇到问题,我在互联网上找不到任何解决方案

我发现并且许多人推荐的最有趣的例子是这个,它说下载歌曲不是直接流式传输,而是以编程方式似乎做同样的事情,即设置下载 = False

这是我在安装 ytdlp 时遇到的错误:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -DPYCRYPTO_LITTLE_ENDIAN -DSYS_BITS=64 -DLTC_NO_ASM -Isrc/ -IC:\Users\Gian\PycharmProjects\provabot\venv\include -IC:
\Users\Gian\Anaconda3\include -IC:\Users\Gian\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc/MD2.c /Fobuild\temp.win-amd64-3.6
\Release\src/MD2.obj
    MD2.c
    C:\Users\Gian\AppData\Local\Temp\pip-install-2_upmt2u\pycryptodomex\src\common.h(34): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "C:\Users\Gian\PycharmProjects\provabot\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Gian\\AppData\\Local\\Temp\\pip-install-2_upmt2u\\pycryptodomex\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace
('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Gian\AppData\Local\Temp\pip-record-19077se_\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\Gian\PycharmProjects\provabot\venv\include
\site\python3.6\pycryptodomex" failed with error code 1 in C:\Users\Gian\AppData\Local\Temp\pip-install-2_upmt2u\pycryptodomex\
4

1 回答 1

0

我使用 ytdl 而不是 ytdlp 解决了我的问题。基本上,要打开 youtube 链接,您可以使用参数

{'extract_flat': True, 'skip_download': True}

通过这种方式,您不会下载任何东西,除了一些信息,如 id、title 等。获取播放列表中的所有 id 就足够了,然后将这个 id 与 youtube 链接的第一部分连接起来

"https://www.youtube.com/watch?v="+id
于 2021-12-26T16:23:19.043 回答