1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::{
    channel, playlist, stream, video, youtube::innertube::Api, Channel, Playlist, Stream, Video,
};

/// A Client capable of interacting with YouTube
///
/// Note: This structure already uses an [`Arc`](std::sync::Arc) internally, so
///       it does not need to be wrapped again.
#[allow(missing_debug_implementations)]
#[derive(Clone, Default)]
pub struct Client {
    pub(crate) api: Api,
}

impl Client {
    /// Create a new [`Client`]
    pub fn new() -> Self {
        Self::default()
    }

    /// Get a [`Video`] identified by a [`Id`](video::Id)
    pub async fn video(&self, id: video::Id) -> crate::Result<Video> {
        Video::get(self.clone(), id).await
    }

    /// Get the [`Stream`]s of a [`Video`] identified by a [`Id`](video::Id)
    pub async fn streams(&self, id: video::Id) -> crate::Result<impl Iterator<Item = Stream>> {
        stream::get(self.clone(), id).await
    }

    /// Get a [`Playlist`] identified by a [`Id`](playlist::Id)
    pub async fn playlist(&self, id: playlist::Id) -> crate::Result<Playlist> {
        Playlist::get(self.clone(), id).await
    }

    /// Get a [`Channel`] identified by a [`Id`](channel::Id)
    pub async fn channel(&self, id: channel::Id) -> crate::Result<Channel> {
        Channel::get(self.clone(), id).await
    }
}