~.youtube
YouTube Audio Source
YouTubeAudioSource
YouTubeAudioSource(
url: str,
*,
bitrate: str | None = None,
channels: int | None = None,
name: str | None = None,
volume: float | str | None = None
)
Bases: AudioSource
YouTube audio source implementation.
Create a YouTube audio source.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
The YouTube URL of the audio source.
TYPE:
|
bitrate
|
If provided, the bitrate in which to play this source back at.
TYPE:
|
channels
|
If provided, the amount of channels this source plays with.
TYPE:
|
name
|
If provided, an internal name used for display purposes.
TYPE:
|
volume
|
If provided, overrides the player's set/default volume. Can be scaled ( |
Important
This source depends on YouTube's undocumented internal APIs via yt-dlp. As a result, it is best-effort and may break without notice if YouTube changes its internal behavior.
Functionality may require updating the pinned yt-dlp version to restore compatibility.
Basic video metadata is extracted on construction of this source. Using resolve_metadata will ensure this metadata is retrieved before using the metadata property.
Enhanced video metadata, like media URLs, is extracted on request internally by the player (to ensure non-expired timestamps and nonces). Using resolve_media does this as well.
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
|
ValueError
|
|
duration
property
duration: float | None
The duration of the media source URL, if discovered - Use resolve_metadata or resolve_media to attain if not discovered.
metadata
property
The metadata of the YouTube media provided, if discovered - Use resolve_metadata or resolve_media to attain if not discovered.
url_media
property
url_media: str | None
The media source URL that the YouTube URL points to, if discovered - Use resolve_media to attain if not discovered.
bitrate
property
bitrate: str | None
If provided, the bitrate in which this source is played back at.