aboutsummaryrefslogtreecommitdiff
path: root/import/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-22 15:16:58 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-22 15:17:23 +0100
commit80e545d06c4a0f0841d4b40e3aff479ef8d864f9 (patch)
tree9a555ea9404f45fb7ebf617ebdfb1f8248332e05 /import/src/lib.rs
parentc644f3b2f7b93cba2c903fa2a5e30ea80d86ef13 (diff)
downloadjellything-80e545d06c4a0f0841d4b40e3aff479ef8d864f9.tar
jellything-80e545d06c4a0f0841d4b40e3aff479ef8d864f9.tar.bz2
jellything-80e545d06c4a0f0841d4b40e3aff479ef8d864f9.tar.zst
rework import system pt. 5: local import and playback working again
Diffstat (limited to 'import/src/lib.rs')
-rw-r--r--import/src/lib.rs71
1 files changed, 46 insertions, 25 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs
index 6639789..e69e203 100644
--- a/import/src/lib.rs
+++ b/import/src/lib.rs
@@ -11,11 +11,15 @@ use anyhow::{anyhow, Context, Ok};
use async_recursion::async_recursion;
use futures::{stream::FuturesUnordered, StreamExt};
use jellybase::{
- cache::async_cache_file, database::Database, federation::Federation, AssetLocationExt, CONF,
+ cache::{async_cache_file, cache_file},
+ database::Database,
+ federation::Federation,
+ AssetLocationExt, CONF,
};
use jellyclient::Session;
use jellycommon::{
- AssetLocation, AssetRole, ImportOptions, ImportSource, Node, NodePrivate, NodePublic,
+ AssetLocation, AssetRole, ImportOptions, ImportSource, MediaInfo, Node, NodePrivate,
+ NodePublic, TrackSource,
};
use jellymatroska::read::EbmlReader;
use jellyremuxer::import::import_metadata;
@@ -24,12 +28,12 @@ use std::{
cmp::Ordering,
ffi::OsStr,
fs::File,
- io::BufReader,
+ io::{BufReader, Write},
os::unix::prelude::OsStrExt,
path::{Path, PathBuf},
sync::{Arc, LazyLock},
};
-use tokio::{sync::Semaphore, task::spawn_blocking};
+use tokio::{io::AsyncWriteExt, sync::Semaphore, task::spawn_blocking};
static IMPORT_SEM: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1));
@@ -179,45 +183,62 @@ async fn process_source(
};
match s {
ImportSource::Override(n) => insert_node(&id, n)?,
- ImportSource::Tmdb(_) => todo!(),
+ ImportSource::Tmdb { id } => {
+ todo!()
+ }
ImportSource::Media { location, .. } => {
// TODO use ignore options
let media_path = location.path();
let metadata = spawn_blocking(move || {
- let input = BufReader::new(File::open(&media_path).unwrap());
+ let input =
+ BufReader::new(File::open(&location.path()).context("opening media file")?);
let mut input = EbmlReader::new(input);
import_metadata(&mut input)
})
.await??;
- // if let Some(cover) = metadata.cover {
- // let pu = path.join(format!(
- // "cover.{}",
- // match mime.as_str() {
- // "image/webp" => "webp",
- // "image/jpeg" => "jpeg",
- // "image/png" => "png",
- // _ => {
- // warn!("unknown mime, just using webp");
- // "webp"
- // }
- // }
- // ));
- // if !pu.exists() {
- // let mut f = tokio::fs::File::create(&pu).await?;
- // f.write_all(&data).await?;
- // }
- // }
+ let poster = if let Some((filename, data)) = metadata.cover {
+ Some(
+ async_cache_file(
+ &[media_path.to_str().unwrap(), &filename],
+ |mut f| async move {
+ f.write_all(&data).await?;
+ Ok(())
+ },
+ )
+ .await?,
+ )
+ } else {
+ None
+ };
let node = Node {
public: NodePublic {
title: metadata.title,
description: metadata.description,
tagline: metadata.tagline,
+ media: Some(MediaInfo {
+ chapters: metadata.chapters,
+ duration: metadata.duration,
+ tracks: metadata.tracks,
+ }),
+ ..Default::default()
+ },
+ private: NodePrivate {
+ poster,
+ source: Some(
+ metadata
+ .track_sources
+ .into_iter()
+ .map(|mut ts| {
+ ts.path = media_path.to_owned();
+ TrackSource::Local(ts)
+ })
+ .collect(),
+ ),
..Default::default()
},
- private: NodePrivate::default(),
};
insert_node(&id, node)?;
}