Cache cover art as file instead of sending it over dbus as base64
This commit is contained in:
parent
b76ab9cdcb
commit
6940148f3b
3 changed files with 348 additions and 323 deletions
643
Cargo.lock
generated
643
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -16,10 +16,11 @@ muss-interpreter = { path = "../interpreter", version = "0.9.0" }
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
#dbus = { version = "^0.9" }
|
#dbus = { version = "^0.9" }
|
||||||
mpris-player = { version = "^0.6", path = "../mpris-player", optional = true }
|
mpris-player = { version = "^0.6", path = "../mpris-player", optional = true }
|
||||||
|
base64 = { version = "0.13", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["os-controls", "mpd"]
|
default = ["os-controls", "mpd"]
|
||||||
os-controls = []
|
os-controls = ["base64"]
|
||||||
|
|
||||||
# I wish this worked...
|
# I wish this worked...
|
||||||
#[target.'cfg(not(target_os = "linux"))'.features]
|
#[target.'cfg(not(target_os = "linux"))'.features]
|
||||||
|
|
|
@ -9,6 +9,9 @@ use mpris_player::{Metadata, MprisPlayer, PlaybackStatus};
|
||||||
#[cfg(all(target_os = "linux", feature = "os-controls", feature = "mpris-player"))]
|
#[cfg(all(target_os = "linux", feature = "os-controls", feature = "mpris-player"))]
|
||||||
use muss_interpreter::Item;
|
use muss_interpreter::Item;
|
||||||
|
|
||||||
|
#[cfg(all(target_os = "linux", feature = "os-controls", feature = "mpris-player"))]
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
//use super::Controller;
|
//use super::Controller;
|
||||||
use super::player_wrapper::{ControlAction, PlaybackAction};
|
use super::player_wrapper::{ControlAction, PlaybackAction};
|
||||||
|
|
||||||
|
@ -202,10 +205,28 @@ impl SystemControlWrapper {
|
||||||
|
|
||||||
fn build_metadata(item: Item) -> Metadata {
|
fn build_metadata(item: Item) -> Metadata {
|
||||||
let file_uri = item.field("filename").and_then(|x| x.to_owned().to_str());
|
let file_uri = item.field("filename").and_then(|x| x.to_owned().to_str());
|
||||||
|
let cover_art = item.field("cover")
|
||||||
|
.and_then(|x| x.to_owned().to_str());
|
||||||
|
let cover_url = if let Some(art) = &cover_art {
|
||||||
|
const DATA_START: usize = 23;
|
||||||
|
let path = format!("{}/muss-cover-{}.jpg",
|
||||||
|
std::env::var("HOME").map(|home| home + "/.cache").unwrap_or_else(|_| "/tmp".to_owned()),
|
||||||
|
&art[DATA_START..DATA_START+16].replace("/", ""));
|
||||||
|
let pathbuf = std::path::PathBuf::from(&path);
|
||||||
|
if !pathbuf.exists() {
|
||||||
|
base64::decode(&art[DATA_START..]).ok()
|
||||||
|
.and_then(|decoded| std::fs::File::create(&path).ok().map(|file| (decoded, file)))
|
||||||
|
.and_then(|(decoded, mut file)| file.write(&decoded).ok())
|
||||||
|
.map(|_| path)
|
||||||
|
} else {
|
||||||
|
Some(path)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
Metadata {
|
Metadata {
|
||||||
length: None, // populated separately
|
length: None, // populated separately
|
||||||
art_url: item.field("cover")
|
art_url: cover_url,
|
||||||
.and_then(|x| x.to_owned().to_str()),
|
|
||||||
album: item.field("album").and_then(|x| x.to_owned().to_str()),
|
album: item.field("album").and_then(|x| x.to_owned().to_str()),
|
||||||
album_artist: item
|
album_artist: item
|
||||||
.field("albumartist")
|
.field("albumartist")
|
||||||
|
|
Loading…
Reference in a new issue