diff options
Diffstat (limited to 'common/src')
-rw-r--r-- | common/src/impl.rs | 124 | ||||
-rw-r--r-- | common/src/jhls.rs | 4 | ||||
-rw-r--r-- | common/src/lib.rs | 252 |
3 files changed, 160 insertions, 220 deletions
diff --git a/common/src/impl.rs b/common/src/impl.rs index 25cc47d..a35216b 100644 --- a/common/src/impl.rs +++ b/common/src/impl.rs @@ -1,9 +1,10 @@ /* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2024 metamuffin <metamuffin.org> + Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::{AssetRole, SourceTrack, SourceTrackKind}; +use crate::{ObjectIds, PeopleGroup, SourceTrack, SourceTrackKind, TmdbKind, TraktKind}; +use std::{fmt::Display, str::FromStr}; impl SourceTrackKind { pub fn letter(&self) -> char { @@ -14,17 +15,7 @@ impl SourceTrackKind { } } } - -impl AssetRole { - pub fn as_str(&self) -> &'static str { - match self { - AssetRole::Poster => "poster", - AssetRole::Backdrop => "backdrop", - } - } -} - -impl std::fmt::Display for SourceTrack { +impl Display for SourceTrack { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let kspec = match &self.kind { SourceTrackKind::Video { @@ -48,3 +39,110 @@ impl std::fmt::Display for SourceTrack { )) } } + +impl Display for TmdbKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + TmdbKind::Tv => "tv", + TmdbKind::Movie => "movie", + }) + } +} + +impl TraktKind { + pub fn singular(self) -> &'static str { + match self { + TraktKind::Movie => "movie", + TraktKind::Show => "show", + TraktKind::Season => "season", + TraktKind::Episode => "episode", + TraktKind::Person => "person", + TraktKind::User => "user", + } + } + pub fn plural(self) -> &'static str { + match self { + TraktKind::Movie => "movies", + TraktKind::Show => "shows", + TraktKind::Season => "seasons", + TraktKind::Episode => "episodes", + TraktKind::Person => "people", + TraktKind::User => "users", // //! not used in API + } + } +} +impl Display for TraktKind { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + TraktKind::Movie => "Movie", + TraktKind::Show => "Show", + TraktKind::Season => "Season", + TraktKind::Episode => "Episode", + TraktKind::Person => "Person", + TraktKind::User => "User", + }) + } +} +impl Display for ObjectIds { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Some(id) = self.trakt { + f.write_fmt(format_args!("trakt={}", id))?; + } + if let Some(_id) = &self.slug { + f.write_str(",slug")?; + } + if let Some(id) = self.tmdb { + f.write_fmt(format_args!(",tmdb={}", id))?; + } + if let Some(_id) = &self.imdb { + f.write_str(",imdb")?; + } + if let Some(_id) = &self.tvdb { + f.write_str(",tvdb")?; + } + if let Some(_id) = &self.omdb { + f.write_str(",omdb")?; + } + Ok(()) + } +} +impl Display for PeopleGroup { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + PeopleGroup::Cast => "Cast", + PeopleGroup::Writing => "Writing", + PeopleGroup::Directing => "Directing", + PeopleGroup::Art => "Art", + PeopleGroup::Sound => "Sound", + PeopleGroup::Camera => "Camera", + PeopleGroup::Lighting => "Lighting", + PeopleGroup::Crew => "Crew", + PeopleGroup::Editing => "Editing", + PeopleGroup::Production => "Production", + PeopleGroup::Vfx => "Visual Effects", + PeopleGroup::CostumeMakeup => "Costume & Makeup", + PeopleGroup::CreatedBy => "Created by:", + }) + } +} +impl FromStr for PeopleGroup { + type Err = (); + fn from_str(s: &str) -> Result<Self, Self::Err> { + Ok(match s { + "Cast" => PeopleGroup::Cast, + "Writing" => PeopleGroup::Writing, + "Directing" => PeopleGroup::Directing, + "Art" => PeopleGroup::Art, + "Sound" => PeopleGroup::Sound, + "Camera" => PeopleGroup::Camera, + "Lighting" => PeopleGroup::Lighting, + "Crew" => PeopleGroup::Crew, + "Editing" => PeopleGroup::Editing, + "Production" => PeopleGroup::Production, + "Visual Effects" => PeopleGroup::Vfx, + "Costume & Makeup" => PeopleGroup::CostumeMakeup, + "Created by:" => PeopleGroup::CreatedBy, + _ => return Err(()), + }) + } +} diff --git a/common/src/jhls.rs b/common/src/jhls.rs index 12fa2d6..846e43a 100644 --- a/common/src/jhls.rs +++ b/common/src/jhls.rs @@ -1,9 +1,9 @@ -use bincode::{Decode, Encode}; /* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2024 metamuffin <metamuffin.org> + Copyright (C) 2025 metamuffin <metamuffin.org> */ +use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; use std::ops::Range; diff --git a/common/src/lib.rs b/common/src/lib.rs index 7403347..a72f345 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,9 +1,8 @@ /* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2024 metamuffin <metamuffin.org> + Copyright (C) 2025 metamuffin <metamuffin.org> */ -#![allow(clippy::needless_borrows_for_generic_args)] pub mod config; pub mod helpers; pub mod r#impl; @@ -15,61 +14,34 @@ pub mod user; pub use chrono; use bincode::{Decode, Encode}; -#[cfg(feature = "rocket")] -use rocket::{FromFormField, UriDisplayQuery}; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, fmt::Display, path::PathBuf}; +use std::{collections::BTreeMap, path::PathBuf}; #[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] pub struct Node { - #[serde(default)] - pub public: NodePublic, - #[serde(default)] - pub private: NodePrivate, -} - -#[rustfmt::skip] -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode,Decode)] -pub struct NodePrivate { - #[serde(default)] pub id: Option<String>, - #[serde(default)] pub source: Option<Vec<TrackSource>>, - - #[serde(default)] pub poster: Option<PathBuf>, - #[serde(default)] pub backdrop: Option<PathBuf>, -} - -#[rustfmt::skip] -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] -pub struct NodePublic { - #[serde(default)] pub kind: Option<NodeKind>, - - #[serde(default)] pub poster: Option<Asset>, - #[serde(default)] pub backdrop: Option<Asset>, - - #[serde(default)] pub title: Option<String>, - #[serde(default)] pub subtitle: Option<String>, - #[serde(default)] pub id: Option<String>, - #[serde(default)] pub path: Vec<String>, - #[serde(default)] pub tagline: Option<String>, - #[serde(default)] pub children: Vec<String>, - #[serde(default)] pub description: Option<String>, - #[serde(default)] pub release_date: Option<i64>, // in unix millis - #[serde(default)] pub index: Option<usize>, - #[serde(default)] pub media: Option<MediaInfo>, - #[serde(default)] pub ratings: BTreeMap<Rating, f64>, - #[serde(default)] pub federated: Option<String>, + pub slug: String, + pub parents: Vec<String>, + pub kind: Option<NodeKind>, + pub poster: Option<Asset>, + pub backdrop: Option<Asset>, + pub title: Option<String>, + pub subtitle: Option<String>, + pub id: Option<String>, + pub tagline: Option<String>, + pub description: Option<String>, + pub release_date: Option<i64>, // in unix millis + pub index: Option<usize>, + pub media: Option<MediaInfo>, + pub ratings: BTreeMap<Rating, f64>, + pub federated: Option<String>, + pub people: BTreeMap<PeopleGroup, Vec<Appearance>>, + pub external_ids: ObjectIds, } -#[derive(Debug, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Encode, Decode)] pub struct Asset(pub String); #[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] -pub struct ExtendedNode { - pub ids: ObjectIds, - pub people: BTreeMap<PeopleGroup, Vec<Appearance>>, -} - -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] pub struct Appearance { #[serde(default)] pub jobs: Vec<String>, @@ -95,75 +67,37 @@ pub struct ObjectIds { pub tvdb: Option<u64>, } -#[rustfmt::skip] #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)] -#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] #[serde(rename_all = "snake_case")] pub enum PeopleGroup { - #[cfg_attr(feature = "rocket", field(value = "cast"))] Cast, - #[cfg_attr(feature = "rocket", field(value = "writing"))] Writing, - #[cfg_attr(feature = "rocket", field(value = "directing"))] Directing, - #[cfg_attr(feature = "rocket", field(value = "art"))] Art, - #[cfg_attr(feature = "rocket", field(value = "sound"))] Sound, - #[cfg_attr(feature = "rocket", field(value = "camera"))] Camera, - #[cfg_attr(feature = "rocket", field(value = "lighting"))] Lighting, - #[cfg_attr(feature = "rocket", field(value = "crew"))] Crew, - #[cfg_attr(feature = "rocket", field(value = "editing"))] Editing, - #[cfg_attr(feature = "rocket", field(value = "production"))] Production, - #[cfg_attr(feature = "rocket", field(value = "vfx"))] Vfx, - #[cfg_attr(feature = "rocket", field(value = "costume"))] CostumeMakeup, - #[cfg_attr(feature = "rocket", field(value = "createdby"))] CreatedBy, -} - -#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)] -pub struct ImportOptions { - pub id: String, - pub sources: Vec<ImportSource>, -} - -#[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)] -#[serde(rename_all = "snake_case")] -pub enum ImportSource { - Override(Node), - Tmdb { - kind: TmdbKind, - id: u64, - }, - Trakt { - kind: TraktKind, - id: u64, - }, - AutoChildren { - path: Option<PathBuf>, - }, - Media { - path: PathBuf, - #[serde(default)] - ignore_metadata: bool, - #[serde(default)] - ignore_attachments: bool, - #[serde(default)] - ignore_chapters: bool, - }, - Federated { - host: String, - }, + Cast, + Writing, + Directing, + Art, + Sound, + Camera, + Lighting, + Crew, + Editing, + Production, + Vfx, + CostumeMakeup, + CreatedBy, } -#[rustfmt::skip] -#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Default, Encode,Decode)] -#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] +#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Default, Encode, Decode)] #[serde(rename_all = "snake_case")] pub enum NodeKind { - #[cfg_attr(feature = "rocket", field(value = "movie"))] #[default] Movie, - #[cfg_attr(feature = "rocket", field(value = "video"))] Video, - #[cfg_attr(feature = "rocket", field(value = "shortformvideo"))] ShortFormVideo, - #[cfg_attr(feature = "rocket", field(value = "collection"))] Collection, - #[cfg_attr(feature = "rocket", field(value = "channel"))] Channel, - #[cfg_attr(feature = "rocket", field(value = "show"))] Show, - #[cfg_attr(feature = "rocket", field(value = "series"))] Series, - #[cfg_attr(feature = "rocket", field(value = "season"))] Season, - #[cfg_attr(feature = "rocket", field(value = "episode"))] Episode, + #[default] + Movie, + Video, + ShortFormVideo, + Collection, + Channel, + Show, + Series, + Season, + Episode, } #[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)] @@ -175,7 +109,7 @@ pub enum TrackSource { pub type TrackID = usize; -#[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode, Hash)] +#[derive(Debug, Clone, Deserialize, Serialize, Hash, Encode, Decode)] pub struct LocalTrack { pub path: PathBuf, pub track: TrackID, @@ -199,6 +133,7 @@ pub struct Chapter { #[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)] pub struct SourceTrack { + pub source: TrackSource, pub kind: SourceTrackKind, pub name: String, pub codec: String, @@ -242,14 +177,6 @@ pub enum SourceTrackKind { Subtitles, } -#[rustfmt::skip] -#[derive(Debug, Clone, Copy, Encode, Decode)] -#[cfg_attr(feature = "rocket", derive(FromFormField, UriDisplayQuery))] -pub enum AssetRole { - #[cfg_attr(feature = "rocket", field(value = "poster"))] Poster, - #[cfg_attr(feature = "rocket", field(value = "backdrop"))] Backdrop, -} - #[derive(Debug, Serialize, Deserialize, Clone, Copy, Encode, Decode)] #[serde(rename_all = "snake_case")] pub enum TraktKind { @@ -261,93 +188,8 @@ pub enum TraktKind { User, } -impl TraktKind { - pub fn singular(self) -> &'static str { - match self { - TraktKind::Movie => "movie", - TraktKind::Show => "show", - TraktKind::Season => "season", - TraktKind::Episode => "episode", - TraktKind::Person => "person", - TraktKind::User => "user", - } - } - pub fn plural(self) -> &'static str { - match self { - TraktKind::Movie => "movies", - TraktKind::Show => "shows", - TraktKind::Season => "seasons", - TraktKind::Episode => "episodes", - TraktKind::Person => "people", - TraktKind::User => "users", // //! not used in API - } - } -} -impl Display for TraktKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(match self { - TraktKind::Movie => "Movie", - TraktKind::Show => "Show", - TraktKind::Season => "Season", - TraktKind::Episode => "Episode", - TraktKind::Person => "Person", - TraktKind::User => "User", - }) - } -} -impl Display for ObjectIds { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if let Some(id) = self.trakt { - f.write_fmt(format_args!("trakt={}", id))?; - } - if let Some(_id) = &self.slug { - f.write_str(",slug")?; - } - if let Some(id) = self.tmdb { - f.write_fmt(format_args!(",tmdb={}", id))?; - } - if let Some(_id) = &self.imdb { - f.write_str(",imdb")?; - } - if let Some(_id) = &self.tvdb { - f.write_str(",tvdb")?; - } - if let Some(_id) = &self.omdb { - f.write_str(",omdb")?; - } - Ok(()) - } -} -impl Display for PeopleGroup { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(match self { - PeopleGroup::Cast => "Cast", - PeopleGroup::Writing => "Writing", - PeopleGroup::Directing => "Directing", - PeopleGroup::Art => "Art", - PeopleGroup::Sound => "Sound", - PeopleGroup::Camera => "Camera", - PeopleGroup::Lighting => "Lighting", - PeopleGroup::Crew => "Crew", - PeopleGroup::Editing => "Editing", - PeopleGroup::Production => "Production", - PeopleGroup::Vfx => "Visual Effects", - PeopleGroup::CostumeMakeup => "Costume & Makeup", - PeopleGroup::CreatedBy => "Created by:", - }) - } -} - -#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum TmdbKind { Tv, Movie, } -impl Display for TmdbKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(match self { - TmdbKind::Tv => "tv", - TmdbKind::Movie => "movie", - }) - } -} |