Re: [Banshee-List] Version 1.6



On Thu, Apr 2, 2009 at 5:26 PM, Gabriel Burt <gabriel burt gmail com> wrote:
> you want to help get 1.6 out faster by fixing bugs - checkout the code
> from svn - http://banshee-project.org/download/development

OK, here's a patch for an old pet peeve:

When importing a CD, the ID3 tag for release date is absent on the MP3s
(though Musicbrainz knows it and Banshee shows it in the "Year" column).

The reason is that Musicbrainz metadata XML supplies the date
as "YYYY-MM-DD", "YYYY-MM" or "YYYY", but it is parsed as

DateTime.Parse (release_event.Date, ApplicationContext.InternalCultureInfo)

I know of no culture that would use the above format :), hence this always
throws a parse exception (that is ignored), album.ReleaseDate is set to
DateTime.MinValue and hence ignored for tagging.

Note: If you test this with importing a CD to MP3, only the year of
the release will
show up in the ID3 tags though Musicbrainz may supply month and day.
Blame that on Gstreamer's id3v2mux element (or maybe it's actually taglib) that
throws away month and day :)

Cheers, Roderich
Index: src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdDiscModel.cs
===================================================================
--- src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdDiscModel.cs	(revision 5186)
+++ src/Extensions/Banshee.AudioCd/Banshee.AudioCd/AudioCdDiscModel.cs	(working copy)
@@ -30,6 +30,7 @@
 using System.Threading;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Text.RegularExpressions;
 
 using Mono.Unix;
 using MusicBrainz;
@@ -142,14 +143,27 @@
             
             DateTime release_date = DateTime.MaxValue;
  
+            // The MusicBrainz metadata schema 
+	    // (cf. http://musicbrainz.org/doc/MusicBrainzXMLMetaData)
+            // defines the format of a (release event) date as
+            // "YYYY-MM-DD", "YYYY-MM" or "YYYY".
+            Regex r = new Regex(@"^(\d{4})(-(\d{2}))?(-(\d{2}))?$", RegexOptions.None);
+
             foreach (Event release_event in release.GetEvents ()) {
                 if (release_event.Date != null) {
-                    try {
-                        DateTime date = DateTime.Parse (release_event.Date, ApplicationContext.InternalCultureInfo);
+                    Match m = r.Match(release_event.Date);
+                    if (m.Success) {
+                        string year = m.Groups[1].Value;
+                        string month = m.Groups[3].Value;
+                        string day = m.Groups[5].Value;
+  
+                        DateTime date = new DateTime(
+                            Convert.ToInt32(year),
+                            month.Length > 0 ? Convert.ToInt32(month) : 1,
+                            day.Length > 0 ? Convert.ToInt32(day) : 1);
                         if (date < release_date) {
                             release_date = date;
                         }
-                    } catch {
                     }
                 }
             }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]