Skip to main content

lichess_api/api/
tv.rs

1//! Lichess TV: the best ongoing games, overall and per channel (speed
2//! variants like bullet or blitz, plus computer and bot games).
3//!
4//! [`LichessApi::tv_channels`] gives current champions for every channel in
5//! one call, and [`LichessApi::tv_channel_games`] lists ongoing games for a
6//! single channel. [`LichessApi::tv_stream_current`] and
7//! [`LichessApi::tv_stream_channel_current`] instead follow the featured game
8//! (overall, or for one channel) as it changes, streaming positions and moves
9//! rather than returning a single value.
10//!
11//! All of these endpoints are public and need no bearer token.
12
13use futures::stream::StreamExt;
14
15use crate::client::LichessApi;
16use crate::error::Result;
17use crate::model::games::GameJson;
18use crate::model::tv::*;
19
20impl LichessApi<reqwest::Client> {
21    pub async fn tv_channels(&self) -> Result<Channels> {
22        self.get_single_model(channels::GetRequest::new()).await
23    }
24
25    pub async fn tv_stream_current(&self) -> Result<impl StreamExt<Item = Result<stream::Event>>> {
26        self.get_streamed_models(stream::current::GetRequest::new())
27            .await
28    }
29
30    pub async fn tv_stream_channel_current(
31        &self,
32        request: impl Into<stream::channel::GetRequest>,
33    ) -> Result<impl StreamExt<Item = Result<stream::Event>>> {
34        self.get_streamed_models(request.into()).await
35    }
36
37    pub async fn tv_channel_games(
38        &self,
39        request: impl Into<games::GetRequest>,
40    ) -> Result<impl StreamExt<Item = Result<GameJson>>> {
41        self.get_streamed_models(request.into()).await
42    }
43}