diff options
Diffstat (limited to 'common/src/lib.rs')
| -rw-r--r-- | common/src/lib.rs | 356 |
1 files changed, 116 insertions, 240 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index f73130f..9ab0b91 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,272 +1,148 @@ /* 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) 2026 metamuffin <metamuffin.org> + Copyright (C) 2025 metamuffin <metamuffin.org> */ #![feature(array_try_map)] pub mod api; -pub mod config; -pub mod helpers; -pub mod r#impl; -pub mod jhls; pub mod routes; pub mod user; -pub use jellystream_types as stream; - -pub use chrono; - -use serde::{Deserialize, Serialize}; -use std::{ - collections::{BTreeMap, BTreeSet}, - 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_opt(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_opt(s).ok_or(()) - } - } - }; -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct NodeID(pub [u8; 32]); - -pub enum NodeIDOrSlug { - ID(NodeID), - Slug(String), -} - use jellyobject::{Object, Tag, TypedTag}; +pub use jellystream_types as stream; use std::marker::PhantomData; -macro_rules! keys { + +macro_rules! fields { ($($id:ident: $type:ty = $tag:literal $name:literal;)*) => { $(pub const $id: TypedTag<$type> = TypedTag(Tag($tag), PhantomData);)* }; } - -keys! { - N_KIND: Tag = 1 "kind"; - N_TITLE: &str = 2 "title"; - N_PARENT: u64 = 3 "parent"; - N_TAGLINE: &str = 4 "tagline"; - N_DESCRIPTION: &str = 5 "description"; - N_RELEASEDATE: u64 = 6 "releasedate"; - N_INDEX: u64 = 7 "index"; - N_SEASON_INDEX: u64 = 8 "season_index"; - N_MEDIA: Object = 9 "media"; - N_TAG: &str = 10 "tag"; - N_RATINGS: Object = 11 "ratings"; - N_PICTURES: Object = 12 "pictures"; - N_IDENTIFIERS: Object = 13 "identifiers"; - N_VISIBILITY: Tag = 14 "visibility"; - N_STORAGE_SIZE: u64 = 15 "storage_size"; - - LANG_NATIVE: &str = 0xa001 "native"; - LANG_ENG: &str = 0xa002 "eng"; - LANG_DEU: &str = 0xa003 "deu"; - LANG_JPN: &str = 0xa003 "jpn"; -} - -#[derive(Debug, Clone, Deserialize, Serialize, Default)] -pub struct Node { - pub slug: String, - pub parents: BTreeSet<NodeID>, - pub kind: NodeKind, - pub title: Option<String>, - pub subtitle: Option<String>, - pub tagline: Option<String>, - pub description: Option<String>, - pub release_date: Option<i64>, // in unix millis - pub index: Option<usize>, - pub season_index: Option<usize>, - pub media: Option<MediaInfo>, - pub federated: Option<String>, - pub tags: BTreeSet<String>, - pub ratings: BTreeMap<RatingType, f64>, - pub pictures: BTreeMap<PictureSlot, Asset>, - pub credits: BTreeMap<CreditCategory, Vec<Appearance>>, - pub identifiers: BTreeMap<IdentifierType, String>, - pub visibility: Visibility, - pub storage_size: u64, +macro_rules! enums { + ($($id:ident = $tag:literal $name:literal;)*) => { + $(pub const $id: Tag = Tag($tag);)* + }; } -#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] -#[serde(rename_all = "snake_case")] -pub enum PictureSlot { - Cover, - Backdrop, -} +fields! { + // Tag counter: 32 -#[repr(u8)] -#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] -#[serde(rename_all = "snake_case")] -pub enum IdentifierType { - MusicbrainzRecording, - MusicbrainzArtist, - MusicbrainzRelease, - MusicbrainzReleaseGroup, - AcoustIdTrack, - YoutubeVideo, - YoutubeChannel, - YoutubeChannelHandle, - Bandcamp, - Isrc, - Barcode, - TraktMovie, - TraktShow, - TraktSeason, - TraktEpisode, - Imdb, - TmdbSeries, - TmdbMovie, - Tvdb, - Omdb, - VgmdbArtist, -} + NO_KIND: Tag = 1 "kind"; + NO_TITLE: &str = 2 "title"; + NO_PARENT: u64 = 3 "parent"; // multi + NO_TAGLINE: &str = 4 "tagline"; + NO_DESCRIPTION: &str = 5 "description"; + NO_RELEASEDATE: u64 = 6 "releasedate"; + NO_INDEX: u64 = 7 "index"; + NO_SEASON_INDEX: u64 = 8 "season_index"; + NO_TRACK: Object = 9 "track"; // multi + NO_CHAPTER: Object = 32 "chapter"; // multi + NO_TAG: &str = 10 "tag"; // multi + NO_RATINGS: Object = 11 "ratings"; + NO_PICTURES: Object = 12 "pictures"; + NO_IDENTIFIERS: Object = 13 "identifiers"; + NO_VISIBILITY: Tag = 14 "visibility"; + NO_STORAGE_SIZE: u64 = 15 "storage_size"; + NO_CREDIT: Object = 33 "credit"; // multi -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Hash)] -pub struct Asset(pub String); + CR_NODE: u64 = 34 "node"; + CR_KIND: Tag = 34 "kind"; + CR_JOB: &str = 34 "node"; -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct Appearance { - pub jobs: Vec<String>, - pub characters: Vec<String>, - pub node: NodeID, -} + TR_KIND: Tag = 16 "kind"; + TR_SOURCE: &str = 17 "source"; + TR_NAME: &str = 18 "name"; + TR_CODEC: &str = 19 "codec"; + TR_LANGUAGE: Tag = 20 "language"; + TR_RATE: f64 = 23 "rate"; + TR_BIT_DEPTH: f64 = 25 "bit_depth"; + TR_CHANNELS: f64 = 28 "channels"; + TR_PIXEL_WIDTH: u32 = 26 "pixel_width"; + TR_PIXEL_HEIGHT: u32 = 27 "pixel_height"; -#[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, -} + TRSOURCE_LOCAL_PATH: &str = 21 "local_path"; + TRSOURCE_LOCAL_TRACKNUM: u64 = 22 "local_tracknum"; -#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Default)] -#[serde(rename_all = "snake_case")] -pub enum Visibility { - Hidden, - Reduced, - #[default] - Visible, -} + CH_START: f64 = 29 "start"; + CH_END: f64 = 30 "end"; + CH_NAME: f64 = 31 "name"; -#[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, -} + LANG_NATIVE: &str = 0xa001 "native"; + LANG_ENG: &str = 0xa002 "eng"; + LANG_DEU: &str = 0xa003 "deu"; + LANG_JPN: &str = 0xa003 "jpn"; -#[derive(Debug, Clone, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] -pub enum TrackSource { - Local(PathBuf, u64), - Remote(usize), -} + PICT_COVER: &str = 0xd001 "cover"; + PICT_BACKDROP: &str = 0xd001 "backdrop"; -pub type TrackID = usize; + RTYP_IMDB: f64 = 0xf001 "imdb"; + RTYP_TMDB: f64 = 0xf002 "tmdb"; + RTYP_ROTTEN_TOMATOES: f64 = 0xf003 "rotten_tomatoes"; + RTYP_METACRITIC: f64 = 0xf004 "metacritic"; + RTYP_YOUTUBE_VIEWS: f64 = 0xf005 "youtube_views"; + RTYP_YOUTUBE_LIKES: f64 = 0xf006 "youtube_likes"; + RTYP_YOUTUBE_FOLLOWERS: f64 = 0xf007 "youtube_followers"; + RTYP_TRAKT: f64 = 0xf008 "trakt"; -#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq)] -pub struct LocalTrack { - pub path: PathBuf, - pub track: TrackID, -} + IDENT_MUSICBRAINZ_RECORDING: &str = 0xc001 "musicbrainz_recording"; + IDENT_MUSICBRAINZ_ARTIST: &str = 0xc002 "musicbrainz_artist"; + IDENT_MUSICBRAINZ_RELEASE: &str = 0xc003 "musicbrainz_release"; + IDENT_MUSICBRAINZ_RELEASE_GROUP: &str = 0xc004 "musicbrainz_release_group"; + IDENT_ACOUST_ID_TRACK: &str = 0xc005 "acoust_id_track"; + IDENT_YOUTUBE_VIDEO: &str = 0xc006 "youtube_video"; + IDENT_YOUTUBE_CHANNEL: &str = 0xc007 "youtube_channel"; + IDENT_YOUTUBE_CHANNEL_HANDLE: &str = 0xc008 "youtube_channel_handle"; + IDENT_BANDCAMP: &str = 0xc009 "bandcamp"; + IDENT_ISRC: &str = 0xc00a "isrc"; + IDENT_BARCODE: &str = 0xc00b "barcode"; + IDENT_TRAKT_MOVIE: &str = 0xc00c "trakt_movie"; + IDENT_TRAKT_SHOW: &str = 0xc00d "trakt_show"; + IDENT_TRAKT_SEASON: &str = 0xc00e "trakt_season"; + IDENT_TRAKT_EPISODE: &str = 0xc00f "trakt_episode"; + IDENT_IMDB: &str = 0xc010 "imdb"; + IDENT_TMDB_SERIES: &str = 0xc011 "tmdb_series"; + IDENT_TMDB_MOVIE: &str = 0xc012 "tmdb_movie"; + IDENT_TVDB: &str = 0xc013 "tvdb"; + IDENT_OMDB: &str = 0xc014 "omdb"; + IDENT_VGMDB_ARTIST: &str = 0xc015 "vgmdb_artist"; -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct MediaInfo { - pub duration: f64, // in seconds - pub tracks: Vec<SourceTrack>, - #[serde(default)] - pub chapters: Vec<Chapter>, } -#[derive(Debug, Clone, Deserialize, Serialize, Default)] -pub struct Chapter { - pub time_start: Option<f64>, - pub time_end: Option<f64>, - pub labels: Vec<(String, String)>, -} +enums! { + VISI_HIDDEN = 0xe001 "hidden"; + VISI_REDUCED = 0xe002 "reduced"; + VISI_VISIBLE = 0xe003 "visible"; -#[derive(Debug, Clone, Deserialize, Serialize)] -pub struct SourceTrack { - pub source: TrackSource, - pub kind: SourceTrackKind, - pub name: String, - pub codec: String, - pub language: String, - #[serde(default)] - pub federated: Vec<String>, -} + TRKIND_VIDEO = 0x1001 "video"; + TRKIND_AUDIO = 0x1001 "audio"; + TRKIND_TEXT = 0x1001 "text"; -#[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, -} + KIND_MOVIE = 0xb001 "movie"; + KIND_VIDEO = 0xb002 "video"; + KIND_MUSIC = 0xb003 "music"; + KIND_SHORTFORMVIDEO = 0xb004 "shortformvideo"; + KIND_COLLECTION = 0xb005 "collection"; + KIND_CHANNEL = 0xb006 "channel"; + KIND_SHOW = 0xb007 "show"; + KIND_SERIES = 0xb008 "series"; + KIND_SEASON = 0xb009 "season"; + KIND_EPISODE = 0xb00a "episode"; -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] -pub enum SourceTrackKind { - Video { - width: u64, - height: u64, - fps: Option<f64>, - }, - Audio { - channels: usize, - sample_rate: f64, - bit_depth: Option<usize>, - }, - Subtitle, + CRCAT_CAST = 0x2001 "cast"; + CRCAT_WRITING = 0x2002 "writing"; + CRCAT_DIRECTING = 0x2003 "directing"; + CRCAT_ART = 0x2004 "art"; + CRCAT_SOUND = 0x2005 "sound"; + CRCAT_CAMERA = 0x2006 "camera"; + CRCAT_LIGHTING = 0x2007 "lighting"; + CRCAT_CREW = 0x2008 "crew"; + CRCAT_EDITING = 0x2009 "editing"; + CRCAT_PRODUCTION = 0x200a "production"; + CRCAT_VFX = 0x200b "vfx"; + CRCAT_COSTUME_MAKEUP = 0x200c "costume_makeup"; + CRCAT_CREATED_BY = 0x200d "created_by"; + CRCAT_PERFORMANCE = 0x200e "performance"; + CRCAT_INSTRUMENT = 0x200f "instrument"; + CRCAT_VOCAL = 0x2010 "vocal"; + CRCAT_ARRANGER = 0x2011 "arranger"; + CRCAT_PRODUCER = 0x2012 "producer"; + CRCAT_ENGINEER = 0x2013 "engineer"; } |