Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/AudioObject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

public class Music.AudioObject : Object {
public string uri { get; construct; }
public Gdk.Texture texture { get; set; }
public Gdk.Texture? texture { get; set; default = null; }
public string album { get; set; }
public string artist { get; set; }
public string title { get; set; }
public int64 duration { get; set; default = 0; }
public string art_url { get; set; default = ""; }

public AudioObject (string uri) {
Object (uri: uri);
Expand Down
4 changes: 4 additions & 0 deletions src/DBus/MprisPlayer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class Music.MprisPlayer : Object {
_metadata.insert ("xesam:artist", array);
}

if (audio.art_url != "") {
_metadata.insert ("mpris:artUrl", audio.art_url);
}

if (audio.title != null) {
_metadata.insert ("xesam:title", audio.title);
}
Expand Down
59 changes: 54 additions & 5 deletions src/PlaybackManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ public class Music.PlaybackManager : Object {

unowned Gst.TagList? tag_list = info.get_tags ();

string _album;
tag_list.get_string (Gst.Tags.ALBUM, out _album);
if (_album != null) {
audio_object.album = _album;
}

string _title;
tag_list.get_string (Gst.Tags.TITLE, out _title);
if (_title != null) {
Expand All @@ -213,12 +219,37 @@ public class Music.PlaybackManager : Object {
audio_object.artist = _("Unknown");
}

var sample = get_cover_sample (tag_list);
if (sample != null) {
var buffer = sample.get_buffer ();
string art_hash = uri;
if (_artist != null && _album != null) {
art_hash = "%s:%s".printf (_artist, _album);
}

var art_file = File.new_for_path (Path.build_path (
Path.DIR_SEPARATOR_S,
get_art_cache_dir (),
Checksum.compute_for_string (SHA256, art_hash)
));

if (buffer != null) {
audio_object.texture = Gdk.Texture.for_pixbuf (get_pixbuf_from_buffer (buffer));
if (art_file.query_exists ()) {
audio_object.art_url = art_file.get_uri ();
audio_object.texture = Gdk.Texture.from_file (art_file);
} else {
var sample = get_cover_sample (tag_list);
if (sample != null) {
var buffer = sample.get_buffer ();

if (buffer != null) {
var texture = Gdk.Texture.for_pixbuf (get_pixbuf_from_buffer (buffer));
audio_object.texture = texture;

save_art_file.begin (texture, art_file, (obj, res) => {
try {
audio_object.art_url = save_art_file.end (res);
} catch (Error e) {
critical (e.message);
}
});
}
}
}
} else {
Expand Down Expand Up @@ -451,4 +482,22 @@ public class Music.PlaybackManager : Object {

return pix;
}

private async string save_art_file (Gdk.Texture texture, File file) throws Error requires (texture != null) {
DirUtils.create_with_parents (get_art_cache_dir (), 0755);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right permission to use? I would think 644 since it doesn't need to be executable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because this is for the parent folder, not the file. So for folders 7 is access, not execute

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooooh!


var ostream = yield file.create_async (NONE);
yield ostream.write_bytes_async (texture.save_to_png_bytes ());

return file.get_uri ();
}

private string get_art_cache_dir () {
return Path.build_path (
Path.DIR_SEPARATOR_S,
Environment.get_user_cache_dir (),
GLib.Application.get_default ().application_id,
"art"
);
}
}