diff options
Diffstat (limited to 'common/src/impl.rs')
-rw-r--r-- | common/src/impl.rs | 124 |
1 files changed, 111 insertions, 13 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(()), + }) + } +} |