use std::{process::Command, str}; pub struct SongMetadata { pub name: String, pub artist: String, pub album: String, pub art_url: String, } impl SongMetadata { pub fn new() -> SongMetadata { SongMetadata { name: "NONE".to_string(), artist: "NONE".to_string(), album: "NONE".to_string(), art_url: "NONE".to_string(), } } } const COM_START: &str = "playerctl --player=strawberry"; pub fn get_song_metadata() -> SongMetadata { let command = format!("{} {}", COM_START, "metadata --format {{title}},{{artist}},{{album}},{{mpris:artUrl}}"); 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.art_url = split[3].to_string(); sm } pub fn next_track() { let command = format!("{} {}", COM_START, "next"); let _ = run_command(&command); } 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() }