[banshee/bug-520516_nonascii-cover-art] Support cover art in tracks with non-ASCII metadata.



commit c00b72ab98a9cf7fde9e84635ef869335ce1ec32
Author: John Millikin <jmillikin gmail com>
Date:   Fri Apr 17 18:40:44 2009 -0700

    Support cover art in tracks with non-ASCII metadata.
---
 src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs |   25 +++++++++++--------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs b/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs
index 0f065a6..a151901 100644
--- a/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs
+++ b/src/Core/Banshee.Core/Banshee.Base/CoverArtSpec.cs
@@ -29,6 +29,7 @@
 using System;
 using System.IO;
 using System.Text.RegularExpressions;
+using System.Security.Cryptography; 
 
 using Mono.Unix;
 
@@ -65,7 +66,7 @@ namespace Banshee.Base
         {
             return size == 0
                 ? Path.Combine (RootPath, String.Format ("{0}.jpg", aaid))
-                : Path.Combine (RootPath, Path.Combine (size.ToString (), String.Format ("{0}.jpg", aaid))); 
+                : Path.Combine (RootPath, Path.Combine (size.ToString (), String.Format ("{0}.jpg", aaid)));
         }
     
         public static string CreateArtistAlbumId (string artist, string album)
@@ -75,16 +76,16 @@ namespace Banshee.Base
 
         public static string CreateArtistAlbumId (string artist, string album, bool asUriPart)
         {
-            if (artist == unknown_artist || artist == unknown_artist_tr || album == unknown_album || album == unknown_album_tr) {
+            if (artist == unknown_artist ||
+                artist == unknown_artist_tr ||
+                album == unknown_album ||
+                album == unknown_album_tr ||
+                String.IsNullOrEmpty (artist) ||
+                String.IsNullOrEmpty (album)) {
                 return null;
             }
-
-            string sm_artist = EscapePart (artist);
-            string sm_album = EscapePart (album);
-
-            return String.IsNullOrEmpty (sm_artist) || String.IsNullOrEmpty (sm_album)
-                ? null 
-                : String.Format ("{0}{1}{2}", sm_artist, asUriPart ? "/" : "-", sm_album); 
+            
+            return EscapePart (String.Format ("{0}\x00{1}", artist, album));
         }
         
         public static string EscapePart (string part)
@@ -98,8 +99,10 @@ namespace Banshee.Base
                 part = part.Substring (0, lp_index);
             }
             
-            // TODO compile regex
-            return Regex.Replace (part, @"[^A-Za-z0-9]*", "").ToLower ();
+            byte[] part_bytes = System.Text.Encoding.UTF8.GetBytes (part.ToLower ());
+            HashAlgorithm hash = (HashAlgorithm) SHA1.Create ();
+            byte[] digest = hash.ComputeHash (part_bytes);
+            return BitConverter.ToString (digest).Replace ("-", "").ToLower ();
         }
         
         private static string root_path = Path.Combine (XdgBaseDirectorySpec.GetUserDirectory (



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