aboutsummaryrefslogtreecommitdiff
path: root/import/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-30 16:45:06 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-30 16:45:06 +0100
commitbfc5552a8eba07897c2ed626b49c085d97fdfa0d (patch)
tree2eaff957b4a744e55710502c81f7ce38a3f86294 /import/src/lib.rs
parent32a05b5ec244d4d8143993b082f8d3f86a0a4ecd (diff)
downloadjellything-bfc5552a8eba07897c2ed626b49c085d97fdfa0d.tar
jellything-bfc5552a8eba07897c2ed626b49c085d97fdfa0d.tar.bz2
jellything-bfc5552a8eba07897c2ed626b49c085d97fdfa0d.tar.zst
external ids and urls
Diffstat (limited to 'import/src/lib.rs')
-rw-r--r--import/src/lib.rs23
1 files changed, 10 insertions, 13 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,