Client

Client library.

exception youtube_unofficial.client.NoFeedbackToken

No feedback token found.

class youtube_unofficial.client.YouTubeClient(session: niquests.AsyncSession)

YouTube client for managing playlists and history.

async clear_playlist(playlist_id: str) None

Remove all videos from the specified playlist.

Use WL for Watch Later.

Parameters:
playlist_id : str

The ID of the playlist.

async clear_watch_history() bool

Clear watch history.

Returns:

True if the operation was successful, False otherwise.

Return type:

bool

Raises:

NoFeedbackToken – If the feedback token cannot be found in the page data.

async clear_watch_later() None

Remove all videos from the ‘Watch Later’ playlist.

async get_history_info() AsyncGenerator[dict[str, Any], None]

Get information about the History playlist.

Yields:

dict[str, Any] – The history information.

Raises:

RuntimeError – If a continuation token cannot be found.

async get_history_video_ids() AsyncGenerator[str, None]
async get_history_video_ids(*, return_dict: True = True) AsyncGenerator[HistoryVideoIDsEntry, None]
async get_history_video_ids(*, return_dict: False = False) AsyncGenerator[str, None]

Get video IDs from the History playlist.

Parameters:
return_dict : bool

If True, yield dictionaries with detailed video information.

Yields:

str | HistoryVideoIDsEntry – The video IDs or dictionaries with video information.

Raises:

TypeError – If expected keys are missing or of the wrong type.

async get_playlist_info(playlist_id: str) AsyncGenerator[PlaylistInfo, None]

Get playlist information.

Parameters:
playlist_id : str

The ID of the playlist.

Yields:

PlaylistInfo – The playlist information.

Raises:
  • KeyError – If expected response keys are missing, or continuation data is malformed.

  • RuntimeError – If the playlist renderer is missing when expected.

  • TypeError – If a continuation response is not a mapping.

async get_playlist_video_ids(playlist_id: str) AsyncGenerator[str, None]
async get_playlist_video_ids(playlist_id: str, *, return_dict: True) AsyncGenerator[PlaylistVideoIDsEntry, None]
async get_playlist_video_ids(playlist_id: str, *, return_dict: False) AsyncGenerator[str, None]

Get video IDs from a playlist.

Parameters:
playlist_id : str

The ID of the playlist.

return_dict : bool

If True, yield dictionaries.

Yields:

str | PlaylistVideoIDsEntry – The video IDs or dictionaries with video information.

async remove_set_video_id_from_playlist(playlist_id: str, set_video_id: str, *, cache_values: bool | None = False) bool

Remove a video from a playlist by its setVideoId.

Parameters:
playlist_id : str

The ID of the playlist.

set_video_id : str

The setVideoId of the video to remove.

cache_values : bool | None

If True, cache the values of the page and ytcfg. This is useful for performance reasons, but may cause issues if updates are needed.

Returns:

True if the operation was successful, False otherwise.

Return type:

bool

async remove_video_id_from_playlist(playlist_id: str, video_id: str, *, cache_values: bool | None = False) bool

Remove a video from a playlist.

Parameters:
playlist_id : str

The ID of the playlist.

video_id : str

The ID of the video to remove.

cache_values : bool | None

If True, cache the values of the page and ytcfg. This is useful for performance reasons, but may cause issues if updates are needed.

Returns:

True if the operation was successful, False otherwise.

Return type:

bool

async remove_video_ids_from_history(video_ids: collections.abc.Sequence[str]) bool

Delete a history entry by video ID.

Parameters:
video_ids : Sequence[str]

The video IDs to delete.

Returns:

True if the operation was successful, False otherwise.

Return type:

bool

session

Niquests AsyncSession instance.

async toggle_watch_history() bool

Pauses or resumes watch history depending on the current state.

Returns:

True if the operation was successful, False otherwise.

Return type:

bool