Merge branch 'master' of gitlab.com:shockrah/clippable
This commit is contained in:
commit
64d3253b90
@ -1,8 +1,9 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fs::DirEntry;
|
use std::fs::DirEntry;
|
||||||
|
use std::path::Path;
|
||||||
use std::io;
|
use std::io;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use crate::common::get_clips_dir;
|
use crate::common::{get_clips_dir, thumbs_dir};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Category {
|
pub struct Category {
|
||||||
@ -34,6 +35,24 @@ pub fn get_category_dirs(path: &str) -> std::io::Result<Vec<DirEntry>> {
|
|||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_category_thumbnail(category: &str) -> std::io::Result<String> {
|
||||||
|
let pathname = format!("{}{}", thumbs_dir(), &category);
|
||||||
|
let path = Path::new(&pathname);
|
||||||
|
println!("Path to use {:?}", path);
|
||||||
|
// Assume its a directory
|
||||||
|
let mut ret = "/static/cantfindshit.jpg".to_string();
|
||||||
|
for ent in path.read_dir()? {
|
||||||
|
if let Ok(ent) = ent {
|
||||||
|
let name = ent.file_name().into_string().unwrap();
|
||||||
|
if name == "category-thumbnail.jpg" {
|
||||||
|
ret = format!("/thumbnail/{}/{}", category, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/categories")]
|
#[get("/categories")]
|
||||||
pub fn list() -> Json<Vec<Category>> {
|
pub fn list() -> Json<Vec<Category>> {
|
||||||
// WARN: misconfigured servers are just going to get shafted and serve up
|
// WARN: misconfigured servers are just going to get shafted and serve up
|
||||||
@ -46,7 +65,10 @@ pub fn list() -> Json<Vec<Category>> {
|
|||||||
// That way we can do this blindly without 9999 allocs
|
// That way we can do this blindly without 9999 allocs
|
||||||
for d in dirs {
|
for d in dirs {
|
||||||
let name = d.file_name().to_string_lossy().to_string();
|
let name = d.file_name().to_string_lossy().to_string();
|
||||||
let thumbnail = format!("/thumbnail/{}/category-thumbnail.jpg", name);
|
let thumbnail = match get_category_thumbnail(&name) {
|
||||||
|
Ok(s) => s,
|
||||||
|
_ => "/static/cantfindshit.jpg".to_string()
|
||||||
|
};
|
||||||
cats.push(Category {name, thumbnail});
|
cats.push(Category {name, thumbnail});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,15 @@ pub async fn get(file: PathBuf) -> Option<NamedFile> {
|
|||||||
if file_path.is_file() {
|
if file_path.is_file() {
|
||||||
return match file_path.extension() {
|
return match file_path.extension() {
|
||||||
Some(ext) => {
|
Some(ext) => {
|
||||||
if ext == "jpg" || ext == "png" || ext == "jpeg" {
|
match ext == "jpg" {
|
||||||
NamedFile::open(file_path).await.ok()
|
true => NamedFile::open(file_path).await.ok(),
|
||||||
} else {
|
false => None
|
||||||
println!("bad extension");
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let path = Path::new("static/cantfindshit.gif");
|
let path = Path::new("static/cantfindshit.jpg");
|
||||||
return NamedFile::open(path).await.ok();
|
return NamedFile::open(path).await.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ pub fn list(cat: PathBuf) -> Option<Json<Vec<VideoPreview>>> {
|
|||||||
let name = name.to_string_lossy();
|
let name = name.to_string_lossy();
|
||||||
|
|
||||||
let cat = cat.to_string_lossy();
|
let cat = cat.to_string_lossy();
|
||||||
let thumbnail = format!("/thumbnail/{}/{}", cat, name);
|
let thumbnail = format!("/thumbnail/{}/{}.jpg", cat, name);
|
||||||
|
|
||||||
let item = VideoPreview {
|
let item = VideoPreview {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.8 MiB |
3
api/static/cantfindshit.jpg
Normal file
3
api/static/cantfindshit.jpg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:bc7637a1b3f7e75322e3dddb3499931dc9cd57804afbf46c7941e6bc5211d03c
|
||||||
|
size 21076
|
50
scripts/tn-tree-clone.sh
Normal file
50
scripts/tn-tree-clone.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# This script basically clones the tree structure of the videos directory
|
||||||
|
# At the same time it will generate thumbnails for each video
|
||||||
|
|
||||||
|
vids="$1" # root dir for videos that we're going to clone
|
||||||
|
thumbs="$2" # root dir for thumbnails we'll create
|
||||||
|
|
||||||
|
_show_usage() {
|
||||||
|
cat << EOF
|
||||||
|
Generate thumbnails for a whole tree of clips
|
||||||
|
Usage:
|
||||||
|
$0 CLIPS_ROOT_PATH TARGET_ROOT
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z "$vids" ];then
|
||||||
|
echo 'Missing root video directory!'
|
||||||
|
_show_usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$thumbs" ];then
|
||||||
|
echo 'Missing target thumbnails directory'
|
||||||
|
_show_usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo Cloning directory structure
|
||||||
|
pushd "$vids" > /dev/null
|
||||||
|
find . -type d | while read f; do
|
||||||
|
mkdir -p "$thumbs/$f"
|
||||||
|
done
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
echo Generating thumbnails
|
||||||
|
thumbs="`realpath "$thumbs"`"
|
||||||
|
pushd "$vids" > /dev/null
|
||||||
|
find . -type f -name '*.mkv' -o -name '*.mp4' -o -name '*.webm' | while read f; do
|
||||||
|
if="`realpath "${vids}/$f"`"
|
||||||
|
of="`realpath "${thumbs}/$f"`"
|
||||||
|
# Make sure only errors pop up here
|
||||||
|
ffmpeg -hide_banner -loglevel error \
|
||||||
|
-y -ss 00:00:01 -i "$if" -frames:v 1 "$of.jpg" > /dev/null
|
||||||
|
ffmpeg -hide_banner -loglevel error \
|
||||||
|
-y -i "$of.jpg" -vf scale=640:-1 "$of.jpg" > /dev/null
|
||||||
|
echo $of
|
||||||
|
done
|
||||||
|
popd > /dev/null
|
Loading…
Reference in New Issue
Block a user