Save watched right after something is watched, and use match

This commit is contained in:
Love 2023-02-27 16:24:16 +01:00
parent d580ca8956
commit 35bb1edfc3
5 changed files with 69 additions and 93 deletions

29
Cargo.lock generated
View File

@ -123,16 +123,6 @@ dependencies = [
"cfg-if", "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]] [[package]]
name = "directories" name = "directories"
version = "4.0.1" version = "4.0.1"
@ -470,7 +460,6 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bytes", "bytes",
"colored", "colored",
"ctrlc",
"directories", "directories",
"futures-util", "futures-util",
"indicatif", "indicatif",
@ -576,18 +565,6 @@ dependencies = [
"tempfile", "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]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.15.0" version = "1.15.0"
@ -959,12 +936,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.107" version = "1.0.107"

View File

@ -8,7 +8,6 @@ edition = "2021"
[dependencies] [dependencies]
bytes = "1.3.0" bytes = "1.3.0"
colored = "2.0.0" colored = "2.0.0"
ctrlc = "3.2.4"
directories = "4.0.1" directories = "4.0.1"
futures-util = "0.3.25" futures-util = "0.3.25"
indicatif = { version = "0.17.3", features = ["tokio"] } indicatif = { version = "0.17.3", features = ["tokio"] }

View File

@ -9,6 +9,5 @@ You will need to install mpv, and have it in your path, otherwise it wont work
## Left to do ## Left to do
- Implement the ctrlc handler so that the program saves watched links before exiting.
- Create a GUI - Create a GUI
- Would be nice to bundle mpv in some form - Would be nice to bundle mpv in some form

View File

@ -29,14 +29,18 @@ async fn main() {
let search = readline.input("Search by name [ r/q/f ]: ").to_lowercase(); let search = readline.input("Search by name [ r/q/f ]: ").to_lowercase();
let search = search.trim(); let search = search.trim();
// If they want to quit, let them- // Special commands
if search == "q" { match search {
break; // Quit
} else if search == "r" { "q" => break,
// Refresh playlist
"r" => {
search_result = None; search_result = None;
refresh(&parser).await; refresh(&parser).await;
continue; continue;
} else if search == "f" { }
// Toggle fullscreen for mpv
"f" => {
mpv_fs = !mpv_fs; mpv_fs = !mpv_fs;
println!( println!(
"Toggled mpv to {}launch in fullscreen", "Toggled mpv to {}launch in fullscreen",
@ -44,7 +48,8 @@ async fn main() {
); );
continue; continue;
} }
_ => {}
}
search_result = Some(Rc::new(parser.find(search))); search_result = Some(Rc::new(parser.find(search)));
if search_result.as_ref().unwrap().len() == 0 { if search_result.as_ref().unwrap().len() == 0 {
@ -64,17 +69,23 @@ async fn main() {
let user_wish = user_wish.trim(); let user_wish = user_wish.trim();
// If they want to quit, let them- // If they want to quit, let them-
if user_wish == "q" { match user_wish {
break; // Quit
} else if user_wish == "s" { "q" => break,
// Go inte search-mode
"s" => {
search_result = None; search_result = None;
continue; continue;
} else if user_wish == "r" { }
// Refresh playlist
"r" => {
println!("Refreshing local m3u8-file"); println!("Refreshing local m3u8-file");
search_result = None; search_result = None;
refresh(&parser).await; refresh(&parser).await;
continue; continue;
} else if user_wish == "d" { }
// Downloadmode
"d" => {
let selection = readline let selection = readline
.input("Download all or select in comma separated [a | 1,2,3,4]: ") .input("Download all or select in comma separated [a | 1,2,3,4]: ")
.to_lowercase(); .to_lowercase();
@ -107,18 +118,19 @@ async fn main() {
}; };
download_m3u8(to_download).await; download_m3u8(to_download).await;
} }
_ => {}
}
let choosen = user_wish.parse::<usize>(); let choosen = user_wish.parse::<usize>();
match choosen { match choosen {
Ok(k) => { Ok(k) => {
let search_result = search_result.as_ref().unwrap().clone(); 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), Err(e) => println!("Have to be a valid number! {:?}", e),
} }
} }
parser.save_watched();
} }
/* /*

View File

@ -90,13 +90,8 @@ impl Parser {
let _ = fs::create_dir_all(&*self.watched_name.parent().unwrap()); let _ = fs::create_dir_all(&*self.watched_name.parent().unwrap());
match fs::write(&*self.watched_name, watched_items.join("\n")) { if let Err(e) = fs::write(&*self.watched_name, watched_items.join("\n")) {
Ok(_) => { eprintln!("Failed to write watched links {:?}", e);
println!("Saved watched")
}
Err(e) => {
eprintln!("Failed to write downloaded m3u8file {:?}", e);
}
} }
} }