pythondiscord.pyytdl

how to speed up ytdl playlist load [discord.py]


This is the ytdl options:

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)

Then to extract the info I tried like this:

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

and like this:

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

but in both cases the loading is extremely slow, it takes up to 2 minutes to load a playlist of 100 songs. So I thought of extracting the first song and playing it and in the meantime start the download the rest of the playlist, but I don't know how to do it, I don't know how to say stop at the first with ytdl. I heard ytdlp is faster but I have problems installing and I can't find any solutions on the internet

The most interesting example that I have found and that many recommend is this, saying that instead of downloading the song is streamed directly, but programmatically it seems to do the same thing, that is set download = False

This is the error I get while installing 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\

Solution

  • I solved my problem using ytdl and not ytdlp. Basically, to open the youtube link you can use the parameter

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

    in this way you don't download anything except some information like id, title, etc. It is enough to get all ids in the playlist, and then concat this id with the first part of youtube links

    "https://www.youtube.com/watch?v="+id