You've already forked flix
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ba9c3fa03d
|
|||
|
ced1fe8194
|
|||
|
2b348851d7
|
|||
|
73c5e4af9b
|
Generated
+220
-280
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -34,12 +34,13 @@ overflow-checks = true
|
|||||||
strip = "debuginfo"
|
strip = "debuginfo"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
flix = { path = "crates/flix", version = "=0.0.4", default-features = false }
|
flix = { path = "crates/flix", version = "=0.0.8", default-features = false }
|
||||||
flix-tmdb = { path = "crates/tmdb", version = "=0.0.4", default-features = false }
|
flix-tmdb = { path = "crates/tmdb", version = "=0.0.8", default-features = false }
|
||||||
|
|
||||||
anyhow = { version = "^1", default-features = false }
|
anyhow = { version = "^1", default-features = false }
|
||||||
chrono = { version = "^0.4", default-features = false }
|
chrono = { version = "^0.4", default-features = false }
|
||||||
clap = { version = "^4", default-features = false, features = ["std"] }
|
clap = { version = "^4", default-features = false, features = ["std"] }
|
||||||
|
futures = { version = "^0.3", default-features = false }
|
||||||
home = { version = "^0.5", default-features = false }
|
home = { version = "^0.5", default-features = false }
|
||||||
reqwest = { version = "^0.12", default-features = false }
|
reqwest = { version = "^0.12", default-features = false }
|
||||||
serde = { version = "^1", default-features = false }
|
serde = { version = "^1", default-features = false }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-cli"
|
name = "flix-cli"
|
||||||
version = "0.0.4"
|
version = "0.0.8"
|
||||||
|
|
||||||
categories = ["command-line-utilities"]
|
categories = ["command-line-utilities"]
|
||||||
description = "CLI for interacting with flix media"
|
description = "CLI for interacting with flix media"
|
||||||
@@ -48,5 +48,6 @@ clap = { workspace = true, features = [
|
|||||||
] }
|
] }
|
||||||
home = { workspace = true }
|
home = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
futures = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["rt", "fs", "macros"] }
|
tokio = { workspace = true, features = ["rt", "fs", "macros"] }
|
||||||
toml = { workspace = true, features = ["display", "parse"] }
|
toml = { workspace = true, features = ["display", "parse"] }
|
||||||
|
|||||||
+21
-12
@@ -7,9 +7,9 @@ pub mod tmdb;
|
|||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Use a custom config file [default: ~/.flix]
|
/// Use a custom config file
|
||||||
#[arg(short, long, value_name = "FILE")]
|
#[arg(short, long, value_name = "FILE", default_value = "~/.flix")]
|
||||||
config: Option<PathBuf>,
|
config: PathBuf,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Command,
|
command: Command,
|
||||||
@@ -17,17 +17,14 @@ pub struct Cli {
|
|||||||
|
|
||||||
impl Cli {
|
impl Cli {
|
||||||
pub fn config_path(&self) -> PathBuf {
|
pub fn config_path(&self) -> PathBuf {
|
||||||
match self.config.as_ref() {
|
match self.config.strip_prefix("~/") {
|
||||||
Some(path) => match path.strip_prefix("~/") {
|
|
||||||
Ok(path) => expect_home_dir().join(path),
|
Ok(path) => expect_home_dir().join(path),
|
||||||
Err(_) => path.to_owned(),
|
Err(_) => self.config.to_owned(),
|
||||||
},
|
|
||||||
None => expect_home_dir().join(".flix"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn command(&self) -> &Command {
|
pub fn command(self) -> Command {
|
||||||
&self.command
|
self.command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,12 +42,18 @@ pub enum Command {
|
|||||||
force: bool,
|
force: bool,
|
||||||
|
|
||||||
/// Change the destination
|
/// Change the destination
|
||||||
#[arg(short, long, value_name = "FILE")]
|
#[arg(short, long, value_name = "FILE", default_value = "flix.toml")]
|
||||||
output: Option<PathBuf>,
|
output: PathBuf,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: BackendCommand,
|
command: BackendCommand,
|
||||||
},
|
},
|
||||||
|
/// Update a flix manifest
|
||||||
|
Update {
|
||||||
|
/// Change the destination
|
||||||
|
#[arg(short, long, value_name = "FILE", default_value = "flix.toml")]
|
||||||
|
output: PathBuf,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
@@ -62,6 +65,12 @@ pub enum BackendCommand {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<tmdb::Command> for BackendCommand {
|
||||||
|
fn from(value: tmdb::Command) -> Self {
|
||||||
|
Self::Tmdb { command: value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn expect_home_dir() -> PathBuf {
|
fn expect_home_dir() -> PathBuf {
|
||||||
#[allow(clippy::expect_used)]
|
#[allow(clippy::expect_used)]
|
||||||
home::home_dir().expect("you do not have a home directory")
|
home::home_dir().expect("you do not have a home directory")
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub enum Command {
|
|||||||
season: u32,
|
season: u32,
|
||||||
},
|
},
|
||||||
/// Process a TMDB episode
|
/// Process a TMDB episode
|
||||||
|
#[command(trailing_var_arg = true)]
|
||||||
Episode {
|
Episode {
|
||||||
#[arg(value_name = "TMDB_ID")]
|
#[arg(value_name = "TMDB_ID")]
|
||||||
id: u32,
|
id: u32,
|
||||||
@@ -32,5 +33,7 @@ pub enum Command {
|
|||||||
season: u32,
|
season: u32,
|
||||||
#[arg(value_name = "EPISODE_NUM")]
|
#[arg(value_name = "EPISODE_NUM")]
|
||||||
episode: u32,
|
episode: u32,
|
||||||
|
#[arg(value_name = "...")]
|
||||||
|
episodes: Vec<u32>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-15
@@ -5,15 +5,16 @@ use flix_tmdb::Client;
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
use cli::{BackendCommand, Cli, Command};
|
use cli::{BackendCommand, Cli, Command};
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use tokio::io::AsyncWriteExt;
|
|
||||||
|
|
||||||
mod run;
|
mod run;
|
||||||
|
use run::flix::FlixObject;
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
@@ -27,25 +28,39 @@ async fn main() -> Result<()> {
|
|||||||
let client = Client::new(config.tmdb().bearer_token().to_owned());
|
let client = Client::new(config.tmdb().bearer_token().to_owned());
|
||||||
|
|
||||||
match cli.command() {
|
match cli.command() {
|
||||||
Command::Print { command } => match command {
|
Command::Print { command } => exec_print(client, command).await?,
|
||||||
BackendCommand::Tmdb { command } => {
|
|
||||||
let object = run::tmdb::TmdbObject::fetch(&client, command).await?;
|
|
||||||
println!("{}", object.serialize().context("failed to serialize")?)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Command::Write {
|
Command::Write {
|
||||||
force,
|
force,
|
||||||
output,
|
output,
|
||||||
command,
|
command,
|
||||||
} => match command {
|
} => exec_write(client, force, &output, command).await?,
|
||||||
|
Command::Update { output } => exec_update(client, &output).await?,
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn exec_print(client: Client, command: BackendCommand) -> Result<()> {
|
||||||
|
match command {
|
||||||
BackendCommand::Tmdb { command } => {
|
BackendCommand::Tmdb { command } => {
|
||||||
let object = run::tmdb::TmdbObject::fetch(&client, command).await?;
|
let object = run::tmdb::TmdbObject::fetch(&client, command).await?;
|
||||||
let output = output
|
println!("{}", object.serialize().context("failed to serialize")?)
|
||||||
.as_ref()
|
}
|
||||||
.map(|p| p.as_path())
|
}
|
||||||
.unwrap_or(Path::new("flix.toml"));
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
let mut file = if *force {
|
async fn exec_write(
|
||||||
|
client: Client,
|
||||||
|
force: bool,
|
||||||
|
output: &Path,
|
||||||
|
command: BackendCommand,
|
||||||
|
) -> Result<()> {
|
||||||
|
match command {
|
||||||
|
BackendCommand::Tmdb { command } => {
|
||||||
|
let object = run::tmdb::TmdbObject::fetch(&client, command).await?;
|
||||||
|
|
||||||
|
let mut file = if force {
|
||||||
fs::File::create(output).await
|
fs::File::create(output).await
|
||||||
} else {
|
} else {
|
||||||
fs::File::create_new(output).await
|
fs::File::create_new(output).await
|
||||||
@@ -60,8 +75,17 @@ async fn main() -> Result<()> {
|
|||||||
.await
|
.await
|
||||||
.with_context(|| format!("could not write to file at path {}", output.display()))?;
|
.with_context(|| format!("could not write to file at path {}", output.display()))?;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn exec_update(client: Client, output: &Path) -> Result<()> {
|
||||||
|
let content = fs::read_to_string(output)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("failed to read file at path: {}", output.display()))?;
|
||||||
|
let object: FlixObject = toml::from_str(&content)
|
||||||
|
.with_context(|| format!("failed to deserialize flix file: {}", output.display()))?;
|
||||||
|
|
||||||
|
let command = object.backend_command()?;
|
||||||
|
exec_write(client, true, output, command).await
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
use flix::model::{Collection, Episode, Movie, Season, Show, Verse};
|
||||||
|
|
||||||
|
use anyhow::{Result, anyhow, bail};
|
||||||
|
|
||||||
|
use crate::cli::BackendCommand;
|
||||||
|
use crate::cli::tmdb;
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum FlixObject {
|
||||||
|
Collection(Collection),
|
||||||
|
Movie(Movie),
|
||||||
|
Show(Show),
|
||||||
|
Season(Season),
|
||||||
|
Episode(Episode),
|
||||||
|
// DEAD CODE: The TMDB backend does not support Verses
|
||||||
|
#[allow(dead_code)]
|
||||||
|
Verse(Verse),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FlixObject {
|
||||||
|
pub fn backend_command(&self) -> Result<BackendCommand> {
|
||||||
|
Ok(match self {
|
||||||
|
FlixObject::Collection(collection) => {
|
||||||
|
let Some(ref tmdb) = collection.tmdb else {
|
||||||
|
bail!("missing tmdb data")
|
||||||
|
};
|
||||||
|
tmdb::Command::Collection { id: tmdb.id.into() }.into()
|
||||||
|
}
|
||||||
|
FlixObject::Movie(movie) => {
|
||||||
|
let Some(ref tmdb) = movie.tmdb else {
|
||||||
|
bail!("missing tmdb data")
|
||||||
|
};
|
||||||
|
tmdb::Command::Movie { id: tmdb.id.into() }.into()
|
||||||
|
}
|
||||||
|
FlixObject::Show(show) => {
|
||||||
|
let Some(ref tmdb) = show.tmdb else {
|
||||||
|
bail!("missing tmdb data")
|
||||||
|
};
|
||||||
|
tmdb::Command::Show { id: tmdb.id.into() }.into()
|
||||||
|
}
|
||||||
|
FlixObject::Season(season) => {
|
||||||
|
let Some(ref tmdb) = season.tmdb else {
|
||||||
|
bail!("missing tmdb data")
|
||||||
|
};
|
||||||
|
tmdb::Command::Season {
|
||||||
|
id: tmdb.show_id.into(),
|
||||||
|
season: season.season.number,
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
FlixObject::Episode(episode) => {
|
||||||
|
let Some(ref tmdb) = episode.tmdb else {
|
||||||
|
bail!("missing tmdb data")
|
||||||
|
};
|
||||||
|
tmdb::Command::Episode {
|
||||||
|
id: tmdb.show_id.into(),
|
||||||
|
season: episode.episode.season,
|
||||||
|
episode: episode
|
||||||
|
.episode
|
||||||
|
.number
|
||||||
|
.primary_episode_number()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow!("the episode does not have a primary episode number")
|
||||||
|
})?,
|
||||||
|
episodes: episode.episode.number.additional_episode_numbers(),
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
FlixObject::Verse(_) => {
|
||||||
|
bail!("verses are not handled")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,2 @@
|
|||||||
|
pub mod flix;
|
||||||
pub mod tmdb;
|
pub mod tmdb;
|
||||||
|
|||||||
+51
-17
@@ -1,14 +1,16 @@
|
|||||||
use flix::model::{
|
use flix::model::{
|
||||||
Collection, Episode, GenericCollection, GenericEpisode, GenericMovie, GenericSeason,
|
Collection, Episode, EpisodeNumber, GenericCollection, GenericEpisode, GenericMovie,
|
||||||
GenericShow, Movie, Season, Show, TmdbCollection, TmdbMovie, TmdbShow,
|
GenericSeason, GenericShow, Movie, Season, Show, TmdbCollection, TmdbEpisode, TmdbMovie,
|
||||||
|
TmdbSeason, TmdbShow,
|
||||||
};
|
};
|
||||||
use flix_tmdb::Client;
|
use flix_tmdb::Client;
|
||||||
use flix_tmdb::model::{
|
use flix_tmdb::model::{
|
||||||
Collection as TCollection, Episode as TEpisode, Movie as TMovie, Season as TSeason,
|
Collection as TCollection, Episode as TEpisode, Movie as TMovie, Season as TSeason,
|
||||||
Show as TShow,
|
Show as TShow, ShowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use futures::{StreamExt, TryStreamExt, stream};
|
||||||
|
|
||||||
use crate::cli::tmdb::Command;
|
use crate::cli::tmdb::Command;
|
||||||
|
|
||||||
@@ -16,8 +18,8 @@ pub enum TmdbObject {
|
|||||||
Collection(TCollection),
|
Collection(TCollection),
|
||||||
Movie(TMovie),
|
Movie(TMovie),
|
||||||
Show(TShow),
|
Show(TShow),
|
||||||
Season(TSeason),
|
Season(TSeason, ShowId),
|
||||||
Episode(TEpisode),
|
Episode(TEpisode, Vec<u32>, u32, ShowId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TmdbObject {
|
impl TmdbObject {
|
||||||
@@ -25,7 +27,7 @@ impl TmdbObject {
|
|||||||
Ok(match self {
|
Ok(match self {
|
||||||
TmdbObject::Collection(tmdb) => toml::to_string(&Collection {
|
TmdbObject::Collection(tmdb) => toml::to_string(&Collection {
|
||||||
collection: GenericCollection {
|
collection: GenericCollection {
|
||||||
name: tmdb.name,
|
title: tmdb.title,
|
||||||
overview: tmdb.overview,
|
overview: tmdb.overview,
|
||||||
},
|
},
|
||||||
tmdb: Some(TmdbCollection { id: tmdb.id }),
|
tmdb: Some(TmdbCollection { id: tmdb.id }),
|
||||||
@@ -44,7 +46,7 @@ impl TmdbObject {
|
|||||||
})?,
|
})?,
|
||||||
TmdbObject::Show(tmdb) => toml::to_string(&Show {
|
TmdbObject::Show(tmdb) => toml::to_string(&Show {
|
||||||
show: GenericShow {
|
show: GenericShow {
|
||||||
name: tmdb.name,
|
title: tmdb.title,
|
||||||
overview: tmdb.overview,
|
overview: tmdb.overview,
|
||||||
genres: tmdb.genres.iter().cloned().map(|g| g.name).collect(),
|
genres: tmdb.genres.iter().cloned().map(|g| g.name).collect(),
|
||||||
air_date: tmdb.first_air_date,
|
air_date: tmdb.first_air_date,
|
||||||
@@ -54,29 +56,43 @@ impl TmdbObject {
|
|||||||
genres: tmdb.genres.iter().map(|g| g.id).collect(),
|
genres: tmdb.genres.iter().map(|g| g.id).collect(),
|
||||||
}),
|
}),
|
||||||
})?,
|
})?,
|
||||||
TmdbObject::Season(tmdb) => toml::to_string(&Season {
|
TmdbObject::Season(tmdb, show_id) => toml::to_string(&Season {
|
||||||
season: GenericSeason {
|
season: GenericSeason {
|
||||||
number: tmdb.season_number,
|
number: tmdb.season_number,
|
||||||
name: tmdb.name,
|
title: tmdb.title,
|
||||||
overview: tmdb.overview,
|
overview: tmdb.overview,
|
||||||
air_date: tmdb.air_date,
|
air_date: tmdb.air_date,
|
||||||
},
|
},
|
||||||
|
tmdb: Some(TmdbSeason { show_id }),
|
||||||
})?,
|
})?,
|
||||||
TmdbObject::Episode(tmdb) => toml::to_string(&Episode {
|
TmdbObject::Episode(tmdb, mut episode_numbers, season_number, show_id) => {
|
||||||
|
toml::to_string(&Episode {
|
||||||
episode: GenericEpisode {
|
episode: GenericEpisode {
|
||||||
|
number: if episode_numbers.is_empty() {
|
||||||
|
EpisodeNumber::Single {
|
||||||
number: tmdb.episode_number,
|
number: tmdb.episode_number,
|
||||||
name: tmdb.name,
|
}
|
||||||
|
} else {
|
||||||
|
episode_numbers.insert(0, tmdb.episode_number);
|
||||||
|
EpisodeNumber::Multiple {
|
||||||
|
numbers: episode_numbers,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
season: season_number,
|
||||||
|
title: tmdb.title,
|
||||||
overview: tmdb.overview,
|
overview: tmdb.overview,
|
||||||
air_date: tmdb.air_date,
|
air_date: tmdb.air_date,
|
||||||
},
|
},
|
||||||
})?,
|
tmdb: Some(TmdbEpisode { show_id }),
|
||||||
|
})?
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TmdbObject {
|
impl TmdbObject {
|
||||||
pub async fn fetch(client: &Client, command: &Command) -> Result<Self> {
|
pub async fn fetch(client: &Client, command: Command) -> Result<Self> {
|
||||||
Ok(match *command {
|
Ok(match command {
|
||||||
Command::Collection { id } => Self::Collection(
|
Command::Collection { id } => Self::Collection(
|
||||||
client
|
client
|
||||||
.collections()
|
.collections()
|
||||||
@@ -104,20 +120,38 @@ impl TmdbObject {
|
|||||||
.get_details(id, season, None)
|
.get_details(id, season, None)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("could not get show details for '{id}' S{season}"))?,
|
.with_context(|| format!("could not get show details for '{id}' S{season}"))?,
|
||||||
|
id.into(),
|
||||||
),
|
),
|
||||||
Command::Episode {
|
Command::Episode {
|
||||||
id,
|
id,
|
||||||
season,
|
season,
|
||||||
episode,
|
episode,
|
||||||
} => Self::Episode(
|
episodes,
|
||||||
|
} => {
|
||||||
|
let mut episode = client
|
||||||
|
.episodes()
|
||||||
|
.get_details(id, season, episode, None)
|
||||||
|
.await
|
||||||
|
.with_context(|| {
|
||||||
|
format!("could not get show details for '{id}' S{season}E{episode}")
|
||||||
|
})?;
|
||||||
|
let title = stream::once(async { Ok(episode.title) })
|
||||||
|
.chain(stream::iter(episodes.clone()).then(|episode| async move {
|
||||||
client
|
client
|
||||||
.episodes()
|
.episodes()
|
||||||
.get_details(id, season, episode, None)
|
.get_details(id, season, episode, None)
|
||||||
.await
|
.await
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!("could not get show details for '{id}' S{season}E{episode}")
|
format!("could not get show details for '{id}' S{season}E{episode}")
|
||||||
})?,
|
})
|
||||||
),
|
.map(|episode| episode.title)
|
||||||
|
}))
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await?
|
||||||
|
.join(" + ");
|
||||||
|
episode.title = title;
|
||||||
|
Self::Episode(episode, episodes, season, id.into())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix"
|
name = "flix"
|
||||||
version = "0.0.4"
|
version = "0.0.8"
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
description = "Types for storing persistent data about media"
|
description = "Types for storing persistent data about media"
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ pub struct Collection {
|
|||||||
/// The generic collection data
|
/// The generic collection data
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GenericCollection {
|
pub struct GenericCollection {
|
||||||
/// The collection's name
|
/// The collection's title
|
||||||
pub name: String,
|
pub title: String,
|
||||||
/// The collection's overview
|
/// The collection's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#[cfg(feature = "tmdb")]
|
||||||
|
use flix_tmdb::model::ShowId;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
|
||||||
/// An Episode container
|
/// An Episode container
|
||||||
@@ -5,17 +8,66 @@ use chrono::NaiveDate;
|
|||||||
pub struct Episode {
|
pub struct Episode {
|
||||||
/// The generic episode data
|
/// The generic episode data
|
||||||
pub episode: GenericEpisode,
|
pub episode: GenericEpisode,
|
||||||
|
|
||||||
|
/// The TMDB episode data
|
||||||
|
#[cfg(feature = "tmdb")]
|
||||||
|
pub tmdb: Option<TmdbEpisode>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A wrapper for handling single and multi-episode entries
|
||||||
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum EpisodeNumber {
|
||||||
|
/// The entry contains a single episode
|
||||||
|
Single {
|
||||||
|
/// The episode's number
|
||||||
|
number: u32,
|
||||||
|
},
|
||||||
|
/// The entry contains multiple episodes
|
||||||
|
Multiple {
|
||||||
|
/// The list of episode numbers
|
||||||
|
numbers: Vec<u32>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EpisodeNumber {
|
||||||
|
/// Get the primary episode number of this episode
|
||||||
|
pub fn primary_episode_number(&self) -> Option<u32> {
|
||||||
|
match self {
|
||||||
|
EpisodeNumber::Single { number } => Some(*number),
|
||||||
|
EpisodeNumber::Multiple { numbers } => numbers.first().copied(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get additional episode numbers of this episode
|
||||||
|
pub fn additional_episode_numbers(&self) -> Vec<u32> {
|
||||||
|
match self {
|
||||||
|
EpisodeNumber::Single { number: _ } => vec![],
|
||||||
|
EpisodeNumber::Multiple { numbers } => numbers.iter().skip(1).copied().collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The generic episode data
|
/// The generic episode data
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GenericEpisode {
|
pub struct GenericEpisode {
|
||||||
/// The episode's number
|
/// The episode's number(s)
|
||||||
pub number: u32,
|
#[serde(flatten)]
|
||||||
/// The episode's name
|
pub number: EpisodeNumber,
|
||||||
pub name: String,
|
/// The episode's season's number
|
||||||
|
pub season: u32,
|
||||||
|
/// The episode's title
|
||||||
|
pub title: String,
|
||||||
/// The episode's overview
|
/// The episode's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The episode's air date
|
/// The episode's air date
|
||||||
pub air_date: NaiveDate,
|
pub air_date: NaiveDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The TMDB show data
|
||||||
|
#[cfg(feature = "tmdb")]
|
||||||
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct TmdbEpisode {
|
||||||
|
/// The episodes's show's TMDB ID
|
||||||
|
pub show_id: ShowId,
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#[cfg(feature = "tmdb")]
|
||||||
|
use flix_tmdb::model::ShowId;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
|
||||||
/// A Season container
|
/// A Season container
|
||||||
@@ -5,6 +8,10 @@ use chrono::NaiveDate;
|
|||||||
pub struct Season {
|
pub struct Season {
|
||||||
/// The generic season data
|
/// The generic season data
|
||||||
pub season: GenericSeason,
|
pub season: GenericSeason,
|
||||||
|
|
||||||
|
/// The TMDB season data
|
||||||
|
#[cfg(feature = "tmdb")]
|
||||||
|
pub tmdb: Option<TmdbSeason>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The generic season data
|
/// The generic season data
|
||||||
@@ -12,10 +19,18 @@ pub struct Season {
|
|||||||
pub struct GenericSeason {
|
pub struct GenericSeason {
|
||||||
/// The season's number
|
/// The season's number
|
||||||
pub number: u32,
|
pub number: u32,
|
||||||
/// The season's name
|
/// The season's title
|
||||||
pub name: String,
|
pub title: String,
|
||||||
/// The season's overview
|
/// The season's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The season's air date
|
/// The season's air date
|
||||||
pub air_date: NaiveDate,
|
pub air_date: NaiveDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The TMDB show data
|
||||||
|
#[cfg(feature = "tmdb")]
|
||||||
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct TmdbSeason {
|
||||||
|
/// The season's show's TMDB ID
|
||||||
|
pub show_id: ShowId,
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ pub struct Show {
|
|||||||
/// The generic show data
|
/// The generic show data
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GenericShow {
|
pub struct GenericShow {
|
||||||
/// The show's name
|
/// The show's title
|
||||||
pub name: String,
|
pub title: String,
|
||||||
/// The show's overview
|
/// The show's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The show's genres
|
/// The show's genres
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "tmdb")]
|
#[cfg(feature = "tmdb")]
|
||||||
use flix_tmdb::model::{MovieId, ShowId};
|
use flix_tmdb::model::{CollectionId, MovieId, ShowId};
|
||||||
|
|
||||||
/// A Verse container
|
/// A Verse container
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
@@ -15,8 +15,8 @@ pub struct Verse {
|
|||||||
/// The generic verse data
|
/// The generic verse data
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct GenericVerse {
|
pub struct GenericVerse {
|
||||||
/// The verse's name
|
/// The verse's title
|
||||||
pub name: String,
|
pub title: String,
|
||||||
/// The verse's overview
|
/// The verse's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
}
|
}
|
||||||
@@ -25,8 +25,16 @@ pub struct GenericVerse {
|
|||||||
#[cfg(feature = "tmdb")]
|
#[cfg(feature = "tmdb")]
|
||||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct TmdbVerse {
|
pub struct TmdbVerse {
|
||||||
|
/// The list of collection TMDB IDs in the verse
|
||||||
|
#[serde(default)]
|
||||||
|
pub collections: Vec<CollectionId>,
|
||||||
/// The list of movie TMDB IDs in the verse
|
/// The list of movie TMDB IDs in the verse
|
||||||
|
#[serde(default)]
|
||||||
pub movies: Vec<MovieId>,
|
pub movies: Vec<MovieId>,
|
||||||
/// The list of show TMDB IDs in the verse
|
/// The list of show TMDB IDs in the verse
|
||||||
|
#[serde(default)]
|
||||||
pub shows: Vec<ShowId>,
|
pub shows: Vec<ShowId>,
|
||||||
|
/// The list of sub-verse names
|
||||||
|
#[serde(default)]
|
||||||
|
pub verses: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "flix-tmdb"
|
name = "flix-tmdb"
|
||||||
version = "0.0.4"
|
version = "0.0.8"
|
||||||
|
|
||||||
categories = []
|
categories = []
|
||||||
description = "Clients and models for fetching data from TMDB"
|
description = "Clients and models for fetching data from TMDB"
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ use super::{CollectionId, MovieId};
|
|||||||
pub struct Collection {
|
pub struct Collection {
|
||||||
/// The collection's TMDB ID
|
/// The collection's TMDB ID
|
||||||
pub id: CollectionId,
|
pub id: CollectionId,
|
||||||
/// The collection's name
|
/// The collection's title
|
||||||
pub name: String,
|
#[serde(rename = "name")]
|
||||||
|
pub title: String,
|
||||||
/// The collection's overview
|
/// The collection's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The list of movies that are part of this collection
|
/// The list of movies that are part of this collection
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ use chrono::NaiveDate;
|
|||||||
pub struct Episode {
|
pub struct Episode {
|
||||||
/// The episode's number
|
/// The episode's number
|
||||||
pub episode_number: u32,
|
pub episode_number: u32,
|
||||||
/// The episode's name
|
/// The episode's title
|
||||||
pub name: String,
|
#[serde(rename = "name")]
|
||||||
|
pub title: String,
|
||||||
/// The episode's overview
|
/// The episode's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The episode's air date
|
/// The episode's air date
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
use core::hash::{Hash, Hasher};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
/// The TMDB ID type of a movie genre
|
/// The TMDB ID type of a movie genre
|
||||||
@@ -81,3 +82,9 @@ impl<T> PartialEq for TmdbId<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Eq for TmdbId<T> {}
|
impl<T> Eq for TmdbId<T> {}
|
||||||
|
|
||||||
|
impl<T> Hash for TmdbId<T> {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.inner.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ use super::Episode;
|
|||||||
pub struct Season {
|
pub struct Season {
|
||||||
/// The season's number
|
/// The season's number
|
||||||
pub season_number: u32,
|
pub season_number: u32,
|
||||||
/// The season's name
|
/// The season's title
|
||||||
pub name: String,
|
#[serde(rename = "name")]
|
||||||
|
pub title: String,
|
||||||
/// The season's overview
|
/// The season's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The season's air date
|
/// The season's air date
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ use super::{ShowGenre, ShowId};
|
|||||||
pub struct Show {
|
pub struct Show {
|
||||||
/// The show's TMDB ID
|
/// The show's TMDB ID
|
||||||
pub id: ShowId,
|
pub id: ShowId,
|
||||||
/// The show's name
|
/// The show's title
|
||||||
pub name: String,
|
#[serde(rename = "name")]
|
||||||
|
pub title: String,
|
||||||
/// The show's overview
|
/// The show's overview
|
||||||
pub overview: String,
|
pub overview: String,
|
||||||
/// The list of genres this show belongs to
|
/// The list of genres this show belongs to
|
||||||
|
|||||||
Reference in New Issue
Block a user