diff options
author | metamuffin <metamuffin@disroot.org> | 2023-08-05 12:32:35 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-08-05 12:32:35 +0200 |
commit | ba3dedfaa6fee280761282f50fdee92b65cf0bfd (patch) | |
tree | 2798c163a2ff3fd9c11ca68dab9e6ca2f9a73cf9 | |
parent | abb8e4a10f0ac0a8c0a652efe8b0efc0da59c46e (diff) | |
download | jellything-ba3dedfaa6fee280761282f50fdee92b65cf0bfd.tar jellything-ba3dedfaa6fee280761282f50fdee92b65cf0bfd.tar.bz2 jellything-ba3dedfaa6fee280761282f50fdee92b65cf0bfd.tar.zst |
ability to override id from json and import
-rw-r--r-- | common/src/lib.rs | 1 | ||||
-rw-r--r-- | import/src/infojson.rs | 10 | ||||
-rw-r--r-- | import/src/main.rs | 23 | ||||
-rw-r--r-- | remuxer/src/import/mod.rs | 1 | ||||
-rw-r--r-- | server/src/import.rs | 18 | ||||
-rw-r--r-- | server/src/routes/ui/account/admin.rs | 7 |
6 files changed, 42 insertions, 18 deletions
diff --git a/common/src/lib.rs b/common/src/lib.rs index be0528f..7c44eda 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -19,6 +19,7 @@ pub struct Node { #[rustfmt::skip] #[derive(Debug, Clone, Deserialize, Serialize)] pub struct NodePrivate { + #[serde(default)] pub id: Option<String>, #[serde(default)] pub import: Option<RemoteImportOptions>, #[serde(default)] pub poster: Option<AssetLocation>, #[serde(default)] pub backdrop: Option<AssetLocation>, diff --git a/import/src/infojson.rs b/import/src/infojson.rs index 2f5eeb7..ca02551 100644 --- a/import/src/infojson.rs +++ b/import/src/infojson.rs @@ -16,7 +16,7 @@ pub struct YVideo { pub thumbnail: String, pub description: String, pub channel_id: String, - pub duration: f64, + pub duration: Option<f64>, pub view_count: usize, pub average_rating: Option<String>, pub age_limit: usize, @@ -28,8 +28,8 @@ pub struct YVideo { pub comment_count: Option<usize>, pub chapters: Option<Vec<YChapter>>, pub heatmap: Option<Vec<YHeatmapSample>>, - pub like_count: usize, - pub channel: String, + pub like_count: Option<usize>, + pub channel: Option<String>, pub channel_follower_count: usize, pub channel_is_verified: Option<bool>, pub uploader: String, @@ -93,8 +93,8 @@ pub struct YFormat { #[derive(Debug, Serialize, Deserialize)] pub struct YFragment { - pub url: String, - pub duration: f64, + pub url: Option<String>, + pub duration: Option<f64>, } #[derive(Debug, Serialize, Deserialize)] diff --git a/import/src/main.rs b/import/src/main.rs index b55b645..2d66221 100644 --- a/import/src/main.rs +++ b/import/src/main.rs @@ -41,6 +41,8 @@ enum Action { #[arg(short = 'T', long)] tmdb_id: Option<String>, #[arg(long)] + ident_prefix: Option<String>, + #[arg(long)] copy: bool, #[arg(long)] r#move: bool, @@ -67,6 +69,7 @@ fn main() -> anyhow::Result<()> { tmdb_search, input, series, + ident_prefix, copy, video, r#move, @@ -151,7 +154,17 @@ fn main() -> anyhow::Result<()> { .map(|d| d.title.clone().or(d.name.clone())) .flatten()) .unwrap(); - let ident = make_ident(&title); + + let ident = format!( + "{}{}", + ident_prefix.unwrap_or(String::new()), + make_ident( + &infojson + .as_ref() + .map(|i| i.id.clone()) + .unwrap_or(title.clone()) + ), + ); let path = path.join(&ident); let source_path = input.as_ref().map(|_| path.join(format!("source.mkv"))); @@ -228,11 +241,13 @@ fn main() -> anyhow::Result<()> { ratings.extend( infojson .as_ref() - .map(|i| Rating::YoutubeLikes(i.like_count)), + .map(|i| i.like_count.map(Rating::YoutubeLikes)) + .flatten(), ); let node = Node { private: NodePrivate { + id: Some(ident.clone()), import: None, backdrop: backdrop.clone().map(AssetLocation::Library), poster: poster.clone().map(AssetLocation::Library), @@ -292,9 +307,9 @@ fn main() -> anyhow::Result<()> { seek_index::write_all(&source_path)?; } let f = File::create(path.join(if series { - "directory.json".to_string() + "directory.json" } else { - format!("{ident}.jelly") + "item.jelly" }))?; serde_json::to_writer_pretty(f, &node)?; } diff --git a/remuxer/src/import/mod.rs b/remuxer/src/import/mod.rs index ade1fe0..5f76623 100644 --- a/remuxer/src/import/mod.rs +++ b/remuxer/src/import/mod.rs @@ -269,6 +269,7 @@ fn import_read_segment(segment: &mut Unflatten) -> Result<MatroskaMetadata> { codec_private, }) } + MatroskaTag::Crc32(_) => {} _ => warn!("(rst) tag ignored: {item:?}"), } } diff --git a/server/src/import.rs b/server/src/import.rs index 3b45f14..d72690c 100644 --- a/server/src/import.rs +++ b/server/src/import.rs @@ -100,14 +100,15 @@ pub async fn import_path( info!("loading {path:?}"); let datafile = File::open(path.clone()).context("cant load metadata")?; let mut data: Node = serde_json::from_reader(datafile).context("invalid metadata")?; - let identifier = path - .file_name() - .unwrap() - .to_str() - .unwrap() - .strip_suffix(".jelly") - .unwrap() - .to_string(); + let identifier = data.private.id.clone().unwrap_or_else(|| { + path.file_name() + .unwrap() + .to_str() + .unwrap() + .strip_suffix(".jelly") + .unwrap() + .to_string() + }); if let Some(io) = data.private.import.take() { let session = fed @@ -152,6 +153,7 @@ async fn import_remote( backdrop: Some(AssetLocation::Cache(backdrop)), poster: Some(AssetLocation::Cache(poster)), import: None, + id: None, source: Some(MediaSource::Remote { host: opts.host.clone(), remote_id: opts.id.clone(), diff --git a/server/src/routes/ui/account/admin.rs b/server/src/routes/ui/account/admin.rs index d0ad433..f1520b7 100644 --- a/server/src/routes/ui/account/admin.rs +++ b/server/src/routes/ui/account/admin.rs @@ -17,6 +17,7 @@ use crate::{ use anyhow::anyhow; use rand::Rng; use rocket::{form::Form, get, post, FromForm, State}; +use std::time::Instant; #[get("/account/admin/dashboard")] pub fn r_account_admin_dashboard( @@ -141,9 +142,13 @@ pub async fn r_account_admin_import( if !session.user.admin { Err(anyhow!("you not admin"))? } + let t = Instant::now(); let r = import(&database, &federation).await; admin_dashboard( &database, - Some(r.map_err(|e| e.into()).map(|_| "Import successful".into())), + Some( + r.map_err(|e| e.into()) + .map(|_| format!("Import successful; took {:?}", t.elapsed())), + ), ) } |