diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-11-30 15:47:20 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-11-30 15:47:20 +0100 |
| commit | e4584a8135584e6591bac7d5397cf227cf3cff92 (patch) | |
| tree | 5f3c2bdd19bbad2a9358f8de2de7f5b6c2846ed8 | |
| parent | 8174d129fbabd2d39323678d11d868893ddb429a (diff) | |
| download | jellything-e4584a8135584e6591bac7d5397cf227cf3cff92.tar jellything-e4584a8135584e6591bac7d5397cf227cf3cff92.tar.bz2 jellything-e4584a8135584e6591bac7d5397cf227cf3cff92.tar.zst | |
eid fixes
| -rw-r--r-- | common/src/lib.rs | 1 | ||||
| -rw-r--r-- | database/src/lib.rs | 23 | ||||
| -rw-r--r-- | import/src/lib.rs | 14 | ||||
| -rw-r--r-- | import/src/trakt.rs | 17 | ||||
| -rw-r--r-- | locale/en.ini | 27 | ||||
| -rw-r--r-- | logic/src/node.rs | 10 | ||||
| -rw-r--r-- | server/src/compat/youtube.rs | 13 | ||||
| -rw-r--r-- | transcoder/src/image.rs | 2 | ||||
| -rw-r--r-- | ui/src/node_page.rs | 2 |
9 files changed, 66 insertions, 43 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index 3f535fd..cf79cc5 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -82,6 +82,7 @@ pub enum PictureSlot { Backdrop, } +#[repr(u8)] #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] #[serde(rename_all = "snake_case")] pub enum IdentifierType { diff --git a/database/src/lib.rs b/database/src/lib.rs index 90f596e..62bc585 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -7,7 +7,7 @@ pub mod search; use anyhow::{Context, Result, anyhow, bail}; use jellycommon::{ - Node, NodeID, + IdentifierType, Node, NodeID, user::{NodeUserData, User}, }; use log::info; @@ -37,8 +37,7 @@ const T_NODE: TableDefinition<[u8; 32], Ser<Node>> = TableDefinition::new("node" const T_NODE_CHILDREN: TableDefinition<([u8; 32], [u8; 32]), ()> = TableDefinition::new("node_children"); const T_TAG_NODE: TableDefinition<(&str, [u8; 32]), ()> = TableDefinition::new("tag_node"); -const T_NODE_EXTERNAL_ID: TableDefinition<(&str, &str), [u8; 32]> = - TableDefinition::new("node_external_id"); +const T_NODE_IDENTIFIER: TableDefinition<(u8, &str), [u8; 32]> = TableDefinition::new("node_ids"); const T_IMPORT_FILE_MTIME: TableDefinition<&[u8], u64> = TableDefinition::new("import_file_mtime"); const T_NODE_MTIME: TableDefinition<[u8; 32], u64> = TableDefinition::new("node_mtime"); const T_NODE_MEDIA_PATHS: TableDefinition<([u8; 32], &str), ()> = @@ -71,7 +70,7 @@ impl Database { txn.open_table(T_NODE)?; txn.open_table(T_NODE_MTIME)?; txn.open_table(T_NODE_CHILDREN)?; - txn.open_table(T_NODE_EXTERNAL_ID)?; + txn.open_table(T_NODE_IDENTIFIER)?; txn.open_table(T_NODE_MEDIA_PATHS)?; txn.open_table(T_IMPORT_FILE_MTIME)?; txn.commit()?; @@ -94,10 +93,14 @@ impl Database { Ok(None) } } - pub fn get_node_external_id(&self, platform: &str, eid: &str) -> Result<Option<NodeID>> { + pub fn get_node_by_identifier( + &self, + ty: IdentifierType, + value: &str, + ) -> Result<Option<NodeID>> { let txn = self.inner.begin_read()?; - let t_node_external_id = txn.open_table(T_NODE_EXTERNAL_ID)?; - if let Some(id) = t_node_external_id.get((platform, eid))? { + let t_node_external_id = txn.open_table(T_NODE_IDENTIFIER)?; + if let Some(id) = t_node_external_id.get((ty as u8, value))? { Ok(Some(NodeID(id.value()))) } else { Ok(None) @@ -135,7 +138,7 @@ impl Database { let mut t_node = txn.open_table(T_NODE)?; let mut t_node_mtime = txn.open_table(T_NODE_MTIME)?; let mut t_node_children = txn.open_table(T_NODE_CHILDREN)?; - let mut t_node_external_id = txn.open_table(T_NODE_EXTERNAL_ID)?; + let mut t_node_external_id = txn.open_table(T_NODE_IDENTIFIER)?; let mut t_import_file_mtime = txn.open_table(T_IMPORT_FILE_MTIME)?; let mut t_node_media_paths = txn.open_table(T_NODE_MEDIA_PATHS)?; t_node.retain(|_, _| false)?; @@ -180,7 +183,7 @@ impl Database { let mut t_node = txn.open_table(T_NODE)?; let mut t_node_mtime = txn.open_table(T_NODE_MTIME)?; let mut t_node_children = txn.open_table(T_NODE_CHILDREN)?; - let mut t_node_external_id = txn.open_table(T_NODE_EXTERNAL_ID)?; + let mut t_node_external_id = txn.open_table(T_NODE_IDENTIFIER)?; let mut t_tag_node = txn.open_table(T_TAG_NODE)?; let mut node = t_node.get(id.0)?.map(|v| v.value().0).unwrap_or_default(); @@ -196,7 +199,7 @@ impl Database { t_node_children.insert((parent.0, id.0), ())?; } for (pl, eid) in &node.identifiers { - t_node_external_id.insert((pl.to_string().as_str(), eid.as_str()), id.0)?; + t_node_external_id.insert((*pl as u8, eid.as_str()), id.0)?; } for tag in &node.tags { t_tag_node.insert((tag.as_str(), id.0), ())?; diff --git a/import/src/lib.rs b/import/src/lib.rs index 3cbabdc..af13316 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -890,7 +890,10 @@ fn apply_trakt_tmdb( } for (group, people) in people.crew.iter() { for p in people { - people_map.entry(group.a()).or_default().push(p.a()) + people_map + .entry(group.as_credit_category()) + .or_default() + .push(p.a()) } } @@ -932,14 +935,7 @@ fn apply_trakt_tmdb( db.update_node_init(node, |node| { node.title = Some(data.title.clone()); node.credits.extend(people_map); - node.kind = match trakt_kind { - TraktKind::Movie => NodeKind::Movie, - TraktKind::Show => NodeKind::Show, - TraktKind::Season => NodeKind::Season, - TraktKind::Episode => NodeKind::Episode, - TraktKind::Person => NodeKind::Channel, - TraktKind::User => NodeKind::Channel, - }; + node.kind = trakt_kind.as_node_kind(); if let Some(overview) = &data.overview { node.description = Some(overview.clone()) } diff --git a/import/src/trakt.rs b/import/src/trakt.rs index 1640ca5..4a4beea 100644 --- a/import/src/trakt.rs +++ b/import/src/trakt.rs @@ -6,7 +6,7 @@ use crate::USER_AGENT; use anyhow::Context; use jellycache::{cache_memory, CacheKey}; -use jellycommon::{Appearance, CreditCategory, NodeID}; +use jellycommon::{Appearance, CreditCategory, NodeID, NodeKind}; use log::info; use reqwest::{ header::{HeaderMap, HeaderName, HeaderValue}, @@ -253,7 +253,7 @@ pub enum TraktPeopleGroup { CreatedBy, } impl TraktPeopleGroup { - pub fn a(self) -> CreditCategory { + pub fn as_credit_category(self) -> CreditCategory { match self { TraktPeopleGroup::Production => CreditCategory::Production, TraktPeopleGroup::Art => CreditCategory::Art, @@ -339,6 +339,19 @@ pub enum TraktKind { } impl TraktKind { + pub fn as_node_kind(self) -> NodeKind { + match self { + TraktKind::Movie => NodeKind::Movie, + TraktKind::Show => NodeKind::Show, + TraktKind::Season => NodeKind::Season, + TraktKind::Episode => NodeKind::Episode, + TraktKind::Person => NodeKind::Channel, + TraktKind::User => NodeKind::Channel, + } + } +} + +impl TraktKind { pub fn singular(self) -> &'static str { match self { TraktKind::Movie => "movie", diff --git a/locale/en.ini b/locale/en.ini index 27d1f4c..95ea2e4 100644 --- a/locale/en.ini +++ b/locale/en.ini @@ -186,15 +186,18 @@ settings.player_preference=Preferred Media Player settings.player_preference.changed=Media Player preference changed. settings.native_secret.changed=Native secret updated. -eid.isrc=ISRC -eid.barcode=Barcode -eid.musicbrainz.release=MusicBrainz Release ID -eid.musicbrainz.albumartist=MusicBrainz Album Artist ID -eid.musicbrainz.artist=MusicBrainz Artist ID -eid.musicbrainz.releasegroup=MusicBrainz Release Group ID -eid.musicbrainz.recording=MusicBrainz Recording ID -eid.acoustid.track=AcoustID Track ID -eid.youtube.channelname=YouTube Channel Handle -eid.youtube.channelname=YouTube Channel ID -eid.youtube.video=YouTube Video ID -eid.bandcamp=Bandcamp ID +id.acoustid_track=AcoustID Track +id.barcode=Barcode +id.imdb=IMDb +id.isrc=ISRC +id.musicbrainz_artist=MusicBrainz Artist +id.musicbrainz_recording=MusicBrainz Recording +id.musicbrainz_release_group=MusicBrainz Release Group +id.musicbrainz_release=MusicBrainz Release +id.omdb=OMDB +id.tmdb=TMDB +id.trakt=Trakt +id.tvdb=TVDB +id.youtube_channel_handle=YouTube Channel Handle +id.youtube_channel=ouTube Channel +id.youtube_video=YouTube Video diff --git a/logic/src/node.rs b/logic/src/node.rs index 3e527c8..94be1a0 100644 --- a/logic/src/node.rs +++ b/logic/src/node.rs @@ -6,7 +6,7 @@ use crate::{DATABASE, filter_sort::filter_and_sort_nodes, session::Session}; use anyhow::{Result, anyhow}; use jellycommon::{ - Node, NodeID, NodeKind, Visibility, + IdentifierType, Node, NodeID, NodeKind, Visibility, api::{ApiNodeResponse, NodeFilterSort, SortOrder, SortProperty}, user::{NodeUserData, WatchedState}, }; @@ -118,8 +118,12 @@ pub fn get_nodes_modified_since(_session: &Session, since: u64) -> Result<Vec<No Ok(nodes) } -pub fn get_node_by_eid(_session: &Session, platform: &str, eid: &str) -> Result<Option<NodeID>> { - DATABASE.get_node_external_id(platform, eid) +pub fn get_node_by_eid( + _session: &Session, + ty: IdentifierType, + value: &str, +) -> Result<Option<NodeID>> { + DATABASE.get_node_by_identifier(ty, value) } pub fn node_id_to_slug(_session: &Session, id: NodeID) -> Result<String> { Ok(DATABASE diff --git a/server/src/compat/youtube.rs b/server/src/compat/youtube.rs index 7126781..5bbcf77 100644 --- a/server/src/compat/youtube.rs +++ b/server/src/compat/youtube.rs @@ -5,7 +5,10 @@ */ use crate::{helper::A, ui::error::MyResult}; use anyhow::anyhow; -use jellycommon::routes::{u_node_slug, u_node_slug_player}; +use jellycommon::{ + routes::{u_node_slug, u_node_slug_player}, + IdentifierType, +}; use jellylogic::{ node::{get_node_by_eid, node_id_to_slug}, session::Session, @@ -17,7 +20,7 @@ pub fn r_youtube_watch(session: A<Session>, v: &str) -> MyResult<Redirect> { if v.len() != 11 { Err(anyhow!("video id length incorrect"))? } - let Some(id) = get_node_by_eid(&session.0, "youtube:video", v)? else { + let Some(id) = get_node_by_eid(&session.0, IdentifierType::YoutubeVideo, v)? else { Err(anyhow!("element not found"))? }; let slug = node_id_to_slug(&session.0, id)?; @@ -27,9 +30,9 @@ pub fn r_youtube_watch(session: A<Session>, v: &str) -> MyResult<Redirect> { #[get("/channel/<id>")] pub fn r_youtube_channel(session: A<Session>, id: &str) -> MyResult<Redirect> { let Some(id) = (if id.starts_with("UC") { - get_node_by_eid(&session.0, "youtube:channel", id)? + get_node_by_eid(&session.0, IdentifierType::YoutubeChannel, id)? } else if id.starts_with("@") { - get_node_by_eid(&session.0, "youtube:channel-name", id)? + get_node_by_eid(&session.0, IdentifierType::YoutubeChannelHandle, id)? } else { Err(anyhow!("unknown channel id format"))? }) else { @@ -44,7 +47,7 @@ pub fn r_youtube_embed(session: A<Session>, v: &str) -> MyResult<Redirect> { if v.len() != 11 { Err(anyhow!("video id length incorrect"))? } - let Some(id) = get_node_by_eid(&session.0, "youtube:video", v)? else { + let Some(id) = get_node_by_eid(&session.0, IdentifierType::YoutubeVideo, v)? else { Err(anyhow!("element not found"))? }; let slug = node_id_to_slug(&session.0, id)?; diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index 8366ece..6943b2b 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -61,7 +61,7 @@ pub fn transcode(key: CacheKey, quality: f32, speed: u8, width: usize) -> Result )) .context("avif encoding")?; - info!("transcode finished"); + debug!("transcode finished"); Ok(encoded.avif_file) }, ) diff --git a/ui/src/node_page.rs b/ui/src/node_page.rs index a72eb9a..d9d2cf8 100644 --- a/ui/src/node_page.rs +++ b/ui/src/node_page.rs @@ -155,7 +155,7 @@ markup::define! { table { @for (key, value) in &node.identifiers { tr { tr { - td { @trs(lang, &format!("eid.{}", key)) } + td { @trs(lang, &format!("id.{}", key)) } @if let Some(url) = external_id_url(*key, value) { td { a[href=url] { pre { @value } } } } else { |