[Muine] Multi-disc albums



On freedb.org, double albums usually have something like "Disc One" and "Disc Two" appended to their titles for the respective discs. Now, if the freedb.org catalogue is used to tag audio files, the album title in the tags will no longer match the album title on Amazon.

Attached is a patch that, in the case where no matches are made on a search, looks to see if the title ends in something like "disc one". If it does, it removes it and searches again. Of course, this results in another query to Amazon, but it should happen rarely enough that performance won't suffer.

--
Peter Oliver
diff -rup muine.old/src/CoverDatabase.cs muine/src/CoverDatabase.cs
--- muine.old/src/CoverDatabase.cs	2004-10-23 16:25:27.000000000 +0100
+++ muine/src/CoverDatabase.cs	2004-10-25 22:44:51.771528319 +0100
@@ -353,9 +353,6 @@ public class CoverDatabase 
 
 		string sane_album_title = SanitizeString (song.Album);
 
-		string [] album_title_array = sane_album_title.Split (' ');
-		Array.Sort (album_title_array);
-
 		/* This assumes the right artist is always in Artists [0] */
 		string sane_artist = SanitizeString (song.Artists [0]);
 		
@@ -413,7 +410,24 @@ public class CoverDatabase 
 				search_service.Proxy = proxy.Proxy;
 			
 			/* This may throw an exception, we catch it in Song.cs in the calling function */
-			pi = search_service.ArtistSearchRequest (asearch);
+			try {
+				pi = search_service.ArtistSearchRequest (asearch);
+			}
+			catch (System.Web.Services.Protocols.SoapException e) {
+				/* Try to remove text such as "disc 1" from the end of the album title and search again if successful */
+				string truncated_album_title =  Regex.Replace (sane_album_title, Muine.Catalog.GetString (@"[,:]?\s*(cd|dis[ck])\s*(\d+|one|two|three|four|five|six|seven|eight|nine|ten)\s*$"), "", RegexOptions.IgnoreCase);
+				Console.WriteLine( truncated_album_title );
+				if ( truncated_album_title == sane_album_title ) {
+					throw e;
+				}
+				else {
+					sane_album_title = asearch.keywords = truncated_album_title;
+					pi = search_service.ArtistSearchRequest (asearch);
+				}
+			}
+
+			string [] album_title_array = sane_album_title.Split (' ');
+			Array.Sort (album_title_array);
 
 			int num_results = pi.Details.Length;
 			total_pages = Convert.ToInt32 (pi.TotalPages);


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