public static DatabaseArtistInfo FindOrCreate(DatabaseArtistInfo artist) { if (artist.Name == last_artist_name && last_artist != null) { return(last_artist); } if (String.IsNullOrEmpty(artist.Name) || artist.Name.Trim() == String.Empty) { artist.Name = null; } using (IDataReader reader = FindExistingArtists(artist.Name)) { if (reader.Read()) { last_artist = provider.Load(reader); if (last_artist.NameSort != artist.NameSort) { last_artist.NameSort = artist.NameSort; last_artist.Save(); } } else { artist.Save(); last_artist = artist; } } last_artist_name = artist.Name; return(last_artist); }
public static DatabaseArtistInfo FindOrCreate (string artistName, string artistNameSort, string artistMusicBrainzId) { DatabaseArtistInfo artist = new DatabaseArtistInfo (); artist.Name = artistName; artist.NameSort = artistNameSort; artist.MusicBrainzId = artistMusicBrainzId; return FindOrCreate (artist); }
public static DatabaseArtistInfo FindOrCreate(string artistName, string artistNameSort) { DatabaseArtistInfo artist = new DatabaseArtistInfo(); artist.Name = artistName; artist.NameSort = artistNameSort; return(FindOrCreate(artist)); }
public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation) { DatabaseAlbumInfo album = new DatabaseAlbumInfo(); album.Title = title; album.TitleSort = title_sort; album.IsCompilation = isCompilation; return(FindOrCreate(artist, album)); }
public static DatabaseAlbumInfo FindOrCreate (DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation, string album_musicrainz_id) { DatabaseAlbumInfo album = new DatabaseAlbumInfo (); album.Title = title; album.TitleSort = title_sort; album.IsCompilation = isCompilation; album.MusicBrainzId = album_musicrainz_id; return FindOrCreate (artist, album); }
public static DatabaseArtistInfo FindOrCreate(string artistName, string artistNameSort, string artistMusicBrainzId) { DatabaseArtistInfo artist = new DatabaseArtistInfo(); artist.Name = artistName; artist.NameSort = artistNameSort; artist.MusicBrainzId = artistMusicBrainzId; return(FindOrCreate(artist)); }
public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation, string album_musicrainz_id) { DatabaseAlbumInfo album = new DatabaseAlbumInfo(); album.Title = title; album.TitleSort = title_sort; album.IsCompilation = isCompilation; album.MusicBrainzId = album_musicrainz_id; return(FindOrCreate(artist, album)); }
public static DatabaseArtistInfo UpdateOrCreate(DatabaseArtistInfo artist) { DatabaseArtistInfo found = FindOrCreate(artist); if (found != artist) { // Overwrite the found artist artist.Name = found.Name; artist.NameSort = found.NameSort; artist.dbid = found.DbId; artist.Save(); } return(artist); }
public void Save(bool notify, params QueryField [] fields_changed) { // If either the artist or album changed, if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true) { DatabaseArtistInfo artist = Artist; ArtistId = artist.DbId; DatabaseAlbumInfo album = Album; AlbumId = album.DbId; // TODO get rid of unused artists/albums } // If PlayCountField is not transient we still want to update the file only if it's from the music library var transient = transient_fields; if (!transient.Contains(BansheeQuery.PlayCountField) && !ServiceManager.SourceManager.MusicLibrary.Equals(PrimarySource)) { transient = new HashSet <QueryField> (transient_fields); transient.Add(BansheeQuery.PlayCountField); } if (fields_changed.Length == 0 || !transient.IsSupersetOf(fields_changed)) { DateUpdated = DateTime.Now; } bool is_new = (TrackId == 0); if (is_new) { LastSyncedStamp = DateAdded = DateUpdated = DateTime.Now; } ProviderSave(); if (notify && PrimarySource != null) { if (is_new) { PrimarySource.NotifyTracksAdded(); } else { PrimarySource.NotifyTracksChanged(fields_changed); } } }
public static DatabaseAlbumInfo UpdateOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album) { DatabaseAlbumInfo found = FindOrCreate(artist, album); if (found != album) { // Overwrite the found album album.Title = found.Title; album.TitleSort = found.TitleSort; album.ArtistName = found.ArtistName; album.ArtistNameSort = found.ArtistNameSort; album.IsCompilation = found.IsCompilation; album.dbid = found.DbId; album.ArtistId = found.ArtistId; album.Save(); } return(album); }
public void Save(bool notify, params QueryField [] fields_changed) { // If either the artist or album changed, if (ArtistId == 0 || AlbumId == 0 || artist_changed == true || album_changed == true) { DatabaseArtistInfo artist = Artist; ArtistId = artist.DbId; DatabaseAlbumInfo album = Album; AlbumId = album.DbId; // TODO get rid of unused artists/albums } if (fields_changed.Length == 0 || !transient_fields.IsSupersetOf(fields_changed)) { DateUpdated = DateTime.Now; } bool is_new = (TrackId == 0); if (is_new) { DateAdded = DateUpdated = DateTime.Now; } ProviderSave(); if (notify && PrimarySource != null) { if (is_new) { PrimarySource.NotifyTracksAdded(); } else { PrimarySource.NotifyTracksChanged(fields_changed); } } }
public static DatabaseArtistInfo UpdateOrCreate(DatabaseArtistInfo artist) { DatabaseArtistInfo found = FindOrCreate (artist); if (found != artist) { // Overwrite the found artist artist.Name = found.Name; artist.NameSort = found.NameSort; artist.MusicBrainzId = found.MusicBrainzId; artist.dbid = found.DbId; artist.Save (); } return artist; }
public static void Reset() { last_artist_name = null; last_artist = null; }
public static DatabaseArtistInfo FindOrCreate(DatabaseArtistInfo artist) { if (artist.Name == last_artist_name && last_artist != null) { return last_artist; } if (String.IsNullOrEmpty (artist.Name) || artist.Name.Trim () == String.Empty) { artist.Name = null; } using (IDataReader reader = FindExistingArtists (artist.Name)) { if (reader.Read ()) { last_artist = provider.Load (reader); bool save = false; if (last_artist.NameSort != artist.NameSort) { last_artist.NameSort = artist.NameSort; save = true; } if (last_artist.MusicBrainzId != artist.MusicBrainzId && !String.IsNullOrEmpty (artist.MusicBrainzId)) { last_artist.MusicBrainzId = artist.MusicBrainzId; save = true; } if (save) { last_artist.Save (); } } else { artist.Save (); last_artist = artist; } } last_artist_name = artist.Name; return last_artist; }
public static DatabaseAlbumInfo UpdateOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album) { DatabaseAlbumInfo found = FindOrCreate (artist, album); if (found != album) { // Overwrite the found album album.Title = found.Title; album.TitleSort = found.TitleSort; album.ArtistName = found.ArtistName; album.ArtistNameSort = found.ArtistNameSort; album.IsCompilation = found.IsCompilation; album.MusicBrainzId = found.MusicBrainzId; album.dbid = found.DbId; album.ArtistId = found.ArtistId; album.ArtworkId = found.ArtworkId; album.Save (); } return album; }
public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album) { if (album.Title == last_title && artist.DbId == last_artist_id && last_album != null) { return last_album; } if (String.IsNullOrEmpty (album.Title) || album.Title.Trim () == String.Empty) { album.Title = null; } using (IDataReader reader = FindExistingArtists (artist.DbId, album.Title)) { if (reader.Read ()) { bool save = false; last_album = provider.Load (reader); // If the artist name has changed since last time (but it's the same artist) then update our copy of the ArtistName if (last_album.ArtistName != artist.Name) { last_album.ArtistName = artist.Name; save = true; } // Ditto artist sort name if (last_album.ArtistNameSort != artist.NameSort) { last_album.ArtistNameSort = artist.NameSort; save = true; } // And album sort name if (last_album.TitleSort != album.TitleSort) { last_album.TitleSort = album.TitleSort; save = true; } // If the album IsCompilation status has changed, update the saved album info if (last_album.IsCompilation != album.IsCompilation) { last_album.IsCompilation = album.IsCompilation; save = true; } // If the album MusicBrainzId has changed, but is not null if (last_album.MusicBrainzId != album.MusicBrainzId && !String.IsNullOrEmpty (album.MusicBrainzId)) { last_album.MusicBrainzId = album.MusicBrainzId; save = true; } // If the ArtworkId has changed, update the db if (last_album.ArtworkId != album.ArtworkId) { last_album.ArtworkId = album.ArtworkId; save = true; } if (save) { last_album.Save (); } } else { album.ArtistId = artist.DbId; album.ArtistName = artist.Name; album.ArtistNameSort = artist.NameSort; album.Save (); last_album = album; } } last_title = album.Title; last_artist_id = artist.DbId; return last_album; }
public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation) { return FindOrCreate (artist, title, title_sort, isCompilation, null); }
private void LoadDiscMetadata (object state) { try { LocalDisc mb_disc = (LocalDisc)state; OnMetadataQueryStarted (mb_disc); Release release = Release.Query (mb_disc).First (); if (release == null || release.Score < 100) { OnMetadataQueryFinished (false); return; } var tracks = release.GetTracks (); if (tracks.Count != Count) { OnMetadataQueryFinished (false); return; } disc_title = release.GetTitle (); int disc_number = 1; int i = 0; foreach (Disc disc in release.GetDiscs ()) { i++; if (disc.Id == mb_disc.Id) { disc_number = i; } } DateTime release_date = DateTime.MaxValue; foreach (Event release_event in release.GetEvents ()) { if (release_event.Date != null) { try { // Handle "YYYY" dates var date_str = release_event.Date; DateTime date = DateTime.Parse ( date_str.Length > 4 ? date_str : date_str + "-01", ApplicationContext.InternalCultureInfo ); if (date < release_date) { release_date = date; } } catch { } } } DatabaseArtistInfo artist = new DatabaseArtistInfo (); var mb_artist = release.GetArtist (); artist.Name = mb_artist.GetName (); artist.NameSort = mb_artist.GetSortName (); artist.MusicBrainzId = mb_artist.Id; bool is_compilation = false; DatabaseAlbumInfo album = new DatabaseAlbumInfo (); album.Title = disc_title; album.ArtistName = artist.Name; album.MusicBrainzId = release.Id; album.ReleaseDate = release_date == DateTime.MaxValue ? DateTime.MinValue : release_date; i = 0; foreach (Track track in tracks) { AudioCdTrackInfo model_track = (AudioCdTrackInfo)this[i++]; var mb_track_artist = track.GetArtist (); model_track.MusicBrainzId = track.Id; model_track.TrackTitle = track.GetTitle (); model_track.ArtistName = mb_track_artist.GetName (); model_track.AlbumTitle = disc_title; model_track.DiscNumber = disc_number; model_track.Album = album; model_track.Artist = new DatabaseArtistInfo (); model_track.Artist.Name = model_track.ArtistName; model_track.Artist.NameSort = mb_track_artist.GetSortName (); model_track.Artist.MusicBrainzId = mb_track_artist.Id; if (release_date != DateTime.MinValue) { model_track.Year = release_date.Year; } if (!is_compilation && mb_track_artist.Id != artist.MusicBrainzId) { is_compilation = true; } } if (is_compilation) { album.IsCompilation = true; for (i = 0; i < tracks.Count; i++) { AudioCdTrackInfo model_track = (AudioCdTrackInfo)this[i]; model_track.IsCompilation = true; model_track.AlbumArtist = artist.Name; model_track.AlbumArtistSort = artist.NameSort; } } OnMetadataQueryFinished (true); } catch (Exception ex) { Log.DebugException (ex); OnMetadataQueryFinished (false); } }
public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, string title, string title_sort, bool isCompilation) { return(FindOrCreate(artist, title, title_sort, isCompilation, null)); }
public static DatabaseAlbumInfo FindOrCreate(DatabaseArtistInfo artist, DatabaseAlbumInfo album) { if (album.Title == last_title && artist.DbId == last_artist_id && last_album != null) { return(last_album); } if (String.IsNullOrEmpty(album.Title) || album.Title.Trim() == String.Empty) { album.Title = null; } using (IDataReader reader = FindExistingArtists(artist.DbId, album.Title)) { if (reader.Read()) { bool save = false; last_album = provider.Load(reader); // If the artist name has changed since last time (but it's the same artist) then update our copy of the ArtistName if (last_album.ArtistName != artist.Name) { last_album.ArtistName = artist.Name; save = true; } // Ditto artist sort name if (last_album.ArtistNameSort != artist.NameSort) { last_album.ArtistNameSort = artist.NameSort; save = true; } // And album sort name if (last_album.TitleSort != album.TitleSort) { last_album.TitleSort = album.TitleSort; save = true; } // If the album IsCompilation status has changed, update the saved album info if (last_album.IsCompilation != album.IsCompilation) { last_album.IsCompilation = album.IsCompilation; save = true; } // If the album MusicBrainzId has changed, but is not null if (last_album.MusicBrainzId != album.MusicBrainzId && !String.IsNullOrEmpty(album.MusicBrainzId)) { last_album.MusicBrainzId = album.MusicBrainzId; save = true; } // If the ArtworkId has changed, update the db if (last_album.ArtworkId != album.ArtworkId) { last_album.ArtworkId = album.ArtworkId; save = true; } if (save) { last_album.Save(); } } else { album.ArtistId = artist.DbId; album.ArtistName = artist.Name; album.ArtistNameSort = artist.NameSort; album.Save(); last_album = album; } } last_title = album.Title; last_artist_id = artist.DbId; return(last_album); }