Struct YtMusic

Source
pub struct YtMusic<A: AuthToken> { /* private fields */ }
Expand description

A handle to the YouTube Music API, wrapping a http client. Generic over AuthToken, as different AuthTokens may allow different queries to be executed. It is recommended to re-use these as they internally contain a connection pool.

§Documentation note

Examples given for methods on this struct will use fake or mock constructors. When using in a real environment, you will need to construct using a real token or cookie.

Implementations§

Source§

impl<A: AuthToken> YtMusic<A>

Source

pub async fn search<'a, Q: Into<SearchQuery<'a, BasicSearch>>>( &self, query: Q, ) -> Result<SearchResults>

Available on crate feature simplified-queries only.

API Search Query that returns results for each category if available.

§Usage
let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search("Beatles").await
Source

pub async fn search_artists<'a, Q: Into<SearchQuery<'a, FilteredSearch<ArtistsFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultArtist>>

Available on crate feature simplified-queries only.

API Search Query for Artists only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_artists("Beatles").await
Source

pub async fn search_albums<'a, Q: Into<SearchQuery<'a, FilteredSearch<AlbumsFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultAlbum>>

Available on crate feature simplified-queries only.

API Search Query for Albums only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_albums("Beatles").await
Source

pub async fn search_songs<'a, Q: Into<SearchQuery<'a, FilteredSearch<SongsFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultSong>>

Available on crate feature simplified-queries only.

API Search Query for Songs only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_songs("Beatles").await
Source

pub async fn search_playlists<'a, Q: Into<SearchQuery<'a, FilteredSearch<PlaylistsFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultPlaylist>>

Available on crate feature simplified-queries only.

API Search Query for Playlists only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_playlists("Beatles").await
Source

pub async fn search_community_playlists<'a, Q: Into<SearchQuery<'a, FilteredSearch<CommunityPlaylistsFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultPlaylist>>

Available on crate feature simplified-queries only.

API Search Query for Community Playlists only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_community_playlists("Beatles").await
Available on crate feature simplified-queries only.

API Search Query for Featured Playlists only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_featured_playlists("Beatles").await
Source

pub async fn search_episodes<'a, Q: Into<SearchQuery<'a, FilteredSearch<EpisodesFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultEpisode>>

Available on crate feature simplified-queries only.

API Search Query for Episodes only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_episodes("Beatles").await
Source

pub async fn search_podcasts<'a, Q: Into<SearchQuery<'a, FilteredSearch<PodcastsFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultPodcast>>

Available on crate feature simplified-queries only.

API Search Query for Podcasts only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_podcasts("Beatles").await
Source

pub async fn search_videos<'a, Q: Into<SearchQuery<'a, FilteredSearch<VideosFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultVideo>>

Available on crate feature simplified-queries only.

API Search Query for Videos only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_videos("Beatles").await
Source

pub async fn search_profiles<'a, Q: Into<SearchQuery<'a, FilteredSearch<ProfilesFilter>>>>( &self, query: Q, ) -> Result<Vec<SearchResultProfile>>

Available on crate feature simplified-queries only.

API Search Query for Profiles only.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.search_profiles("Beatles").await
Source

pub async fn get_artist<'a>( &self, query: impl Into<GetArtistQuery<'a>>, ) -> Result<ArtistParams>

Available on crate feature simplified-queries only.

Gets information about an artist and their top releases.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_artists("Beatles").await.unwrap();
yt.get_artist(&results[0].browse_id).await
Source

pub async fn get_artist_albums<'a, T: Into<ArtistChannelID<'a>>, U: Into<BrowseParams<'a>>>( &self, channel_id: T, browse_params: U, ) -> Result<Vec<GetArtistAlbumsAlbum>>

Available on crate feature simplified-queries only.

Gets a full list albums for an artist.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_artists("Beatles").await.unwrap();
let artist_top_albums = yt.get_artist(&results[0].browse_id).await.unwrap().top_releases.albums.unwrap();
yt.get_artist_albums(
    artist_top_albums.browse_id.unwrap(),
    artist_top_albums.params.unwrap(),
).await
Source

pub async fn get_album<'a, T: Into<AlbumID<'a>>>( &self, album_id: T, ) -> Result<GetAlbum>

Available on crate feature simplified-queries only.

Gets information about an album and its tracks.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_albums("Dark Side Of The Moon").await.unwrap();
yt.get_album(&results[0].album_id).await
Source

pub async fn get_watch_playlist_from_video_id<'a, S: Into<VideoID<'a>>>( &self, video_id: S, ) -> Result<WatchPlaylist>

Available on crate feature simplified-queries only.

Gets the information that’s available when playing a song or playlist; upcoming tracks and lyrics.

§Partially implemented

Tracks are not implemented - empty vector always returned. See GetWatchPlaylistQuery and YtMusic.query() for more ways to construct and run a GetWatchPlaylistQuery.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_songs("While My Guitar Gently Weeps").await.unwrap();
yt.get_watch_playlist_from_video_id(&results[0].video_id).await
Source

pub async fn get_lyrics<'a, T: Into<LyricsID<'a>>>( &self, lyrics_id: T, ) -> Result<Lyrics>

Available on crate feature simplified-queries only.

Gets song lyrics and the source.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_songs("While My Guitar Gently Weeps").await.unwrap();
let watch_playlist = yt.get_watch_playlist_from_video_id(&results[0].video_id).await.unwrap();
yt.get_lyrics(watch_playlist.lyrics_id).await
Source

pub async fn get_playlist<'a, T: Into<PlaylistID<'a>>>( &self, playlist_id: T, ) -> Result<GetPlaylist>

Available on crate feature simplified-queries only.

Gets information about a playlist and its tracks.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_featured_playlists("Heavy metal").await.unwrap();
yt.get_playlist(&results[0].playlist_id).await
Source

pub async fn get_search_suggestions<'a, S: Into<GetSearchSuggestionsQuery<'a>>>( &self, query: S, ) -> Result<Vec<SearchSuggestion>>

Available on crate feature simplified-queries only.

Gets search suggestions

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_search_suggestions("The Beat").await;
Source

pub async fn get_library_playlists(&self) -> Result<GetLibraryPlaylists>

Available on crate feature simplified-queries only.

Gets a list of all playlists in your Library.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_library_playlists().await;
Source

pub async fn get_library_artists(&self) -> Result<GetLibraryArtists>

Available on crate feature simplified-queries only.

Gets a list of all artists in your Library.

§Additional functionality

See GetLibraryArtistsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_library_artists().await;
Source

pub async fn get_library_songs( &self, ) -> Result<<GetLibrarySongsQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets a list of all songs in your Library.

§Additional functionality

See GetLibrarySongsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_library_songs().await;
Source

pub async fn get_library_albums(&self) -> Result<GetLibraryAlbums>

Available on crate feature simplified-queries only.

Gets a list of all albums in your Library.

§Additional functionality

See GetLibraryAlbumsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_library_albums().await;
Source

pub async fn get_library_artist_subscriptions( &self, ) -> Result<GetLibraryArtistSubscriptions>

Available on crate feature simplified-queries only.

Gets a list of all artist subscriptions in your Library.

§Additional functionality

See GetLibraryArtistSubscriptionsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_library_artist_subscriptions().await;
Source

pub async fn get_history(&self) -> Result<Vec<HistoryPeriod>>

Available on crate feature simplified-queries only.

Gets your recently played history.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_history().await;
Source

pub async fn remove_history_items( &self, feedback_tokens: Vec<FeedbackTokenRemoveFromHistory<'_>>, ) -> Result<Vec<ApiOutcome>>

Available on crate feature simplified-queries only.

Removes a list of items from your recently played history.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let history = yt.get_history().await.unwrap();
let first_history_token = match history.first().unwrap().items.first().unwrap() {
    ytmapi_rs::parse::HistoryItem::Song(i) => &i.feedback_token_remove,
    ytmapi_rs::parse::HistoryItem::Video(i) => &i.feedback_token_remove,
    ytmapi_rs::parse::HistoryItem::Episode(i) => &i.feedback_token_remove,
    ytmapi_rs::parse::HistoryItem::UploadSong(i) => &i.feedback_token_remove,
}.into();
yt.remove_history_items(vec![first_history_token]).await
Source

pub async fn edit_song_library_status( &self, query: EditSongLibraryStatusQuery<'_>, ) -> Result<Vec<ApiOutcome>>

Available on crate feature simplified-queries only.
Source

pub async fn rate_song<'a, T: Into<VideoID<'a>>>( &self, video_id: T, rating: LikeStatus, ) -> Result<()>

Available on crate feature simplified-queries only.

Sets the like status for a song.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_songs("While My Guitar Gently Weeps").await.unwrap();
yt.rate_song(&results[0].video_id, ytmapi_rs::common::LikeStatus::Liked).await
Source

pub async fn rate_playlist<'a, T: Into<PlaylistID<'a>>>( &self, playlist_id: T, rating: LikeStatus, ) -> Result<()>

Available on crate feature simplified-queries only.

Sets the like status for a playlist. A ‘Liked’ playlist will be added to your library, an ‘Indifferent’ will be removed, and a ‘Disliked’ will reduce the chance of it appearing in your recommendations.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.search_featured_playlists("Heavy metal")
   .await
   .unwrap();
yt.rate_playlist(
   &results[0].playlist_id,
   ytmapi_rs::common::LikeStatus::Liked,
).await
Source

pub async fn delete_playlist<'a, T: Into<PlaylistID<'a>>>( &self, playlist_id: T, ) -> Result<()>

Available on crate feature simplified-queries only.

Deletes a playlist you own.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_library_playlists().await.unwrap();
yt.delete_playlist(&results.playlists[0].playlist_id).await
Source

pub async fn create_playlist<T: CreatePlaylistType>( &self, query: CreatePlaylistQuery<'_, T>, ) -> Result<PlaylistID<'static>>

Available on crate feature simplified-queries only.

Creates a new playlist.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let playlists = yt.search_featured_playlists("Heavy metal")
   .await
   .unwrap();
let query = ytmapi_rs::query::CreatePlaylistQuery::new(
   "My heavy metal playlist",
   None,
   ytmapi_rs::query::PrivacyStatus::Public,
)
   .with_source(&playlists[0].playlist_id);
yt.create_playlist(query).await
Source

pub async fn add_video_items_to_playlist<'a, T: Into<PlaylistID<'a>>>( &self, playlist_id: T, video_ids: Vec<VideoID<'a>>, ) -> Result<Vec<AddPlaylistItem>>

Available on crate feature simplified-queries only.

Adds video items to a playlist you own.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let ytmapi_rs::parse::LibraryPlaylist { playlist_id, .. } =
   yt.get_library_playlists().await.unwrap().playlists.pop().unwrap();
let songs = yt.search_songs("Master of puppets").await.unwrap();
yt.add_video_items_to_playlist(
   playlist_id,
   songs.iter().map(|s| (&s.video_id).into()).collect()
).await
Source

pub async fn add_playlist_to_playlist<'a, T: Into<PlaylistID<'a>>, U: Into<PlaylistID<'a>>>( &self, destination_playlist: T, source_playlist: U, ) -> Result<Vec<AddPlaylistItem>>

Available on crate feature simplified-queries only.

Appends another playlist to a playlist you own.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let ytmapi_rs::parse::LibraryPlaylist { playlist_id, .. } =
   yt.get_library_playlists().await.unwrap().playlists.pop().unwrap();
let source_playlist = yt.search_featured_playlists("Heavy metal")
   .await
   .unwrap();
yt.add_playlist_to_playlist(
   playlist_id,
   &source_playlist[0].playlist_id
).await
Source

pub async fn remove_playlist_items<'a, T: Into<PlaylistID<'a>>>( &self, playlist_id: T, video_items: Vec<SetVideoID<'a>>, ) -> Result<()>

Available on crate feature simplified-queries only.

Removes items from a playlist you own.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let ytmapi_rs::parse::LibraryPlaylist { playlist_id, .. } =
   yt.get_library_playlists().await.unwrap().playlists.pop().unwrap();
let source_playlist = yt.search_featured_playlists("Heavy metal")
   .await
   .unwrap();
let outcome = yt.add_playlist_to_playlist(
   &playlist_id,
   &source_playlist[0].playlist_id
).await.unwrap();
yt.remove_playlist_items(
   playlist_id,
   outcome.iter().map(|o| (&o.set_video_id).into()).collect(),
).await
Source

pub async fn edit_playlist( &self, query: EditPlaylistQuery<'_>, ) -> Result<ApiOutcome>

Available on crate feature simplified-queries only.

Makes changes to a playlist.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let playlists = yt.get_library_playlists()
   .await
   .unwrap()
   .playlists;
let query = ytmapi_rs::query::EditPlaylistQuery::new_title(
   &playlists[0].playlist_id,
   "Better playlist title",
)
   .with_new_description("Edited description");
yt.edit_playlist(query).await
Source

pub async fn get_library_upload_songs( &self, ) -> Result<<GetLibraryUploadSongsQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets a list of all uploaded songs in your Library.

§Additional functionality

See GetLibraryUploadSongsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_library_upload_songs().await
Source

pub async fn get_library_upload_artists( &self, ) -> Result<<GetLibraryUploadArtistsQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets a list of all uploaded artists in your Library.

§Additional functionality

See GetLibraryUploadArtistsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_library_upload_artists().await
Source

pub async fn get_library_upload_albums( &self, ) -> Result<<GetLibraryUploadAlbumsQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets a list of all uploaded albums in your Library.

§Additional functionality

See GetLibraryUploadAlbumsQuery and YtMusic.query() for more ways to construct and run.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_library_upload_albums().await
Source

pub async fn get_library_upload_album<'a, T: Into<UploadAlbumID<'a>>>( &self, upload_album_id: T, ) -> Result<<GetLibraryUploadAlbumQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets information and tracks for an uploaded album in your Library.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let albums = yt.get_library_upload_albums().await.unwrap();
yt.get_library_upload_album(&albums[0].album_id).await
Source

pub async fn get_library_upload_artist<'a, T: Into<UploadArtistID<'a>>>( &self, upload_artist_id: T, ) -> Result<<GetLibraryUploadArtistQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets all tracks for an uploaded artist in your Library.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let artists = yt.get_library_upload_artists().await.unwrap();
yt.get_library_upload_artist(&artists[0].artist_id).await
Source

pub async fn delete_upload_entity<'a, T: Into<UploadEntityID<'a>>>( &self, upload_entity_id: T, ) -> Result<<DeleteUploadEntityQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Deletes an upload entity from your library - this is either a song or an album.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let albums = yt.get_library_upload_albums().await.unwrap();
yt.delete_upload_entity(&albums[0].entity_id).await
Source

pub async fn get_taste_profile( &self, ) -> Result<<GetTasteProfileQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Fetches suggested artists from taste profile https://music.youtube.com/tasteprofile. Tasteprofile allows users to pick artists to update their recommendations.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_taste_profile().await
Source

pub async fn set_taste_profile<'a, I, II>( &self, taste_tokens: II, ) -> Result<<SetTasteProfileQuery<'a, I> as Query<A>>::Output>
where I: Iterator<Item = TasteToken<'a>> + Clone, II: IntoIterator<IntoIter = I>,

Available on crate feature simplified-queries only.

Sets artists as favourites to influence your recommendations.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_taste_profile().await.unwrap();
yt.set_taste_profile(results.into_iter()
    .take(5)
    .map(|r| r.taste_tokens))
    .await
Source

pub async fn get_mood_categories( &self, ) -> Result<<GetMoodCategoriesQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Fetches ‘Moods & Genres’ categories.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_mood_categories().await
Source

pub async fn get_mood_playlists<'a, T: Into<MoodCategoryParams<'a>>>( &self, mood_params: T, ) -> Result<<GetMoodPlaylistsQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Returns a list of playlists for a given mood category.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let results = yt.get_mood_categories().await.unwrap();
yt.get_mood_playlists(&results[0].mood_categories[0].params).await
Source

pub async fn get_song_tracking_url<'a, T: Into<VideoID<'a>>>( &self, video_id: T, ) -> Result<SongTrackingUrl<'static>>

Available on crate feature simplified-queries only.

Get the ‘SongTrackingUrl’ for a song. This is used to add items to history using add_history_item().

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let song = yt.search_songs("While My Guitar Gently Weeps")
    .await
    .unwrap()
    .into_iter()
    .next()
    .unwrap();
yt.get_song_tracking_url(song.video_id).await
Source

pub async fn add_history_item<'a, T: Into<SongTrackingUrl<'a>>>( &self, song_url: T, ) -> Result<<AddHistoryItemQuery<'a> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Adds an item to the accounts history.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let song = yt.search_songs("While My Guitar Gently Weeps")
    .await
    .unwrap()
    .into_iter()
    .next()
    .unwrap();
let url = yt.get_song_tracking_url(song.video_id).await.unwrap();
yt.add_history_item(url).await
Source

pub async fn get_channel( &self, channel_id: impl Into<PodcastChannelID<'_>>, ) -> Result<<GetChannelQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets information about a Channel of Podcasts.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let podcasts = yt.search_podcasts("Rustacean").await.unwrap();
let podcast = yt.get_podcast(&podcasts[0].podcast_id).await.unwrap();
yt.get_channel(podcast.channels[0].id.as_ref().unwrap()).await
Source

pub async fn get_channel_episodes<'a>( &self, channel_id: impl Into<PodcastChannelID<'a>>, podcast_channel_params: impl Into<PodcastChannelParams<'a>>, ) -> Result<<GetChannelEpisodesQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets a list of all Episodes for a Channel. Note, if GetPodcastChannel doesn’t contain episode_params, you can be sure that all episodes are already included at episodes key.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let podcasts = yt.search_podcasts("Rustacean").await.unwrap();
let podcast = yt.get_podcast(&podcasts[0].podcast_id).await.unwrap();
let channel_id = podcast.channels[0].id.as_ref().unwrap();
let channel = yt.get_channel(channel_id).await.unwrap();
match channel.episode_params {
    Some(p) => yt.get_channel_episodes(channel_id, p).await,
    None => Ok(channel.episodes),
}
Source

pub async fn get_podcast( &self, podcast_id: impl Into<PodcastID<'_>>, ) -> Result<<GetPodcastQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets information about a Podcast, including Episodes.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let podcasts = yt.search_podcasts("Rustacean").await.unwrap();
yt.get_podcast(&podcasts[0].podcast_id).await
Source

pub async fn get_episode( &self, episode_id: impl Into<EpisodeID<'_>>, ) -> Result<<GetEpisodeQuery<'_> as Query<A>>::Output>

Available on crate feature simplified-queries only.
let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
let episodes = yt.search_episodes("Ratatui").await.unwrap();
yt.get_episode(&episodes[0].episode_id).await
Source

pub async fn get_new_episodes( &self, ) -> Result<<GetNewEpisodesQuery as Query<A>>::Output>

Available on crate feature simplified-queries only.

Gets the special ‘New Episodes’ playlist.

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await.unwrap();
yt.get_new_episodes().await
Source§

impl YtMusic<BrowserToken>

Source

pub fn from_browser_token(token: BrowserToken) -> YtMusic<BrowserToken>

Create a new API handle using a BrowserToken. Utilises the default TLS option for the enabled features.

§Panics

This will panic in some situations - see https://docs.rs/reqwest/latest/reqwest/struct.Client.html#panics

Create a new API handle using a real browser authentication cookie saved to a file on disk. Utilises the default TLS option for the enabled features.

§Panics

This will panic in some situations - see https://docs.rs/reqwest/latest/reqwest/struct.Client.html#panics

Create a new API handle using a real browser authentication cookie in a String. Utilises the default TLS option for the enabled features.

§Panics

This will panic in some situations - see https://docs.rs/reqwest/latest/reqwest/struct.Client.html#panics

Source§

impl YtMusic<OAuthToken>

Source

pub fn from_oauth_token(token: OAuthToken) -> YtMusic<OAuthToken>

Create a new API handle using an OAuthToken. Utilises the default TLS option for the enabled features.

§Panics

This will panic in some situations - see https://docs.rs/reqwest/latest/reqwest/struct.Client.html#panics

Source

pub async fn refresh_token(&mut self) -> Result<OAuthToken>

Refresh the internal oauth token, and return a clone of it (for user to store locally, e.g).

Source

pub fn get_token_hash(&self) -> u64

Get a hash of the internal oauth token, for use in comparison operations.

Source§

impl<A: AuthToken> YtMusic<A>

Source

pub async fn raw_query<'a, Q: Query<A>>( &self, query: &'a Q, ) -> Result<RawResult<'a, Q, A>>

Return a raw result from YouTube music for query Q that requires further processing.

§Note

The returned raw result will hold a reference to the query it was called with. Therefore, passing an owned value is not permitted.

§Usage
use ytmapi_rs::auth::BrowserToken;
use ytmapi_rs::parse::ParseFrom;

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await?;
let query =
    ytmapi_rs::query::SearchQuery::new("Beatles").with_filter(ytmapi_rs::query::ArtistsFilter);
let raw_result = yt.raw_query(&query).await?;
let result: Vec<ytmapi_rs::parse::SearchResultArtist> =
    ParseFrom::parse_from(raw_result.process()?)?;
assert_eq!(result[0].artist, "The Beatles");
Source

pub async fn processed_query<'a, Q: Query<A>>( &self, query: &'a Q, ) -> Result<ProcessedResult<'a, Q>>

Return a result from YouTube music that has had errors removed and been processed into parsable JSON.

§Note

The returned raw result will hold a reference to the query it was called with. Therefore, passing an owned value is not permitted.

§Usage
use ytmapi_rs::auth::BrowserToken;
use ytmapi_rs::parse::ParseFrom;

let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await?;
let query =
    ytmapi_rs::query::SearchQuery::new("Beatles").with_filter(ytmapi_rs::query::ArtistsFilter);
let processed_result = yt.processed_query(&query).await?;
let result: Vec<ytmapi_rs::parse::SearchResultArtist> =
    ParseFrom::parse_from(processed_result)?;
assert_eq!(result[0].artist, "The Beatles");
Source

pub async fn json_query<Q: Query<A>>( &self, query: impl Borrow<Q>, ) -> Result<String>

Return the raw JSON returned by YouTube music for Query Q. Return a result from YouTube music that has had errors removed and been processed into parsable JSON.

§Usage
let yt = ytmapi_rs::YtMusic::from_cookie("FAKE COOKIE").await?;
let query =
    ytmapi_rs::query::SearchQuery::new("Beatles").with_filter(ytmapi_rs::query::ArtistsFilter);
let json_string = yt.json_query(query).await?;
assert!(serde_json::from_str::<serde_json::Value>(&json_string).is_ok());
Source

pub async fn query<Q: Query<A>>( &self, query: impl Borrow<Q>, ) -> Result<Q::Output>

Return a result from YouTube music that has had errors removed and been processed into parsable JSON.

§Usage
let yt = ytmapi_rs::YtMusic::from_cookie("").await?;
let query =
    ytmapi_rs::query::SearchQuery::new("Beatles").with_filter(ytmapi_rs::query::ArtistsFilter);
let result = yt.query(query).await?;
assert_eq!(result[0].artist, "The Beatles");
Source

pub fn stream<'a, Q>( &'a self, query: &'a Q, ) -> impl Stream<Item = Result<Q::Output>> + 'a
where Q: Query<A> + PostQuery, Q::Output: Continuable<Q>,

Stream a query that has ‘continuations’, i.e can continue to stream results.

§Return type lifetime notes

The returned Impl Stream is tied to the lifetime of self, since it’s self’s client that will emit the results. It’s also tied to the lifetime of query, but ideally it could take either owned or borrowed query.

§Usage
use futures::stream::TryStreamExt;
let yt = ytmapi_rs::YtMusic::from_cookie("").await?;
let query = ytmapi_rs::query::GetLibrarySongsQuery::default();
let results = yt.stream(&query).try_collect::<Vec<_>>().await?;

Trait Implementations§

Source§

impl<A: Clone + AuthToken> Clone for YtMusic<A>

Source§

fn clone(&self) -> YtMusic<A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug + AuthToken> Debug for YtMusic<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for YtMusic<A>
where A: Freeze,

§

impl<A> !RefUnwindSafe for YtMusic<A>

§

impl<A> Send for YtMusic<A>
where A: Send,

§

impl<A> Sync for YtMusic<A>
where A: Sync,

§

impl<A> Unpin for YtMusic<A>
where A: Unpin,

§

impl<A> !UnwindSafe for YtMusic<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T