use crate::base::TMDB;
use std::collections::HashMap;
use serde_json::Value;
pub struct TV {
tmdb: TMDB,
id: i32,
}
impl TV {
pub fn new(id: i32) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = "tv".to_string();
tmdb.urls = [
("info".to_string(), "/{id}".to_string()),
("account_states".to_string(), "/{id}/account_states".to_string()),
("alternative_titles".to_string(), "/{id}/alternative_titles".to_string()),
("content_ratings".to_string(), "/{id}/content_ratings".to_string()),
("credits".to_string(), "/{id}/credits".to_string()),
("episode_groups".to_string(), "/{id}/episode_groups".to_string()),
("external_ids".to_string(), "/{id}/external_ids".to_string()),
("images".to_string(), "/{id}/images".to_string()),
("keywords".to_string(), "/{id}/keywords".to_string()),
("recommendations".to_string(), "/{id}/recommendations".to_string()),
("reviews".to_string(), "/{id}/reviews".to_string()),
("screened_theatrically".to_string(), "/{id}/screened_theatrically".to_string()),
("similar".to_string(), "/{id}/similar".to_string()),
("translations".to_string(), "/{id}/translations".to_string()),
("videos".to_string(), "/{id}/videos".to_string()),
("watch_providers".to_string(), "/{id}/watch/providers".to_string()),
("rating".to_string(), "/{id}/rating".to_string()),
("latest".to_string(), "/latest".to_string()),
("airing_today".to_string(), "/airing_today".to_string()),
("on_the_air".to_string(), "/on_the_air".to_string()),
("popular".to_string(), "/popular".to_string()),
("top_rated".to_string(), "/top_rated".to_string()),
]
.iter()
.cloned()
.collect();
TV { tmdb, id }
}
pub fn _get_id_path(&self, key: &str) -> String {
self.tmdb._get_path(key).replace("{id}", &self.id.to_string())
}
pub async fn info(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("info");
self.tmdb._get(&path, options).await
}
pub async fn account_states(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("account_states");
self.tmdb._get(&path, options).await
}
pub async fn alternative_titles(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("alternative_titles");
self.tmdb._get(&path, options).await
}
pub async fn content_ratings(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("content_ratings");
self.tmdb._get(&path, options).await
}
pub async fn credits(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("credits");
self.tmdb._get(&path, options).await
}
pub async fn episode_groups(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("episode_groups");
self.tmdb._get(&path, options).await
}
pub async fn external_ids(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("external_ids");
self.tmdb._get(&path, options).await
}
pub async fn images(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("images");
self.tmdb._get(&path, options).await
}
pub async fn keywords(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("keywords");
self.tmdb._get(&path, options).await
}
pub async fn recommendations(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("recommendations");
self.tmdb._get(&path, options).await
}
pub async fn reviews(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("reviews");
self.tmdb._get(&path, options).await
}
pub async fn screened_theatrically(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("screened_theatrically");
self.tmdb._get(&path, options).await
}
pub async fn similar(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("similar");
self.tmdb._get(&path, options).await
}
pub async fn translations(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("translations");
self.tmdb._get(&path, options).await
}
pub async fn videos(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("videos");
self.tmdb._get(&path, options).await
}
pub async fn watch_providers(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("watch_providers");
self.tmdb._get(&path, options).await
}
pub async fn rating(&self, options: Option<HashMap<String, String>>, payload: Option<Value>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("rating");
self.tmdb._post(&path, options, payload).await
}
pub async fn rating_delete(&self, options: Option<HashMap<String, String>>, payload: Option<Value>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("rating");
self.tmdb._delete(&path, options, payload).await
}
pub async fn latest(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self.tmdb._get_path("latest");
self.tmdb._get(&path, options).await
}
pub async fn airing_today(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self.tmdb._get_path("airing_today");
self.tmdb._get(&path, options).await
}
pub async fn on_the_air(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self.tmdb._get_path("on_the_air");
self.tmdb._get(&path, options).await
}
pub async fn popular(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self.tmdb._get_path("popular");
self.tmdb._get(&path, options).await
}
pub async fn top_rated(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self.tmdb._get_path("top_rated");
self.tmdb._get(&path, options).await
}
}
pub struct TVSeasons {
tmdb: TMDB,
tv_id: i32,
season_number: i32,
}
impl TVSeasons {
pub fn new(tv_id: i32, season_number: i32) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = format!("tv/{}/season/{}", tv_id, season_number);
tmdb.urls = [
("info".to_string(), "".to_string()),
("account_states".to_string(), "/account_states".to_string()),
("credits".to_string(), "/credits".to_string()),
("external_ids".to_string(), "/external_ids".to_string()),
("images".to_string(), "/images".to_string()),
("videos".to_string(), "/videos".to_string()),
]
.iter()
.cloned()
.collect();
TVSeasons { tmdb, tv_id, season_number }
}
pub fn _get_tv_id_season_number_path(&self, key: &str) -> String {
self.tmdb._get_path(key).to_string()
}
pub async fn info(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_path("info");
self.tmdb._get(&path, options).await
}
pub async fn account_states(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_path("account_states");
self.tmdb._get(&path, options).await
}
pub async fn credits(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_path("credits");
self.tmdb._get(&path, options).await
}
pub async fn external_ids(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_path("external_ids");
self.tmdb._get(&path, options).await
}
pub async fn images(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_path("images");
self.tmdb._get(&path, options).await
}
pub async fn videos(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_path("videos");
self.tmdb._get(&path, options).await
}
}
pub struct TVEpisodes {
tmdb: TMDB,
tv_id: i32,
season_number: i32,
episode_number: i32,
}
impl TVEpisodes {
pub fn new(tv_id: i32, season_number: i32, episode_number: i32) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = format!("tv/{}/season/{}/episode/{}", tv_id, season_number, episode_number);
tmdb.urls = [
("info".to_string(), "".to_string()),
("account_states".to_string(), "/account_states".to_string()),
("credits".to_string(), "/credits".to_string()),
("external_ids".to_string(), "/external_ids".to_string()),
("images".to_string(), "/images".to_string()),
("translations".to_string(), "/translations".to_string()),
("rating".to_string(), "/rating".to_string()),
("videos".to_string(), "/videos".to_string()),
]
.iter()
.cloned()
.collect();
TVEpisodes { tmdb, tv_id, season_number, episode_number }
}
pub fn _get_tv_id_season_number_episode_number_path(&self, key: &str) -> String {
self.tmdb._get_path(key).to_string()
}
pub async fn info(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("info");
self.tmdb._get(&path, options).await
}
pub async fn account_states(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("account_states");
self.tmdb._get(&path, options).await
}
pub async fn credits(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("credits");
self.tmdb._get(&path, options).await
}
pub async fn external_ids(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("external_ids");
self.tmdb._get(&path, options).await
}
pub async fn images(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("images");
self.tmdb._get(&path, options).await
}
pub async fn translations(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("translations");
self.tmdb._get(&path, options).await
}
pub async fn rating(&self, options: Option<HashMap<String, String>>, payload: Option<Value>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("rating");
self.tmdb._post(&path, options, payload).await
}
pub async fn rating_delete(&self, options: Option<HashMap<String, String>>, payload: Option<Value>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("rating");
self.tmdb._delete(&path, options, payload).await
}
pub async fn videos(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_tv_id_season_number_episode_number_path("videos");
self.tmdb._get(&path, options).await
}
}
pub struct TVEpisodeGroups {
tmdb: TMDB,
id: String,
}
impl TVEpisodeGroups {
pub fn new(id: String) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = "tv/episode_group".to_string();
tmdb.urls = [("info".to_string(), "/{id}".to_string())]
.iter()
.cloned()
.collect();
TVEpisodeGroups { tmdb, id }
}
pub fn _get_id_path(&self, key: &str) -> String {
self.tmdb._get_path(key).replace("{id}", &self.id)
}
pub async fn info(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("info");
self.tmdb._get(&path, options).await
}
}
pub struct TVChanges {
tmdb: TMDB,
id: i32,
}
impl TVChanges {
pub fn new(id: i32) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = "tv".to_string();
tmdb.urls = [
("series".to_string(), "/{id}/changes".to_string()),
("season".to_string(), "/season/{id}/changes".to_string()),
("episode".to_string(), "/episode/{id}/changes".to_string()),
]
.iter()
.cloned()
.collect();
TVChanges { tmdb, id }
}
pub fn _get_id_path(&self, key: &str) -> String {
self.tmdb._get_path(key).replace("{id}", &self.id.to_string())
}
pub async fn series(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("series");
self.tmdb._get(&path, options).await
}
pub async fn season(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("season");
self.tmdb._get(&path, options).await
}
pub async fn episode(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("episode");
self.tmdb._get(&path, options).await
}
}
pub struct Networks {
tmdb: TMDB,
id: i32,
}
impl Networks {
pub fn new(id: i32) -> Self {
let mut tmdb = TMDB::new();
tmdb.base_path = "network".to_string();
tmdb.urls = [
("info".to_string(), "/{id}".to_string()),
("alternative_names".to_string(), "/{id}/alternative_names".to_string()),
("images".to_string(), "/{id}/images".to_string()),
]
.iter()
.cloned()
.collect();
Networks { tmdb, id }
}
pub fn _get_id_path(&self, key: &str) -> String {
self.tmdb._get_path(key).replace("{id}", &self.id.to_string())
}
pub async fn info(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("info");
self.tmdb._get(&path, options).await
}
pub async fn alternative_names(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("alternative_names");
self.tmdb._get(&path, options).await
}
pub async fn images(&self, options: Option<HashMap<String, String>>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
let path = self._get_id_path("images");
self.tmdb._get(&path, options).await
}
}