diff options
Diffstat (limited to 'import/src')
-rw-r--r-- | import/src/lib.rs | 23 | ||||
-rw-r--r-- | import/src/matroska.rs | 14 |
2 files changed, 21 insertions, 16 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index a22551e..c841294 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -10,13 +10,12 @@ use jellycommon::{ Chapter, LocalTrack, MediaInfo, Node, NodeID, NodeKind, Rating, SourceTrack, SourceTrackKind, TrackSource, }; -use log::info; use matroska::matroska_metadata; use rayon::iter::{ParallelDrainRange, ParallelIterator}; use std::{ collections::HashMap, fs::File, - io::{BufReader, Read}, + io::BufReader, mem::swap, path::{Path, PathBuf}, sync::LazyLock, @@ -170,9 +169,10 @@ fn import_file(db: &Database, path: &Path) -> Result<()> { .to_owned(), ); node.external_ids - .insert("youtube".to_string(), data.channel_id); + .insert("youtube:channel".to_string(), data.channel_id); if let Some(uid) = data.uploader_id { - node.external_ids.insert("youtube".to_string(), uid); + node.external_ids + .insert("youtube:channel-name".to_string(), uid); } node.description = Some(data.description); if let Some(followers) = data.channel_follower_count { @@ -185,19 +185,15 @@ fn import_file(db: &Database, path: &Path) -> Result<()> { _ => (), } - let mut magic = [0; 4]; - File::open(path)?.read_exact(&mut magic).ok(); - if matches!(magic, [0x1A, 0x45, 0xDF, 0xA3]) { - import_media_file(db, path, parent).context("media file")?; - } + import_media_file(db, path, parent).context("media file")?; Ok(()) } fn import_media_file(db: &Database, path: &Path, parent: NodeID) -> Result<()> { - info!("reading media file {path:?}"); - - let m = (*matroska_metadata(path)?).to_owned(); + let Some(m) = (*matroska_metadata(path)?).to_owned() else { + return Ok(()); + }; let info = m.info.ok_or(anyhow!("no info"))?; let tracks = m.tracks.ok_or(anyhow!("no tracks"))?; @@ -251,7 +247,8 @@ fn import_media_file(db: &Database, path: &Path, parent: NodeID) -> Result<()> { node.release_date = Some(infojson::parse_upload_date(date).context("parsing upload date")?); } - node.external_ids.insert("youtube".to_string(), infojson.id); + node.external_ids + .insert("youtube:video".to_string(), infojson.id); node.ratings.insert( Rating::YoutubeViews, infojson.view_count.unwrap_or_default() as f64, diff --git a/import/src/matroska.rs b/import/src/matroska.rs index bb8d927..6a33420 100644 --- a/import/src/matroska.rs +++ b/import/src/matroska.rs @@ -16,6 +16,7 @@ use jellybase::{ cache::{cache_file, cache_memory}, }; use jellycommon::Asset; +use log::info; use std::{ fs::File, io::{BufReader, ErrorKind, Read, Write}, @@ -32,8 +33,15 @@ pub(crate) struct MatroskaMetadata { pub tags: Option<Tags>, pub infojson: Option<YVideo>, } -pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<MatroskaMetadata>> { +pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<Option<MatroskaMetadata>>> { cache_memory(&["mkmeta-v1", path.to_string_lossy().as_ref()], || { + let mut magic = [0; 4]; + File::open(path)?.read_exact(&mut magic).ok(); + if !matches!(magic, [0x1A, 0x45, 0xDF, 0xA3]) { + return Ok(None); + } + + info!("reading media file {path:?}"); let mut file = BufReader::new(File::open(path)?); let mut file = file.by_ref().take(u64::MAX); @@ -100,13 +108,13 @@ pub(crate) fn matroska_metadata(path: &Path) -> Result<Arc<MatroskaMetadata>> { } } } - Ok(MatroskaMetadata { + Ok(Some(MatroskaMetadata { chapters, cover, info, infojson, tags, tracks, - }) + })) }) } |