Add support for a very basic randomize.

master
Tom Alexander 2 years ago
parent 24c4d95bb5
commit 81f73ac7a9
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -3,7 +3,9 @@ name = "record_watch"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "rw"
path = "src/main.rs"
[dependencies]
walkdir = "2.3.2"
@ -13,3 +15,5 @@ dirs = "4.0.0"
serde_json = "1.0.79"
serde = { version = "1.0.136", features= ["derive"] }
bytes = "1.1.0"
rand = "0.8.5"

@ -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 = ?)"#)

Loading…
Cancel
Save