Skip to content

Commit

Permalink
Album Cover from MusicBrainz
Browse files Browse the repository at this point in the history
  • Loading branch information
artemanufrij committed Feb 19, 2018
1 parent 2558b7f commit c1f66fd
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 82 deletions.
1 change: 1 addition & 0 deletions data/com.github.artemanufrij.playmymusic.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<p>New:</p>
<ul>
<li>List View for all music content</li>
<li>Grab album cover from MusicBrainz</li>
</ul>
</description>
</release>
Expand Down
6 changes: 3 additions & 3 deletions schemas/com.github.artemanufrij.playmymusic.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@
<summary>Last choosed view.</summary>
<description>Last choosed view.</description>
</key>
<key name="load-artist-from-musicbrainz" type="b">
<key name="load-content-from-musicbrainz" type="b">
<default>true</default>
<summary>Load Artist data like Artwork from MusicBrainz.</summary>
<description>Load Artist data like Artwork from MusicBrainz.</description>
<summary>Load Artwork and Cover from MusicBrainz.</summary>
<description>Load Artwork and Cover from MusicBrainz.</description>
</key>
<key name="use-dark-theme" type="b">
<default>false</default>
Expand Down
16 changes: 8 additions & 8 deletions src/Dialogs/Preferences.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ namespace PlayMyMusic.Dialogs {
settings.sync_files = sync_files.active;
});

var load_artist_data_label = new Gtk.Label (_("Load Artist data from MusicBrainz"));
load_artist_data_label.halign = Gtk.Align.START;
var load_artist_data = new Gtk.Switch ();
load_artist_data.active = settings.load_artist_from_musicbrainz;
load_artist_data.notify["active"].connect (() => {
settings.load_artist_from_musicbrainz = load_artist_data.active;
var load_content_label = new Gtk.Label (_("Load Content from MusicBrainz"));
load_content_label.halign = Gtk.Align.START;
var load_content = new Gtk.Switch ();
load_content.active = settings.load_content_from_musicbrainz;
load_content.notify["active"].connect (() => {
settings.load_content_from_musicbrainz = load_content.active;
});

var save_custom_covers_label = new Gtk.Label (_("Save custom Covers in Library folder"));
Expand All @@ -113,8 +113,8 @@ namespace PlayMyMusic.Dialogs {
grid.attach (sync_files_label, 0, 3);
grid.attach (sync_files, 1, 3);
grid.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 4, 2, 1);
grid.attach (load_artist_data_label, 0, 5);
grid.attach (load_artist_data, 1, 5);
grid.attach (load_content_label, 0, 5);
grid.attach (load_content, 1, 5);
grid.attach (save_custom_covers_label, 0, 6);
grid.attach (save_custom_covers, 1, 6);
grid.attach (save_id3_tags_label, 0, 7);
Expand Down
4 changes: 3 additions & 1 deletion src/Objects/Album.vala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace PlayMyMusic.Objects {
}

// COVER REGION
private async void load_cover_async () {
public async void load_cover_async () {
if (is_cover_loading || cover != null || this.ID == 0 || this.tracks.length () == 0) {
return;
}
Expand All @@ -142,6 +142,8 @@ namespace PlayMyMusic.Objects {
Gdk.Pixbuf? return_value = load_or_create_cover.end (res);
if (return_value != null) {
this.cover = return_value;
} else if (settings.load_content_from_musicbrainz) {
Services.MusicBrainzManager.instance.fill_album_cover_queue (this);
}
is_cover_loading = false;
});
Expand Down
12 changes: 11 additions & 1 deletion src/Objects/Artist.vala
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ namespace PlayMyMusic.Objects {
}
}

public bool has_empty_album_covers () {
foreach (var album in albums) {
if (album.cover == null) {
return true;
}
}

return false;
}

public void merge (GLib.List<Objects.Artist> artists) {
foreach (var artist in artists) {
if (artist.ID == ID) {
Expand Down Expand Up @@ -194,7 +204,7 @@ namespace PlayMyMusic.Objects {
Gdk.Pixbuf? return_value = load_or_create_cover.end (res);
if (return_value != null) {
this.cover = return_value;
} else if (settings.load_artist_from_musicbrainz && !this.name.down ().contains ("various") && !this.name.down ().contains ("artist")) {
} else if (settings.load_content_from_musicbrainz && !this.name.down ().contains ("various") && !this.name.down ().contains ("artist")) {
Services.MusicBrainzManager.instance.fill_artist_cover_queue (this);
}
is_cover_loading = false;
Expand Down
33 changes: 15 additions & 18 deletions src/Objects/Track.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace PlayMyMusic.Objects {
public signal void album_changed (Album album);
public signal void tags_saved ();

Album? _album = null;
Album ? _album = null;
public Album album {
get {
if (_album == null) {
Expand All @@ -43,8 +43,8 @@ namespace PlayMyMusic.Objects {
}
}

Playlist? _playlist = null;
public Playlist? playlist {
Playlist ? _playlist = null;
public Playlist ? playlist {
get {
return _playlist;
}
Expand Down Expand Up @@ -74,24 +74,25 @@ namespace PlayMyMusic.Objects {
}
}

public File? original_file { get; set; }
public File ? original_file { get; set; }

public signal void path_not_found ();

construct {
library_manager = Services.LibraryManager.instance;
removed.connect (() => {
if (album != null) {
album.track_removed (this);
album.artist.track_removed (this);
}
if (playlist != null) {
playlist.track_removed (this);
}
});
removed.connect (
() => {
if (album != null) {
album.track_removed (this);
album.artist.track_removed (this);
}
if (playlist != null) {
playlist.track_removed (this);
}
});
}

public Track (TracksContainer? container = null) {
public Track (TracksContainer ? container = null) {
if (container != null && container is Album) {
set_album (container as Album);
} else if (container != null && container is Playlist) {
Expand Down Expand Up @@ -126,10 +127,8 @@ namespace PlayMyMusic.Objects {
}

public void save_id3_tags () {

var path = File.new_for_uri (uri);

stdout.printf ("ID3 Start\n");
var file = new TagLib.File (path.get_path ());
if (file.tag.album == this.album.title && file.tag.artist == this.album.artist.name && file.tag.year == this.album.year && file.tag.genre == genre) {
return;
Expand All @@ -141,8 +140,6 @@ namespace PlayMyMusic.Objects {
file.tag.genre = genre;
if (file.save ()) {
tags_saved ();

stdout.printf ("ID3 SAVED year:%u \n", file.tag.year);
}
path.dispose ();
}
Expand Down
Loading

0 comments on commit c1f66fd

Please sign in to comment.