mirror of
https://codeberg.org/YGGverse/ytd.git
synced 2026-04-08 21:05:30 +00:00
initial commit
This commit is contained in:
parent
bb39b5b504
commit
8dcd80b9fe
6 changed files with 113 additions and 8 deletions
63
src/provider.rs
Normal file
63
src/provider.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use invidious::{ClientSync, ClientSyncTrait};
|
||||
use rustypipe::client::RustyPipe;
|
||||
|
||||
pub struct Video {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub is_live: bool,
|
||||
pub is_short: bool,
|
||||
pub is_upcoming: bool,
|
||||
}
|
||||
|
||||
pub enum Provider {
|
||||
Youtube(RustyPipe),
|
||||
Invidious(ClientSync),
|
||||
}
|
||||
|
||||
impl Provider {
|
||||
pub fn youtube() -> Self {
|
||||
Self::Youtube(RustyPipe::new())
|
||||
}
|
||||
pub fn invidious() -> Self {
|
||||
Self::Invidious(ClientSync::default())
|
||||
}
|
||||
pub async fn videos(&self, channel_id: &str) -> Result<Vec<Video>> {
|
||||
let mut videos = Vec::new();
|
||||
match self {
|
||||
Provider::Youtube(client) => {
|
||||
for video in client
|
||||
.query()
|
||||
.channel_videos(channel_id)
|
||||
.await?
|
||||
.content
|
||||
.items
|
||||
{
|
||||
videos.push(Video {
|
||||
id: video.id,
|
||||
name: video.name,
|
||||
is_live: video.is_live,
|
||||
is_short: video.is_short,
|
||||
is_upcoming: video.is_upcoming,
|
||||
})
|
||||
}
|
||||
}
|
||||
Provider::Invidious(client) => {
|
||||
for video in client
|
||||
.channel_videos(channel_id, None)
|
||||
.map_err(|e| anyhow!("{e:?}"))?
|
||||
.videos
|
||||
{
|
||||
videos.push(Video {
|
||||
id: video.id,
|
||||
name: video.title,
|
||||
is_live: video.live,
|
||||
is_short: video.length <= 60,
|
||||
is_upcoming: video.upcoming,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(videos)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue