toggle mpv fullscreen

This commit is contained in:
Love 2023-02-02 16:41:36 +01:00
parent 39ced4e0d7
commit 304fa44629

View File

@ -13,18 +13,20 @@ async fn main() {
"BLAZINGLY FAST".italic() "BLAZINGLY FAST".italic()
); );
println!( println!(
"There will be some options along the way \n {} is to refresh the local iptvfile.\n {} is to quit and save watched fields\n {} is to download fields\n {} is to perform a new search\n {} is to select all", "There will be some options along the way \n {} is to refresh the local iptvfile.\n {} is to quit and save watched fields\n {} is to download fields\n {} is to perform a new search\n {} is to select all\n {} is to toggtle fullscreen for mpv",
"r".bold(),"q".bold(),"d".bold(),"s".bold(),"a".bold() "r".bold(),"q".bold(),"d".bold(),"s".bold(),"a".bold(), "f".bold()
); );
let parser = Parser::new("iptv.m3u8".to_owned(), setup(), "watched.txt".to_owned()).await; let parser = Parser::new("iptv.m3u8".to_owned(), setup(), "watched.txt".to_owned()).await;
let mut mpv_fs = false;
let mut search_result: Option<Rc<Vec<&M3u8>>> = None; let mut search_result: Option<Rc<Vec<&M3u8>>> = None;
let mut readline = Readline::new(); let mut readline = Readline::new();
loop { loop {
// Dont't perform a search if user has just watched, instead present the previous search // Dont't perform a search if user has just watched, instead present the previous search
if search_result.is_none() { if search_result.is_none() {
let search = readline.input("Search by name [r | q]: ").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- // If they want to quit, let them-
@ -34,6 +36,13 @@ async fn main() {
search_result = None; search_result = None;
refresh(&parser).await; refresh(&parser).await;
continue; continue;
} else if search == "f" {
mpv_fs = !mpv_fs;
println!(
"Toggled mpv to {}launch in fullscreen",
if mpv_fs { "" } else { "not " }
);
continue;
} }
search_result = Some(Rc::new(parser.find(search))); search_result = Some(Rc::new(parser.find(search)));
@ -103,7 +112,7 @@ async fn main() {
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])) stream(&(search_result[k - 1]), mpv_fs)
} }
Err(e) => println!("Have to be a valid number! {:?}", e), Err(e) => println!("Have to be a valid number! {:?}", e),
} }
@ -144,13 +153,17 @@ async fn download_m3u8(files_to_download: Rc<Vec<&M3u8>>) {
* how youre supposed to do things, it's perfectly safe in this context and also the most efficient way. * how youre supposed to do things, it's perfectly safe in this context and also the most efficient way.
* With other words, it's BLAZINGLY FAST * With other words, it's BLAZINGLY FAST
*/ */
fn stream(m3u8item: &M3u8) { fn stream(m3u8item: &M3u8, launch_in_fullscreen: bool) {
let ptr = m3u8item as *const M3u8 as *mut M3u8; let ptr = m3u8item as *const M3u8 as *mut M3u8;
let mut item = unsafe { &mut *ptr }; let mut item = unsafe { &mut *ptr };
item.watched = true; item.watched = true;
let mut args: Vec<&str> = vec![&m3u8item.link];
if launch_in_fullscreen {
args.push("--fs");
}
Command::new("mpv") Command::new("mpv")
.arg(&m3u8item.link) .args(args)
.output() .output()
.expect("Could not listen for output"); .expect("Could not listen for output");
} }