c219e4d20a2d66e747cabb81f7313392e107284c — Robbie Straw 7 years ago bcaf50b
this utility creates video thumbnails for any file tagged with `THUMB`.
2 files changed, 86 insertions(+), 0 deletions(-)

M Cargo.toml
A src/bin/aqua_thumbfix.rs
M Cargo.toml => Cargo.toml +5 -0
@@ 14,6 14,11 @@ path = "src/bin/aqua_find.rs"
doc = false

name = "aqua-thumbfix"
path = "src/bin/aqua_thumbfix.rs"
doc = false

name = "aqua-watch"
path = "src/bin/aqua_watch.rs"
doc = false

A src/bin/aqua_thumbfix.rs => src/bin/aqua_thumbfix.rs +81 -0
@@ 0,0 1,81 @@
#[macro_use] extern crate log;

extern crate aqua;
extern crate clap;
extern crate diesel;
extern crate dotenv;
extern crate env_logger;
extern crate image;

use aqua::models::{Entry, EntryTag, Tag, NewEntry};
use aqua::schema;
use aqua::util::processing::{ProcessingError, ProcessingResult};
use clap::{Arg, App};
use diesel::prelude::*;
use diesel::pg::PgConnection;
use dotenv::dotenv;
use std::{env, fs};
use std::error::Error;
use std::fs::OpenOptions;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::time::Duration;

fn main() {
    dotenv().expect("must provide .env file, see README (TODO: haha jk)");
    env_logger::init().expect("could not initialize console logging");

    // read command line arguments
    let matches = App::new("aqua-watch")
        .author("himechi <hime@localhost>")
        .about("Watches a directory for new files and moves them to the `aqua` content store.")
             .help("Determines the input directory to be watched.")

    let content_store = matches.value_of("CONTENT_PATH").unwrap();

fn establish_connection() -> ProcessingResult<PgConnection> {
    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL not set in `.env` file !!!");


fn process_entries(content_store: &str) -> ProcessingResult<()> {
    let conn = establish_connection()?;
    let missing_thumb_tag = schema::tags::table

    let entries = schema::entries::table
        .load::<(Entry, EntryTag)>(&conn)?;

    info!("found {} entries in need of thumbs", entries.len());
    for &(ref entry, ref mapping) in &entries {
        let ext = entry.mime.as_ref()
            .splitn(2, "/")

        let path = PathBuf::new()
            .join(format!("f{}", &entry.hash[0..2]))
            .join(format!("{}.{}", &entry.hash[..], &ext));

        info!("path is => {:?}", path);
        aqua::util::processing::thumb_video(content_store, &entry.hash, &path)?;