This commit is contained in:
JMARyA 2024-10-07 09:24:54 +02:00
parent 1979fc246e
commit 224bdf77ab
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
9 changed files with 207 additions and 367 deletions

View file

@ -4,28 +4,28 @@ use crate::library::Library;
#[get("/video/raw?<v>")]
pub async fn video_file(v: &str, library: &State<Library>) -> Option<NamedFile> {
let (_, mut video) = if let Some((channel, video)) = library.get_video_by_hash(v).await {
(channel, video)
} else {
library.get_video_by_youtube_id(v).await.unwrap()
};
let video = if let Some(video) = library.get_video_by_id(v).await {
video
} else {
library.get_video_by_youtube_id(v).await.unwrap()
};
NamedFile::open(video.path().await?).await.ok()
NamedFile::open(video.path).await.ok()
}
#[get("/video/thumbnail?<v>")]
pub async fn video_thumbnail(v: &str, library: &State<Library>) -> Option<NamedFile> {
let (_, mut video) = if let Some((channel, video)) = library.get_video_by_hash(v).await {
(channel, video)
} else {
library.get_video_by_youtube_id(v).await.unwrap()
};
let video = if let Some(video) = library.get_video_by_id(v).await {
video
} else {
library.get_video_by_youtube_id(v).await.unwrap()
};
let path = video.path().await.unwrap();
let parent = path.parent().unwrap();
let thumbnail_path = path.file_stem().unwrap().to_str().unwrap();
let thumbnail_path = parent.join(thumbnail_path);
let thumbnail_path = thumbnail_path.to_str().unwrap();
let path = std::path::Path::new(&video.path);
let parent = path.parent().unwrap();
let thumbnail_path = path.file_stem().unwrap().to_str().unwrap();
let thumbnail_path = parent.join(thumbnail_path);
let thumbnail_path = thumbnail_path.to_str().unwrap();
NamedFile::open(format!("{thumbnail_path}.jpg")).await.ok()
NamedFile::open(format!("{thumbnail_path}.jpg")).await.ok()
}