Save watched right after something is watched, and use match
This commit is contained in:
parent
d580ca8956
commit
35bb1edfc3
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -123,16 +123,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctrlc"
|
||||
version = "3.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1631ca6e3c59112501a9d87fd86f21591ff77acd31331e8a73f8d80a65bbdd71"
|
||||
dependencies = [
|
||||
"nix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "directories"
|
||||
version = "4.0.1"
|
||||
@ -470,7 +460,6 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"colored",
|
||||
"ctrlc",
|
||||
"directories",
|
||||
"futures-util",
|
||||
"indicatif",
|
||||
@ -576,18 +565,6 @@ dependencies = [
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.15.0"
|
||||
@ -959,12 +936,6 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
|
@ -8,7 +8,6 @@ edition = "2021"
|
||||
[dependencies]
|
||||
bytes = "1.3.0"
|
||||
colored = "2.0.0"
|
||||
ctrlc = "3.2.4"
|
||||
directories = "4.0.1"
|
||||
futures-util = "0.3.25"
|
||||
indicatif = { version = "0.17.3", features = ["tokio"] }
|
||||
|
@ -9,6 +9,5 @@ You will need to install mpv, and have it in your path, otherwise it wont work
|
||||
|
||||
## Left to do
|
||||
|
||||
- Implement the ctrlc handler so that the program saves watched links before exiting.
|
||||
- Create a GUI
|
||||
- Would be nice to bundle mpv in some form
|
||||
|
40
src/main.rs
40
src/main.rs
@ -29,14 +29,18 @@ async fn main() {
|
||||
let search = readline.input("Search by name [ r/q/f ]: ").to_lowercase();
|
||||
let search = search.trim();
|
||||
|
||||
// If they want to quit, let them-
|
||||
if search == "q" {
|
||||
break;
|
||||
} else if search == "r" {
|
||||
// Special commands
|
||||
match search {
|
||||
// Quit
|
||||
"q" => break,
|
||||
// Refresh playlist
|
||||
"r" => {
|
||||
search_result = None;
|
||||
refresh(&parser).await;
|
||||
continue;
|
||||
} else if search == "f" {
|
||||
}
|
||||
// Toggle fullscreen for mpv
|
||||
"f" => {
|
||||
mpv_fs = !mpv_fs;
|
||||
println!(
|
||||
"Toggled mpv to {}launch in fullscreen",
|
||||
@ -44,7 +48,8 @@ async fn main() {
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
search_result = Some(Rc::new(parser.find(search)));
|
||||
|
||||
if search_result.as_ref().unwrap().len() == 0 {
|
||||
@ -64,17 +69,23 @@ async fn main() {
|
||||
let user_wish = user_wish.trim();
|
||||
|
||||
// If they want to quit, let them-
|
||||
if user_wish == "q" {
|
||||
break;
|
||||
} else if user_wish == "s" {
|
||||
match user_wish {
|
||||
// Quit
|
||||
"q" => break,
|
||||
// Go inte search-mode
|
||||
"s" => {
|
||||
search_result = None;
|
||||
continue;
|
||||
} else if user_wish == "r" {
|
||||
}
|
||||
// Refresh playlist
|
||||
"r" => {
|
||||
println!("Refreshing local m3u8-file");
|
||||
search_result = None;
|
||||
refresh(&parser).await;
|
||||
continue;
|
||||
} else if user_wish == "d" {
|
||||
}
|
||||
// Downloadmode
|
||||
"d" => {
|
||||
let selection = readline
|
||||
.input("Download all or select in comma separated [a | 1,2,3,4]: ")
|
||||
.to_lowercase();
|
||||
@ -107,18 +118,19 @@ async fn main() {
|
||||
};
|
||||
download_m3u8(to_download).await;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let choosen = user_wish.parse::<usize>();
|
||||
match choosen {
|
||||
Ok(k) => {
|
||||
let search_result = search_result.as_ref().unwrap().clone();
|
||||
stream(&(search_result[k - 1]), mpv_fs)
|
||||
stream(&(search_result[k - 1]), mpv_fs);
|
||||
parser.save_watched();
|
||||
}
|
||||
Err(e) => println!("Have to be a valid number! {:?}", e),
|
||||
}
|
||||
}
|
||||
|
||||
parser.save_watched();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -90,13 +90,8 @@ impl Parser {
|
||||
|
||||
let _ = fs::create_dir_all(&*self.watched_name.parent().unwrap());
|
||||
|
||||
match fs::write(&*self.watched_name, watched_items.join("\n")) {
|
||||
Ok(_) => {
|
||||
println!("Saved watched")
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to write downloaded m3u8file {:?}", e);
|
||||
}
|
||||
if let Err(e) = fs::write(&*self.watched_name, watched_items.join("\n")) {
|
||||
eprintln!("Failed to write watched links {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user