|
|
|
@ -7,13 +7,24 @@ use walkdir::DirEntry;
|
|
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
mod mpvctl;
|
|
|
|
|
use crate::mpvctl::MpvCtl;
|
|
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
|
use rand::thread_rng;
|
|
|
|
|
use tokio::time::{sleep, Duration};
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
let mut args = env::args();
|
|
|
|
|
let mut args = env::args().peekable();
|
|
|
|
|
let _program = args.next().expect("argv[0] should be this program?");
|
|
|
|
|
let randomize: bool = match args.peek() {
|
|
|
|
|
Some(flag) if flag == "-r" => {
|
|
|
|
|
// Consume the flag
|
|
|
|
|
args.next().expect("We already know this arg exists");
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
let profile = args.next().expect("Must provide a profile");
|
|
|
|
|
|
|
|
|
|
let directories: Vec<String> = args.collect();
|
|
|
|
|
|
|
|
|
|
let mut files: Vec<DirEntry> = Vec::new();
|
|
|
|
@ -58,6 +69,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
|
|
|
|
|
let mut mpvctl = MpvCtl::connect("/tmp/recordwatchsocket").await?;
|
|
|
|
|
let mut end_file_listener = mpvctl.listen(&["end-file"])?;
|
|
|
|
|
if randomize {
|
|
|
|
|
files.shuffle(&mut thread_rng());
|
|
|
|
|
}
|
|
|
|
|
for f in files {
|
|
|
|
|
let canonicalized_path = f.path().canonicalize()?;
|
|
|
|
|
let already_watched_count: i64 = sqlx::query(r#"SELECT count(*) FROM watched WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"#)
|
|
|
|
|