# YTAudio Plays YouTube audio in voice channels through a Lavalink node. The cog resolves a query with yt-dlp, streams the audio into a growing file, and asks Lavalink's `local` source to play that file while yt-dlp keeps filling it. YTAudio also owns the process-wide Lavalink client for the whole bot. TtsToy depends on that connection. ## Requirements - A Lavalink node on `localhost:2333` with password `youshallnotpass`, defined in the source as `LL_HOST`, `LL_PORT`, `LL_PASSWORD`. - The `local` source enabled on the node. - A shared filesystem between the bot and the node, because Lavalink opens a path the bot creates. - `yt-dlp` installed in the bot's Python environment, plus `ffmpeg` on the PATH for the fallback conversion. - Python 3.9 or newer for `asyncio` usage, though the bot baseline is 3.11. ## Commands All commands are guild only and none of them have a permission check. Any member can control playback, change the volume, or disconnect the bot. | Command | Aliases | Arguments | Behavior | |---|---|---|---| | `[p]play` | none | `` | Joins your voice channel and queues a URL or search | | `[p]skip` | none | none | Skips the current track | | `[p]stop` | none | none | Stops playback and clears the queue | | `[p]pause` | none | none | Pauses the current track | | `[p]resume` | none | none | Resumes playback | | `[p]queue` | `q` | none | Shows the current track and what is next | | `[p]nowplaying` | `np` | none | Shows the current track | | `[p]volume` | none | `<0-150>` | Sets and saves the guild volume | | `[p]summon` | `ytjoin` | none | Joins your voice channel | | `[p]ytleave` | `ytdc` | none | Stops, disconnects and clears state | `play` accepts a full URL, a `www.` address, or a search phrase. Searches are resolved as `ytsearch1:`, so the first result is used. Playlists are disabled by yt-dlp options. When something is already playing, `play` replies with the queue position. When the queue was empty, the track starts immediately and progress is reported through status messages in the invoking channel. `volume` clamps to 0 through 150 and stores the value per guild. It applies to the active player and to the next track. `skip` aborts any in-flight resolution for the current track by setting its skip event, then stops the Lavalink player. The track end event advances the queue, so the cog does not signal the queue directly, which would skip two tracks. `stop` and `ytleave` also clear pending tracks and delete their temporary files. `ytleave` additionally disconnects the Lavalink player. `queue` truncates its output at 1900 characters. ## Playback pipeline 1. `play` ensures the bot has a Lavalink player and is connected to the author's voice channel. If the bot is in a different channel, the player is moved rather than reconnected. 2. A `QueuedTrack` is appended to the guild's pending list. The player loop wakes. 3. The loop takes the first pending track, sets it as current, and calls `_play_track`. 4. `_play_track` posts "Loading: " and sets the guild volume. 5. The streaming path resolves metadata with yt-dlp using `download=False`, which returns the direct media URL and title without downloading, subject to a 30 second resolver timeout. 6. A regular file is created under the cog data directory, and `python -m yt_dlp -f bestaudio/best -o - ` is started with its stdout writing directly into that file. The file must be a regular file because this Lavalink build's local loader rejects FIFOs. 7. The cog waits until the file reaches 64 KiB or the process exits, up to 15 seconds. A process that exits early counts as a stream failure. 8. Lavalink loads the path through its local source. On success the track plays while yt-dlp continues to write. 9. When the track ends, is skipped, or fails, the yt-dlp process is killed and the file is deleted. The stream path avoids Lavalink's own YouTube source and avoids a full download before playback. Tracks generally start within a few seconds, and a skip is immediate because it only requires killing a process. ### Fallback path If streaming fails, the cog edits the status to "Stream unavailable, downloading: " and downloads the audio through yt-dlp with an `FFmpegExtractAudio` postprocessor at 192 kbps, writing `