aboutsummaryrefslogtreecommitdiff
path: root/common/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/lib.rs')
-rw-r--r--common/src/lib.rs170
1 files changed, 101 insertions, 69 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs
index c606b86..26bf361 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -9,9 +9,9 @@ pub mod config;
pub mod helpers;
pub mod r#impl;
pub mod jhls;
+pub mod routes;
pub mod stream;
pub mod user;
-pub mod routes;
pub use chrono;
@@ -22,6 +22,30 @@ use std::{
path::PathBuf,
};
+#[macro_export]
+macro_rules! url_enum {
+ ($(#[$a:meta])* enum $i:ident { $($(#[$va:meta])* $vi:ident = $vk:literal),*, }) => {
+ $(#[$a])*
+ pub enum $i { $($(#[$va])* $vi),* }
+ impl $i {
+ pub const ALL: &'static [$i] = &[$($i::$vi),*];
+ pub fn to_str(&self) -> &'static str { match self { $(Self::$vi => $vk),* } }
+ pub fn from_str(s: &str) -> Option<Self> { match s { $($vk => Some(Self::$vi) ),*, _ => None } }
+ }
+ impl std::fmt::Display for $i {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.write_str(self.to_str())
+ }
+ }
+ impl std::str::FromStr for $i {
+ type Err = ();
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ Self::from_str(s).ok_or(())
+ }
+ }
+ };
+}
+
#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NodeID(pub [u8; 32]);
@@ -90,31 +114,35 @@ pub struct ObjectIds {
pub tvdb: Option<u64>,
}
-#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
-#[serde(rename_all = "snake_case")]
-pub enum PeopleGroup {
- Cast,
- Writing,
- Directing,
- Art,
- Sound,
- Camera,
- Lighting,
- Crew,
- Editing,
- Production,
- Vfx,
- CostumeMakeup,
- CreatedBy,
- // https://musicbrainz.org/relationships/artist-recording
- // modelling after this, but its too many categories
- Performance,
- Instrument,
- Vocal,
- Arranger,
- Producer,
- Engineer,
-}
+url_enum!(
+ #[derive(
+ Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Encode, Decode,
+ )]
+ #[serde(rename_all = "snake_case")]
+ enum PeopleGroup {
+ Cast = "cast",
+ Writing = "writing",
+ Directing = "directing",
+ Art = "art",
+ Sound = "sound",
+ Camera = "camera",
+ Lighting = "lighting",
+ Crew = "crew",
+ Editing = "editing",
+ Production = "production",
+ Vfx = "vfx",
+ CostumeMakeup = "costume_makeup",
+ CreatedBy = "created_by",
+ // https://musicbrainz.org/relationships/artist-recording
+ // modelling after this, but its too many categories
+ Performance = "performance",
+ Instrument = "instrument",
+ Vocal = "vocal",
+ Arranger = "arranger",
+ Producer = "producer",
+ Engineer = "engineer",
+ }
+);
#[derive(
Debug,
@@ -138,35 +166,37 @@ pub enum Visibility {
Visible,
}
-#[derive(
- Debug,
- Clone,
- Copy,
- Deserialize,
- Serialize,
- PartialEq,
- Eq,
- Default,
- Encode,
- Decode,
- PartialOrd,
- Ord,
-)]
-#[serde(rename_all = "snake_case")]
-pub enum NodeKind {
- #[default]
- Unknown,
- Movie,
- Video,
- Music,
- ShortFormVideo,
- Collection,
- Channel,
- Show,
- Series,
- Season,
- Episode,
-}
+url_enum!(
+ #[derive(
+ Debug,
+ Clone,
+ Copy,
+ Deserialize,
+ Serialize,
+ PartialEq,
+ Eq,
+ Default,
+ Encode,
+ Decode,
+ PartialOrd,
+ Ord,
+ )]
+ #[serde(rename_all = "snake_case")]
+ enum NodeKind {
+ #[default]
+ Unknown = "unknown",
+ Movie = "movie",
+ Video = "video",
+ Music = "music",
+ ShortFormVideo = "short_form_video",
+ Collection = "collection",
+ Channel = "channel",
+ Show = "show",
+ Series = "series",
+ Season = "season",
+ Episode = "episode",
+ }
+);
#[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)]
#[serde(rename_all = "snake_case")]
@@ -213,20 +243,22 @@ pub struct SourceTrack {
pub federated: Vec<String>,
}
-#[derive(
- Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode,
-)]
-#[serde(rename_all = "snake_case")]
-pub enum Rating {
- Imdb,
- Tmdb,
- RottenTomatoes,
- Metacritic,
- YoutubeViews,
- YoutubeLikes,
- YoutubeFollowers,
- Trakt,
-}
+url_enum!(
+ #[derive(
+ Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode,
+ )]
+ #[serde(rename_all = "snake_case")]
+ enum Rating {
+ Imdb = "imdb",
+ Tmdb = "tmdb",
+ RottenTomatoes = "rotten_tomatoes",
+ Metacritic = "metacritic",
+ YoutubeViews = "youtube_views",
+ YoutubeLikes = "youtube_likes",
+ YoutubeFollowers = "youtube_followers",
+ Trakt = "trakt",
+ }
+);
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Encode, Decode)]
#[serde(rename_all = "snake_case")]