|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::{process::Command, str};
|
|
|
|
|
|
|
|
|
|
pub struct SongMetadata
|
|
|
|
|
{
|
|
|
|
|
pub name: String,
|
|
|
|
|
pub artist: String,
|
|
|
|
|
pub album: String,
|
|
|
|
|
}
|
|
|
|
|
impl SongMetadata
|
|
|
|
|
{
|
|
|
|
|
pub fn new() -> SongMetadata
|
|
|
|
|
{
|
|
|
|
|
SongMetadata {
|
|
|
|
|
name: "NONE".to_string(),
|
|
|
|
|
artist: "NONE".to_string(),
|
|
|
|
|
album: "NONE".to_string(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_song_metadata() -> SongMetadata
|
|
|
|
|
{
|
|
|
|
|
const COM_START: &str = "playerctl --player=strawberry";
|
|
|
|
|
|
|
|
|
|
let command = format!("{} {}", COM_START, "metadata --format {{title}},{{artist}},{{album}}");
|
|
|
|
|
|
|
|
|
|
let result = run_command(&command);
|
|
|
|
|
|
|
|
|
|
let mut sm = SongMetadata::new();
|
|
|
|
|
|
|
|
|
|
let split: Vec<&str> = result.split(',').collect();
|
|
|
|
|
|
|
|
|
|
sm.name = split[0].to_string();
|
|
|
|
|
sm.artist = split[1].to_string();
|
|
|
|
|
sm.album = split[2].to_string();
|
|
|
|
|
|
|
|
|
|
sm
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn run_command(command: &str) -> String
|
|
|
|
|
{
|
|
|
|
|
let output = Command::new("sh")
|
|
|
|
|
.arg("-c")
|
|
|
|
|
.arg(command)
|
|
|
|
|
.output()
|
|
|
|
|
.expect(&format!("Failed to run the command: {}", command));
|
|
|
|
|
str::from_utf8(&output.stdout).expect("Failed to convert command result to utf8 string").to_string()
|
|
|
|
|
|
|
|
|
|
}
|