@@ -176,6 +176,12 @@ public class Music.PlaybackManager : Object {
176176
177177 unowned Gst . TagList ? tag_list = info. get_tags ();
178178
179+ string _album;
180+ tag_list. get_string (Gst . Tags . ALBUM , out _album);
181+ if (_album != null ) {
182+ audio_object. album = _album;
183+ }
184+
179185 string _title;
180186 tag_list. get_string (Gst . Tags . TITLE , out _title);
181187 if (_title != null ) {
@@ -190,12 +196,37 @@ public class Music.PlaybackManager : Object {
190196 audio_object. artist = _(" Unknown" );
191197 }
192198
193- var sample = get_cover_sample (tag_list);
194- if (sample != null ) {
195- var buffer = sample. get_buffer ();
199+ string art_hash = uri;
200+ if (_artist != null && _album != null ) {
201+ art_hash = " %s :%s " . printf (_artist, _album);
202+ }
203+
204+ var art_file = File . new_for_path (Path . build_path (
205+ Path . DIR_SEPARATOR_S ,
206+ get_art_cache_dir (),
207+ Checksum . compute_for_string (SHA256 , art_hash)
208+ ));
196209
197- if (buffer != null ) {
198- audio_object. texture = Gdk . Texture . for_pixbuf (get_pixbuf_from_buffer (buffer));
210+ if (art_file. query_exists ()) {
211+ audio_object. art_url = art_file. get_uri ();
212+ audio_object. texture = Gdk . Texture . from_file (art_file);
213+ } else {
214+ var sample = get_cover_sample (tag_list);
215+ if (sample != null ) {
216+ var buffer = sample. get_buffer ();
217+
218+ if (buffer != null ) {
219+ var texture = Gdk . Texture . for_pixbuf (get_pixbuf_from_buffer (buffer));
220+ audio_object. texture = texture;
221+
222+ save_art_file. begin (texture, art_file, (obj, res) = > {
223+ try {
224+ audio_object. art_url = save_art_file. end (res);
225+ } catch (Error e) {
226+ critical (e. message);
227+ }
228+ });
229+ }
199230 }
200231 }
201232 } else {
@@ -429,6 +460,24 @@ public class Music.PlaybackManager : Object {
429460 return pix;
430461 }
431462
463+ private async string save_art_file (Gdk .Texture texture , File file ) throws Error requires (texture != null ) {
464+ DirUtils . create_with_parents (get_art_cache_dir (), 0755 );
465+
466+ var ostream = yield file. create_async (NONE );
467+ yield ostream. write_bytes_async (texture. save_to_png_bytes ());
468+
469+ return file. get_uri ();
470+ }
471+
472+ private string get_art_cache_dir () {
473+ return Path . build_path (
474+ Path . DIR_SEPARATOR_S ,
475+ Environment . get_user_cache_dir (),
476+ GLib . Application . get_default (). application_id,
477+ " art"
478+ );
479+ }
480+
432481 private void on_items_changed () {
433482 var shuffle_action_action = (SimpleAction ) GLib . Application . get_default (). lookup_action (Application . ACTION_SHUFFLE );
434483 has_items = queue_liststore. get_n_items () > 0 ;
0 commit comments