You've already forked flix
Throw away flix files in favor of a flix database
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
//! Collections API
|
||||
|
||||
use core::time::Duration;
|
||||
use std::rc::Rc;
|
||||
|
||||
use governor::Jitter;
|
||||
|
||||
use crate::Config;
|
||||
use crate::model::{Collection, CollectionId};
|
||||
use crate::model::Collection;
|
||||
use crate::model::id::CollectionId;
|
||||
|
||||
use super::{Error, make_request};
|
||||
|
||||
@@ -24,12 +30,20 @@ impl Client {
|
||||
id: impl Into<CollectionId>,
|
||||
language: Option<&str>,
|
||||
) -> Result<Collection, Error> {
|
||||
self.config
|
||||
.limiter
|
||||
.until_ready_with_jitter(Jitter::new(
|
||||
Duration::from_millis(0),
|
||||
Duration::from_millis(50),
|
||||
))
|
||||
.await;
|
||||
|
||||
Ok(self
|
||||
.config
|
||||
.client
|
||||
.execute(make_request(
|
||||
&self.config,
|
||||
&format!("/3/collection/{}", id.into()),
|
||||
&format!("/3/collection/{}", id.into().into_raw()),
|
||||
language,
|
||||
)?)
|
||||
.await?
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
//! Episodes API
|
||||
|
||||
use core::time::Duration;
|
||||
use std::rc::Rc;
|
||||
|
||||
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
|
||||
|
||||
use governor::Jitter;
|
||||
|
||||
use crate::Config;
|
||||
use crate::model::{Episode, ShowId};
|
||||
use crate::model::Episode;
|
||||
use crate::model::id::ShowId;
|
||||
|
||||
use super::{Error, make_request};
|
||||
|
||||
@@ -22,10 +30,18 @@ impl Client {
|
||||
pub async fn get_details(
|
||||
&self,
|
||||
id: impl Into<ShowId>,
|
||||
season: impl Into<u32>,
|
||||
episode: impl Into<u32>,
|
||||
season: impl Into<SeasonNumber>,
|
||||
episode: impl Into<EpisodeNumber>,
|
||||
language: Option<&str>,
|
||||
) -> Result<Episode, Error> {
|
||||
self.config
|
||||
.limiter
|
||||
.until_ready_with_jitter(Jitter::new(
|
||||
Duration::from_millis(0),
|
||||
Duration::from_millis(50),
|
||||
))
|
||||
.await;
|
||||
|
||||
Ok(self
|
||||
.config
|
||||
.client
|
||||
@@ -33,7 +49,7 @@ impl Client {
|
||||
&self.config,
|
||||
&format!(
|
||||
"/3/tv/{}/season/{}/episode/{}",
|
||||
id.into(),
|
||||
id.into().into_raw(),
|
||||
season.into(),
|
||||
episode.into()
|
||||
),
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::Config;
|
||||
use crate::model::{MovieGenre, ShowGenre};
|
||||
|
||||
use super::{Error, make_request};
|
||||
|
||||
/// TMDB Genre API client
|
||||
pub struct Client {
|
||||
config: Rc<Config>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Create a new client with the given configuration
|
||||
pub fn new(config: Rc<Config>) -> Self {
|
||||
Self { config }
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Fetch the list of all valid movie genres
|
||||
pub async fn get_movie_genres(&self, language: Option<&str>) -> Result<Vec<MovieGenre>, Error> {
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Genres {
|
||||
genres: Vec<MovieGenre>,
|
||||
}
|
||||
|
||||
let genres: Genres = self
|
||||
.config
|
||||
.client
|
||||
.execute(make_request(&self.config, "/3/genre/movie/list", language)?)
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
Ok(genres.genres)
|
||||
}
|
||||
|
||||
/// Fetch the list of all valid show genres
|
||||
pub async fn get_tv_genres(&self, language: Option<&str>) -> Result<Vec<ShowGenre>, Error> {
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct Genres {
|
||||
genres: Vec<ShowGenre>,
|
||||
}
|
||||
|
||||
let genres: Genres = self
|
||||
.config
|
||||
.client
|
||||
.execute(make_request(&self.config, "/3/genre/tv/list", language)?)
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
Ok(genres.genres)
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,14 @@
|
||||
//! TMDB API clients
|
||||
|
||||
use reqwest::Request;
|
||||
use reqwest::header;
|
||||
|
||||
use crate::Config;
|
||||
|
||||
/// Collections API
|
||||
pub mod collections;
|
||||
/// Episodes API
|
||||
pub mod episodes;
|
||||
/// Genres API
|
||||
pub mod genres;
|
||||
/// Movies API
|
||||
pub mod movies;
|
||||
/// Seasons API
|
||||
pub mod seasons;
|
||||
/// Shows API
|
||||
pub mod shows;
|
||||
|
||||
/// A generic error wrapping Url and Reqwest errors
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
//! Movies API
|
||||
|
||||
use core::time::Duration;
|
||||
use std::rc::Rc;
|
||||
|
||||
use governor::Jitter;
|
||||
|
||||
use crate::Config;
|
||||
use crate::model::{Movie, MovieId};
|
||||
use crate::model::Movie;
|
||||
use crate::model::id::MovieId;
|
||||
|
||||
use super::{Error, make_request};
|
||||
|
||||
@@ -24,12 +30,20 @@ impl Client {
|
||||
id: impl Into<MovieId>,
|
||||
language: Option<&str>,
|
||||
) -> Result<Movie, Error> {
|
||||
self.config
|
||||
.limiter
|
||||
.until_ready_with_jitter(Jitter::new(
|
||||
Duration::from_millis(0),
|
||||
Duration::from_millis(50),
|
||||
))
|
||||
.await;
|
||||
|
||||
Ok(self
|
||||
.config
|
||||
.client
|
||||
.execute(make_request(
|
||||
&self.config,
|
||||
&format!("/3/movie/{}", id.into()),
|
||||
&format!("/3/movie/{}", id.into().into_raw()),
|
||||
language,
|
||||
)?)
|
||||
.await?
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
//! Seasons API
|
||||
|
||||
use core::time::Duration;
|
||||
use std::rc::Rc;
|
||||
|
||||
use flix_model::numbers::SeasonNumber;
|
||||
|
||||
use governor::Jitter;
|
||||
|
||||
use crate::Config;
|
||||
use crate::model::{Season, ShowId};
|
||||
use crate::model::Season;
|
||||
use crate::model::id::ShowId;
|
||||
|
||||
use super::{Error, make_request};
|
||||
|
||||
@@ -22,15 +30,23 @@ impl Client {
|
||||
pub async fn get_details(
|
||||
&self,
|
||||
id: impl Into<ShowId>,
|
||||
season: impl Into<u32>,
|
||||
season: impl Into<SeasonNumber>,
|
||||
language: Option<&str>,
|
||||
) -> Result<Season, Error> {
|
||||
self.config
|
||||
.limiter
|
||||
.until_ready_with_jitter(Jitter::new(
|
||||
Duration::from_millis(0),
|
||||
Duration::from_millis(50),
|
||||
))
|
||||
.await;
|
||||
|
||||
Ok(self
|
||||
.config
|
||||
.client
|
||||
.execute(make_request(
|
||||
&self.config,
|
||||
&format!("/3/tv/{}/season/{}", id.into(), season.into()),
|
||||
&format!("/3/tv/{}/season/{}", id.into().into_raw(), season.into()),
|
||||
language,
|
||||
)?)
|
||||
.await?
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
//! Shows API
|
||||
|
||||
use core::time::Duration;
|
||||
use std::rc::Rc;
|
||||
|
||||
use governor::Jitter;
|
||||
|
||||
use crate::Config;
|
||||
use crate::model::{Show, ShowId};
|
||||
use crate::model::Show;
|
||||
use crate::model::id::ShowId;
|
||||
|
||||
use super::{Error, make_request};
|
||||
|
||||
@@ -24,12 +30,20 @@ impl Client {
|
||||
id: impl Into<ShowId>,
|
||||
language: Option<&str>,
|
||||
) -> Result<Show, Error> {
|
||||
self.config
|
||||
.limiter
|
||||
.until_ready_with_jitter(Jitter::new(
|
||||
Duration::from_millis(0),
|
||||
Duration::from_millis(50),
|
||||
))
|
||||
.await;
|
||||
|
||||
Ok(self
|
||||
.config
|
||||
.client
|
||||
.execute(make_request(
|
||||
&self.config,
|
||||
&format!("/3/tv/{}", id.into()),
|
||||
&format!("/3/tv/{}", id.into().into_raw()),
|
||||
language,
|
||||
)?)
|
||||
.await?
|
||||
|
||||
Reference in New Issue
Block a user