Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve query constructors - resolves #103 #157

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ytmapi-rs/src/query/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ pub struct GetArtistAlbumsQuery<'a> {
params: BrowseParams<'a>,
}
impl<'a> GetArtistQuery<'a> {
pub fn new(channel_id: ChannelID<'a>) -> GetArtistQuery<'a> {
GetArtistQuery { channel_id }
pub fn new(channel_id: impl Into<ChannelID<'a>>) -> GetArtistQuery<'a> {
GetArtistQuery {
channel_id: channel_id.into(),
}
}
}
impl<'a> GetArtistAlbumsQuery<'a> {
Expand All @@ -28,6 +30,12 @@ impl<'a> GetArtistAlbumsQuery<'a> {
}
}

impl<'a, T: Into<ChannelID<'a>>> From<T> for GetArtistQuery<'a> {
fn from(channel_id: T) -> Self {
GetArtistQuery::new(channel_id.into())
}
}

impl<'a, A: AuthToken> Query<A> for GetArtistQuery<'a> {
type Output = ArtistParams;
type Method = PostMethod;
Expand Down
2 changes: 2 additions & 0 deletions ytmapi-rs/src/query/playlist/additems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ pub struct AddPlaylistItemsQuery<'a, T: SpecialisedQuery> {
id: PlaylistID<'a>,
query_type: T,
}
/// Helper struct for AddPlaylistItemsQuery
#[derive(Default, Debug, Clone, PartialEq)]
pub struct AddVideosToPlaylist<'a> {
video_ids: Vec<VideoID<'a>>,
duplicate_handling_mode: DuplicateHandlingMode,
}
/// Helper struct for AddPlaylistItemsQuery
#[derive(Debug, Clone, PartialEq)]
pub struct AddPlaylistToPlaylist<'a> {
source_playlist: PlaylistID<'a>,
Expand Down
3 changes: 3 additions & 0 deletions ytmapi-rs/src/query/playlist/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ pub struct CreatePlaylistQuery<'a, C: CreatePlaylistType> {
query_type: C,
}

/// Helper struct for CreatePlaylistQuery
#[derive(Default, Debug, Clone, PartialEq)]
pub struct BasicCreatePlaylist {}
/// Helper struct for CreatePlaylistQuery
#[derive(Default, Debug, Clone, PartialEq)]
pub struct CreatePlaylistFromVideos<'a> {
video_ids: Vec<VideoID<'a>>,
}
/// Helper struct for CreatePlaylistQuery
#[derive(Debug, Clone, PartialEq)]
pub struct CreatePlaylistFromPlaylist<'a> {
source_playlist: PlaylistID<'a>,
Expand Down
3 changes: 3 additions & 0 deletions ytmapi-rs/src/query/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ pub enum SpellingMode {
WithSuggestions,
}

/// Helper struct for SearchQuery type state pattern.
#[derive(Default, Debug, Clone, PartialEq)]
pub struct BasicSearch;
/// Helper struct for SearchQuery type state pattern.
#[derive(Default, Debug, Clone, PartialEq)]
pub struct LibrarySearch;
/// Helper struct for SearchQuery type state pattern.
#[derive(Default, Debug, Clone, PartialEq)]
pub struct UploadSearch;

Expand Down
13 changes: 12 additions & 1 deletion ytmapi-rs/src/query/search/filteredsearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,39 @@ pub trait FilteredSearchType: Default {
"EgWKAQ".into()
}
}
/// Helper struct for SearchQuery
#[derive(Default, Debug, Clone, PartialEq)]
pub struct FilteredSearch<F: FilteredSearchType> {
pub filter: F,
pub(crate) filter: F,
}
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct SongsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct VideosFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct AlbumsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct ArtistsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct PlaylistsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct CommunityPlaylistsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct FeaturedPlaylistsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct EpisodesFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct PodcastsFilter;
/// Helper struct for FilteredSearch type state pattern.
#[derive(Default, PartialEq, Debug, Clone)]
pub struct ProfilesFilter;

Expand Down
7 changes: 3 additions & 4 deletions ytmapi-rs/src/simplified_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,11 @@ impl<A: AuthToken> YtMusic<A> {
/// let results = yt.search_artists("Beatles").await.unwrap();
/// yt.get_artist(&results[0].browse_id).await
/// # };
pub async fn get_artist<'a, T: Into<ChannelID<'a>>>(
pub async fn get_artist<'a>(
&self,
channel_id: T,
query: impl Into<GetArtistQuery<'a>>,
) -> Result<ArtistParams> {
let query = GetArtistQuery::new(channel_id.into());
self.query(query).await
self.query(query.into()).await
}
/// Gets a full list albums for an artist.
/// ```no_run
Expand Down