aboutsummaryrefslogtreecommitdiff
path: root/common/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-11-18 12:08:34 +0100
committermetamuffin <metamuffin@disroot.org>2025-11-18 12:08:34 +0100
commitbac47e456085ea153ae6ae1b1e28e41868693c9c (patch)
tree062c157d66faa3935c1175433732d30c07d1cd5b /common/src/lib.rs
parentf3af9263b0472bcef3207906ce0e4d1d4aa3595b (diff)
downloadjellything-bac47e456085ea153ae6ae1b1e28e41868693c9c.tar
jellything-bac47e456085ea153ae6ae1b1e28e41868693c9c.tar.bz2
jellything-bac47e456085ea153ae6ae1b1e28e41868693c9c.tar.zst
start reworking model
Diffstat (limited to 'common/src/lib.rs')
-rw-r--r--common/src/lib.rs232
1 files changed, 95 insertions, 137 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs
index 0cc9ab5..d09153e 100644
--- a/common/src/lib.rs
+++ b/common/src/lib.rs
@@ -15,7 +15,6 @@ pub use jellystream_types as stream;
pub use chrono;
-use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, BTreeSet},
@@ -46,7 +45,7 @@ macro_rules! url_enum {
};
}
-#[derive(Clone, Copy, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NodeID(pub [u8; 32]);
pub enum NodeIDOrSlug {
@@ -54,15 +53,11 @@ pub enum NodeIDOrSlug {
Slug(String),
}
-#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct Node {
- #[serde(default)]
pub slug: String,
- #[serde(default)]
pub parents: BTreeSet<NodeID>,
pub kind: NodeKind,
- pub poster: Option<Asset>,
- pub backdrop: Option<Asset>,
pub title: Option<String>,
pub subtitle: Option<String>,
pub tagline: Option<String>,
@@ -70,94 +65,78 @@ pub struct Node {
pub release_date: Option<i64>, // in unix millis
pub index: Option<usize>,
pub media: Option<MediaInfo>,
- #[serde(default)]
- pub ratings: BTreeMap<Rating, f64>,
pub federated: Option<String>,
- #[serde(default)]
pub tags: BTreeSet<String>,
- #[serde(default)]
- pub people: BTreeMap<PeopleGroup, Vec<Appearance>>,
- #[serde(default)]
- pub external_ids: BTreeMap<String, String>,
- #[serde(default)]
+ pub ratings: BTreeMap<RatingType, f64>,
+ pub pictures: BTreeMap<PictureSlot, Asset>,
+ pub credits: BTreeMap<CreditCategory, Vec<Appearance>>,
+ pub identifiers: Identifiers,
pub visibility: Visibility,
- #[serde(default)]
pub storage_size: u64,
}
-#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize, Default)]
+pub struct Identifiers(pub BTreeMap<IdentifierType, String>);
+
+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
+#[serde(rename_all = "snake_case")]
+pub enum PictureSlot {
+ Poster,
+ Cover,
+ Backdrop,
+ Headshot,
+}
+
+#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
+#[serde(rename_all = "snake_case")]
+pub enum IdentifierType {
+ MusicbrainzRecording,
+ MusicbrainzArtist,
+ MusicbrainzRelease,
+ MusicbrainzReleaseGroup,
+ Isrc,
+ Trakt,
+ Imdb,
+ Tmdb,
+ Tvdb,
+ Omdb,
+}
+
+#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct Asset(pub String);
-#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Appearance {
- #[serde(default)]
pub jobs: Vec<String>,
- #[serde(default)]
pub characters: Vec<String>,
- pub person: Person,
-}
-
-#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)]
-pub struct Person {
- pub name: String,
- pub headshot: Option<Asset>,
- pub ids: ObjectIds,
+ pub node: NodeID,
}
-#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)]
-pub struct ObjectIds {
- pub trakt: Option<u64>,
- pub slug: Option<String>,
- pub imdb: Option<String>,
- pub tmdb: Option<u64>,
- pub omdb: Option<u64>,
- pub tvdb: Option<u64>,
+#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
+#[serde(rename_all = "snake_case")]
+pub enum CreditCategory {
+ Cast,
+ Writing,
+ Directing,
+ Art,
+ Sound,
+ Camera,
+ Lighting,
+ Crew,
+ Editing,
+ Production,
+ Vfx,
+ CostumeMakeup,
+ CreatedBy,
+ 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,
- Clone,
- Copy,
- Deserialize,
- Serialize,
- PartialEq,
- Eq,
- PartialOrd,
- Ord,
- Encode,
- Decode,
- Default,
-)]
+#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Default)]
#[serde(rename_all = "snake_case")]
pub enum Visibility {
Hidden,
@@ -166,39 +145,24 @@ pub enum Visibility {
Visible,
}
-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, Copy, Deserialize, Serialize, PartialEq, Eq, Default, PartialOrd, Ord)]
+#[serde(rename_all = "snake_case")]
+pub enum NodeKind {
+ #[default]
+ Unknown,
+ Movie,
+ Video,
+ Music,
+ ShortFormVideo,
+ Collection,
+ Channel,
+ Show,
+ Series,
+ Season,
+ Episode,
+}
-#[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum TrackSource {
Local(Asset),
@@ -207,13 +171,13 @@ pub enum TrackSource {
pub type TrackID = usize;
-#[derive(Debug, Clone, Deserialize, Serialize, Hash, Encode, Decode, PartialEq, Eq)]
+#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)]
pub struct LocalTrack {
pub path: PathBuf,
pub track: TrackID,
}
-#[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MediaInfo {
pub duration: f64, // in seconds
pub tracks: Vec<SourceTrack>,
@@ -221,14 +185,14 @@ pub struct MediaInfo {
pub chapters: Vec<Chapter>,
}
-#[derive(Debug, Clone, Deserialize, Serialize, Default, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct Chapter {
pub time_start: Option<f64>,
pub time_end: Option<f64>,
pub labels: Vec<(String, String)>,
}
-#[derive(Debug, Clone, Deserialize, Serialize, Encode, Decode)]
+#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SourceTrack {
pub source: TrackSource,
pub kind: SourceTrackKind,
@@ -239,32 +203,25 @@ pub struct SourceTrack {
pub federated: Vec<String>,
}
-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, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[serde(rename_all = "snake_case")]
+pub enum RatingType {
+ Imdb,
+ Tmdb,
+ RottenTomatoes,
+ Metacritic,
+ YoutubeViews,
+ YoutubeLikes,
+ YoutubeFollowers,
+ Trakt,
+}
-#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Encode, Decode)]
+#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum SourceTrackKind {
Video {
width: u64,
height: u64,
- display_width: Option<u64>,
- display_height: Option<u64>,
- display_unit: u64,
fps: Option<f64>,
},
Audio {
@@ -275,7 +232,8 @@ pub enum SourceTrackKind {
Subtitle,
}
-#[derive(Debug, Serialize, Deserialize, Clone, Copy, Hash, PartialEq, Encode, Decode)]
+// TODO move this somewhere else
+#[derive(Debug, Serialize, Deserialize, Clone, Copy, Hash, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TraktKind {
Movie,