i wonder if it is formatted

This commit is contained in:
gallant 2023-05-11 22:16:14 -05:00
parent 8752e8abf8
commit 8a94ca26c5
2 changed files with 11 additions and 95 deletions

View file

@ -20,12 +20,12 @@ fn main() {
//programs need time to run?? crazy.. .
match m.subcommand() {
Some(("pause", _)) => print!("{}", player.pause().unwrap()),
Some(("play", _)) => print!("{}", player.play().unwrap()),
Some(("next", _)) => print!("{}", player.next().unwrap()),
Some(("previous", _)) => print!("{}", player.previous().unwrap()),
Some(("pause", _)) => print!("{}", player.send_command("pause").unwrap()),
Some(("play", _)) => print!("{}", player.send_command("play").unwrap()),
Some(("next", _)) => print!("{}", player.send_command("next track").unwrap()),
Some(("previous", _)) => print!("{}", player.send_command("back track").unwrap()),
_ => {
print!("{}", player.get_track().unwrap());
print!("{}", player.send_command("get name of current track").unwrap());
}
}
}

View file

@ -32,105 +32,20 @@ impl Player {
Player { players: vec_c }
}
pub fn play(&self) -> Result<String, PlayerError> {
pub fn send_command(&self, command: &str) -> Result<String, PlayerError>
{
let a = Command::new("osascript")
.arg("-e")
.arg(format!(
r#"tell application "{}"
if it is running then
play
{}
else
return "not running"
end if
end tell"#,
self.players.get(0).unwrap()
))
.output();
if let Ok(b) = a {
print!("{}", std::str::from_utf8(&b.stderr)?);
Ok(std::str::from_utf8(&b.stdout)?.to_string())
} else {
Err(PlayerError::OutputError)
}
}
pub fn pause(&self) -> Result<String, PlayerError> {
let a = Command::new("osascript")
.arg("-e")
.arg(format!(
r#"tell application "{}"
if it is running then
pause
else
return "not running"
end if
end tell"#,
self.players.get(0).unwrap()
))
.output();
if let Ok(b) = a {
print!("{}", std::str::from_utf8(&b.stderr)?);
Ok(std::str::from_utf8(&b.stdout)?.to_string())
} else {
Err(PlayerError::OutputError)
}
}
pub fn next(&self) -> Result<String, PlayerError> {
let a = Command::new("osascript")
.arg("-e")
.arg(format!(
r#"tell application "{}"
if it is running then
next track
else
return "not running"
end if
end tell"#,
self.players.get(0).unwrap()
))
.output();
if let Ok(b) = a {
print!("{}", std::str::from_utf8(&b.stderr)?);
Ok(std::str::from_utf8(&b.stdout)?.to_string())
} else {
Err(PlayerError::OutputError)
}
}
pub fn previous(&self) -> Result<String, PlayerError> {
let a = Command::new("osascript")
.arg("-e")
.arg(format!(
r#"tell application "{}"
if it is running then
back track
else
return "not running"
end if
end tell"#,
self.players.get(0).unwrap()
))
.output();
if let Ok(b) = a {
print!("{}", std::str::from_utf8(&b.stderr)?);
Ok(std::str::from_utf8(&b.stdout)?.to_string())
} else {
Err(PlayerError::OutputError)
}
}
pub fn get_track(&self) -> Result<String, PlayerError> {
let a = Command::new("osascript")
.arg("-e")
.arg(format!(
r#"tell application "{}"
if it is running then
get name of current track
else
return "not running"
end if
end tell"#,
match self.players.get(0) {
Some(a) => a,
None => "Music",
}
self.players.get(0).unwrap(),
command
))
.output();
if let Ok(b) = a {
@ -140,4 +55,5 @@ impl Player {
Err(PlayerError::OutputError)
}
}
}