diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-24 18:11:23 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-24 18:47:29 +0100 |
commit | 7323709537c6ff14136cd79fb07606cd79391758 (patch) | |
tree | 3d817d449d4c0a821b9b5073c8acf826c6ccfda1 /transcoder | |
parent | cbb2e163abfefd8ed61c41a096d5d6c27b4721b4 (diff) | |
download | jellything-7323709537c6ff14136cd79fb07606cd79391758.tar jellything-7323709537c6ff14136cd79fb07606cd79391758.tar.bz2 jellything-7323709537c6ff14136cd79fb07606cd79391758.tar.zst |
refactor asset system pt. 1
Diffstat (limited to 'transcoder')
-rw-r--r-- | transcoder/src/image.rs | 18 | ||||
-rw-r--r-- | transcoder/src/snippet.rs | 6 | ||||
-rw-r--r-- | transcoder/src/thumbnail.rs | 5 |
3 files changed, 12 insertions, 17 deletions
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs index 5df21a9..20f7e0c 100644 --- a/transcoder/src/image.rs +++ b/transcoder/src/image.rs @@ -6,37 +6,33 @@ use crate::LOCAL_IMAGE_TRANSCODING_TASKS; use anyhow::Context; use image::imageops::FilterType; -use jellybase::{cache::async_cache_file, AssetLocationExt}; -use jellycommon::AssetLocation; +use jellybase::cache::{async_cache_file, CachePath}; use log::{debug, info}; use rgb::FromSlice; use std::{ fs::File, io::{BufReader, Read, Seek, SeekFrom}, + path::PathBuf, }; use tokio::io::AsyncWriteExt; pub async fn transcode( - asset: AssetLocation, + path: PathBuf, quality: f32, speed: u8, width: usize, -) -> anyhow::Result<AssetLocation> { - let original_path = asset.path(); - let asset = asset.clone(); +) -> anyhow::Result<CachePath> { Ok(async_cache_file( &[ "image-tc", - original_path.as_os_str().to_str().unwrap(), + path.clone().as_os_str().to_str().unwrap(), &format!("{width} {quality} {speed}"), ], move |mut output| async move { let _permit = LOCAL_IMAGE_TRANSCODING_TASKS.acquire().await?; - info!("encoding {asset:?} (speed={speed}, quality={quality}, width={width})"); + info!("encoding {path:?} (speed={speed}, quality={quality}, width={width})"); let encoded = tokio::task::spawn_blocking(move || { - let original_path = asset.path(); - let mut file = - BufReader::new(File::open(&original_path).context("opening source")?); + let mut file = BufReader::new(File::open(&path).context("opening source")?); // TODO: use better image library that supports AVIF let is_avif = { diff --git a/transcoder/src/snippet.rs b/transcoder/src/snippet.rs index 5da1ae7..3632919 100644 --- a/transcoder/src/snippet.rs +++ b/transcoder/src/snippet.rs @@ -5,8 +5,8 @@ */ use crate::LOCAL_VIDEO_TRANSCODING_TASKS; -use jellybase::cache::async_cache_file; -use jellycommon::{jhls::EncodingProfile, AssetLocation}; +use jellybase::cache::{async_cache_file, CachePath}; +use jellycommon::jhls::EncodingProfile; use log::{debug, info}; use std::process::Stdio; use tokio::{ @@ -21,7 +21,7 @@ pub async fn transcode( key: &str, enc: &EncodingProfile, input: impl FnOnce(ChildStdin), -) -> anyhow::Result<AssetLocation> { +) -> anyhow::Result<CachePath> { Ok(async_cache_file( &["snip-tc", key, &format!("{enc:?}")], move |mut output| async move { diff --git a/transcoder/src/thumbnail.rs b/transcoder/src/thumbnail.rs index 5baf888..9661fd0 100644 --- a/transcoder/src/thumbnail.rs +++ b/transcoder/src/thumbnail.rs @@ -1,11 +1,10 @@ use crate::LOCAL_IMAGE_TRANSCODING_TASKS; -use jellybase::cache::async_cache_file; -use jellycommon::AssetLocation; +use jellybase::cache::{async_cache_file, CachePath}; use log::info; use std::{path::Path, process::Stdio}; use tokio::{io::copy, process::Command}; -pub async fn create_thumbnail(path: &Path, time: f64) -> anyhow::Result<AssetLocation> { +pub async fn create_thumbnail(path: &Path, time: f64) -> anyhow::Result<CachePath> { Ok(async_cache_file( &["thumb", path.to_str().unwrap(), &format!("{time}")], move |mut output| async move { |