[banshee] Read/write/load the MusicBrainzID properties
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Read/write/load the MusicBrainzID properties
- Date: Sat, 15 May 2010 22:29:26 +0000 (UTC)
commit c8da56be317030103d50f1946a99baa199468864
Author: Aurélien Mino <aurelien mino gmail com>
Date: Sat May 15 15:25:26 2010 -0700
Read/write/load the MusicBrainzID properties
Read and write track, artist, and album IDs to files using TagLib#,
and store/load in the database properly (BGO #617967)
Signed-off-by: Gabriel Burt <gabriel burt gmail com>
.../Banshee.Core/Banshee.Collection/TrackInfo.cs | 8 +---
.../Banshee.Core/Banshee.Streaming/StreamTagger.cs | 6 +++
.../DatabaseAlbumInfo.cs | 13 ++++++
.../DatabaseArtistInfo.cs | 15 +++++++
.../DatabaseTrackInfo.cs | 42 +++++++++++++++++++-
5 files changed, 76 insertions(+), 8 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs b/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
index 2100ab5..51ef991 100644
--- a/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
+++ b/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
@@ -209,14 +209,10 @@ namespace Banshee.Collection
public virtual string MusicBrainzId { get; set; }
[Exportable]
- public virtual string ArtistMusicBrainzId {
- get { return null; }
- }
+ public virtual string ArtistMusicBrainzId { get; set; }
[Exportable]
- public virtual string AlbumMusicBrainzId {
- get { return null; }
- }
+ public virtual string AlbumMusicBrainzId { get; set; }
public virtual DateTime ReleaseDate { get; set; }
diff --git a/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs b/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs
index 90a41fb..ea4dd40 100644
--- a/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs
+++ b/src/Core/Banshee.Core/Banshee.Streaming/StreamTagger.cs
@@ -162,14 +162,17 @@ namespace Banshee.Streaming
track.ArtistName = Choose (file.Tag.JoinedPerformers, track.ArtistName, preferTrackInfo);
track.ArtistNameSort = Choose (file.Tag.JoinedPerformersSort, track.ArtistNameSort, preferTrackInfo);
+ track.ArtistMusicBrainzId = Choose (file.Tag.MusicBrainzArtistId, track.ArtistMusicBrainzId, preferTrackInfo);
track.AlbumTitle = Choose (file.Tag.Album, track.AlbumTitle, preferTrackInfo);
track.AlbumTitleSort = Choose (file.Tag.AlbumSort, track.AlbumTitleSort, preferTrackInfo);
+ track.AlbumMusicBrainzId = Choose (file.Tag.MusicBrainzReleaseId, track.AlbumMusicBrainzId, preferTrackInfo);
track.AlbumArtist = Choose (file.Tag.FirstAlbumArtist, track.AlbumArtist, preferTrackInfo);
track.AlbumArtistSort = Choose (file.Tag.FirstAlbumArtistSort, track.AlbumArtistSort, preferTrackInfo);
track.IsCompilation = preferTrackInfo ? track.IsCompilation : IsCompilation (file);
track.TrackTitle = Choose (file.Tag.Title, track.TrackTitle, preferTrackInfo);
track.TrackTitleSort = Choose (file.Tag.TitleSort, track.TrackTitleSort, preferTrackInfo);
+ track.MusicBrainzId = Choose (file.Tag.MusicBrainzTrackId, track.MusicBrainzId, preferTrackInfo);
track.Genre = Choose (file.Tag.FirstGenre, track.Genre, preferTrackInfo);
track.Composer = Choose (file.Tag.FirstComposer, track.Composer, preferTrackInfo);
track.Conductor = Choose (file.Tag.Conductor, track.Conductor, preferTrackInfo);
@@ -293,14 +296,17 @@ namespace Banshee.Streaming
file.Tag.PerformersSort = new string [] { track.ArtistNameSort };
file.Tag.Album = track.AlbumTitle;
file.Tag.AlbumSort = track.AlbumTitleSort;
+ file.Tag.MusicBrainzReleaseId = track.AlbumMusicBrainzId;
file.Tag.AlbumArtists = track.AlbumArtist == null ? new string [0] : new string [] {track.AlbumArtist};
file.Tag.AlbumArtistsSort = (track.AlbumArtistSort == null ? new string [0] : new string [] {track.AlbumArtistSort});
+ file.Tag.MusicBrainzArtistId = track.ArtistMusicBrainzId;
// Bug in taglib-sharp-2.0.3.0: Crash if you send it a genre of "{ null }"
// on a song with both ID3v1 and ID3v2 metadata. It's happy with "{}", though.
// (see http://forum.taglib-sharp.com/viewtopic.php?f=5&t=239 )
file.Tag.Genres = (track.Genre == null) ? new string[] {} : new string [] { track.Genre };
file.Tag.Title = track.TrackTitle;
file.Tag.TitleSort = track.TrackTitleSort;
+ file.Tag.MusicBrainzTrackId = track.MusicBrainzId;
file.Tag.Track = (uint)track.TrackNumber;
file.Tag.TrackCount = (uint)track.TrackCount;
file.Tag.Composers = new string [] { track.Composer };
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumInfo.cs
index d6db36d..e622f2c 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumInfo.cs
@@ -74,10 +74,16 @@ namespace Banshee.Collection.Database
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, 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);
}
@@ -129,6 +135,12 @@ namespace Banshee.Collection.Database
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 (save) {
last_album.Save ();
}
@@ -156,6 +168,7 @@ namespace Banshee.Collection.Database
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.Save ();
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistInfo.cs
index e3887ab..0a0fbfa 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistInfo.cs
@@ -72,9 +72,15 @@ namespace Banshee.Collection.Database
public static DatabaseArtistInfo FindOrCreate (string artistName, string artistNameSort)
{
+ return FindOrCreate (artistName, artistNameSort, null);
+ }
+
+ 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);
}
@@ -100,8 +106,16 @@ namespace Banshee.Collection.Database
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 {
@@ -121,6 +135,7 @@ namespace Banshee.Collection.Database
// Overwrite the found artist
artist.Name = found.Name;
artist.NameSort = found.NameSort;
+ artist.MusicBrainzId = found.MusicBrainzId;
artist.dbid = found.DbId;
artist.Save ();
}
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index c4fc5ea..2111f56 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -139,11 +139,13 @@ namespace Banshee.Collection.Database
}
public DatabaseArtistInfo Artist {
- get { return DatabaseArtistInfo.FindOrCreate (ArtistName, ArtistNameSort); }
+ get { return DatabaseArtistInfo.FindOrCreate (ArtistName, ArtistNameSort, ArtistMusicBrainzId); }
}
public DatabaseAlbumInfo Album {
- get { return DatabaseAlbumInfo.FindOrCreate (DatabaseArtistInfo.FindOrCreate (AlbumArtist, AlbumArtistSort), AlbumTitle, AlbumTitleSort, IsCompilation); }
+ get { return DatabaseAlbumInfo.FindOrCreate (
+ DatabaseArtistInfo.FindOrCreate (AlbumArtist, AlbumArtistSort, ArtistMusicBrainzId),
+ AlbumTitle, AlbumTitleSort, IsCompilation, AlbumMusicBrainzId); }
}
private static bool notify_saved = true;
@@ -394,6 +396,42 @@ namespace Banshee.Collection.Database
set { base.MusicBrainzId = value; }
}
+ [VirtualDatabaseColumn ("MusicBrainzID", "CoreAlbums", "AlbumID", "AlbumID")]
+ protected string AlbumMusicBrainzIdField {
+ get { return base.AlbumMusicBrainzId; }
+ set { base.AlbumMusicBrainzId = value; }
+ }
+
+ public override string AlbumMusicBrainzId {
+ get { return base.AlbumMusicBrainzId; }
+ set {
+ value = CleanseString (value, AlbumMusicBrainzId);
+ if (value == null)
+ return;
+
+ base.AlbumMusicBrainzId = value;
+ album_changed = true;
+ }
+ }
+
+ [VirtualDatabaseColumn ("MusicBrainzID", "CoreArtists", "ArtistID", "ArtistID")]
+ protected string ArtistMusicBrainzIdField {
+ get { return base.ArtistMusicBrainzId; }
+ set { base.ArtistMusicBrainzId = value; }
+ }
+
+ public override string ArtistMusicBrainzId {
+ get { return base.ArtistMusicBrainzId; }
+ set {
+ value = CleanseString (value, ArtistMusicBrainzId);
+ if (value == null)
+ return;
+
+ base.ArtistMusicBrainzId = value;
+ artist_changed = true;
+ }
+ }
+
[DatabaseColumn ("Uri")]
protected string UriField {
get { return Uri == null ? null : Uri.AbsoluteUri; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]