Skip to content

Commit

Permalink
Continue implementing Query
Browse files Browse the repository at this point in the history
  • Loading branch information
nick42d committed Aug 31, 2024
1 parent a7a5f75 commit 600d6bb
Showing 1 changed file with 62 additions and 21 deletions.
83 changes: 62 additions & 21 deletions ytmapi-rs/src/query/podcasts.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
use serde_json::json;
use super::{PostMethod, PostQuery, Query};
use crate::{auth::AuthToken, common::PodcastChannelParams, };
use crate::{
auth::AuthToken,
common::{PodcastChannelParams, PodcastID, VideoID},
};
use serde_json::json;

pub struct GetChannelQuery;
pub struct GetChannelQuery {
channel_id: (),
}
pub struct GetChannelEpisodesQuery<'a> {
channel_id: (),
podcast_channel_params: PodcastChannelParams<'a>,
}
pub struct GetPodcastQuery;
pub struct GetEpisodeQuery;
pub struct GetPodcastQuery<'a> {
podcast_id: PodcastID<'a>,
}
pub struct GetEpisodeQuery<'a> {
video_id: VideoID<'a>,
}
pub struct GetEpisodesPlaylistQuery;

impl GetChannelQuery {
pub fn new(channel_id: impl Into<()>) -> Self {
Self {
channel_id: channel_id.into(),
}
}
}
impl<'a> GetChannelEpisodesQuery<'a> {
pub fn new(channel_id: impl Into<()>, podcast_channel_params: impl Into<PodcastChannelParams<'a>>) -> GetChannelEpisodesQuery<'a> {
pub fn new(
channel_id: impl Into<()>,
podcast_channel_params: impl Into<PodcastChannelParams<'a>>,
) -> GetChannelEpisodesQuery<'a> {
GetChannelEpisodesQuery {
channel_id: channel_id.into(),
podcast_channel_params: podcast_channel_params.into()
podcast_channel_params: podcast_channel_params.into(),
}
}
}
impl<'a> GetPodcastQuery<'a> {
pub fn new(podcast_id: impl Into<PodcastID<'a>>) -> Self {
Self {
podcast_id: podcast_id.into(),
}
}
}
impl<'a> GetEpisodeQuery<'a> {
pub fn new(video_id: impl Into<VideoID<'a>>) -> Self {
Self {
video_id: video_id.into(),
}
}
}
Expand All @@ -28,7 +61,7 @@ impl<'a, A: AuthToken> Query<A> for GetChannelEpisodesQuery<'a> {
type Output = ();
type Method = PostMethod;
}
impl<A: AuthToken> Query<A> for GetPodcastQuery {
impl<'a, A: AuthToken> Query<A> for GetPodcastQuery<'a> {
type Output = ();
type Method = PostMethod;
}
Expand All @@ -43,8 +76,7 @@ impl<A: AuthToken> Query<A> for GetEpisodesPlaylistQuery {

impl PostQuery for GetChannelQuery {
fn header(&self) -> serde_json::Map<String, serde_json::Value> {
todo!()
FromIterator::from_iter([("browseId".into(), json!(""))])
FromIterator::from_iter([("browseId".into(), json!(self.channel_id))])
}
fn params(&self) -> Option<std::borrow::Cow<str>> {
None
Expand All @@ -55,38 +87,47 @@ impl PostQuery for GetChannelQuery {
}
impl<'a> PostQuery for GetChannelEpisodesQuery<'a> {
fn header(&self) -> serde_json::Map<String, serde_json::Value> {
FromIterator::from_iter([("browseId".into(), json!(self.channel_id)), ("params".into(), json!(self.podcast_channel_params))])
FromIterator::from_iter([
("browseId".into(), json!(self.channel_id)),
("params".into(), json!(self.podcast_channel_params)),
])
}
fn params(&self) -> Option<std::borrow::Cow<str>> {
todo!()
None
}
fn path(&self) -> &str {
"browse"
}
}
impl PostQuery for GetPodcastQuery {
// TODO: Continuations
impl<'a> PostQuery for GetPodcastQuery<'a> {
fn header(&self) -> serde_json::Map<String, serde_json::Value> {
todo!()
// TODO: Confirm if any parsing required
FromIterator::from_iter([("browseId".into(), json!(self.podcast_id))])
}
fn params(&self) -> Option<std::borrow::Cow<str>> {
todo!()
None
}
fn path(&self) -> &str {
todo!()
"browse"
}
}
impl PostQuery for GetEpisodeQuery {
impl<'a> PostQuery for GetEpisodeQuery<'a> {
fn header(&self) -> serde_json::Map<String, serde_json::Value> {
todo!()
// TODO: Confirm if any parsing required
FromIterator::from_iter([("browseId".into(), json!(self.video_id))])
}
fn params(&self) -> Option<std::borrow::Cow<str>> {
todo!()
None
}
fn path(&self) -> &str {
todo!()
"browse"
}
}
impl PostQuery for GetEpisodesPlaylistQuery {
// Gets all episodes in a playlist of episodes.
// The only playlist like this seems to be the New Episodes auto-playlist, so
// it's possible that this is not worth implementing.
impl<'a> PostQuery for GetEpisodesPlaylistQuery<'a> {
fn header(&self) -> serde_json::Map<String, serde_json::Value> {
todo!()
}
Expand Down

0 comments on commit 600d6bb

Please sign in to comment.