banshee r3941 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Metadata src/Core/Banshee.Services/Banshee.Metadata.MusicBrainz src/Core/Banshee.Services/Banshee.Metadata.Rhapsody



Author: abock
Date: Wed May 21 19:36:22 2008
New Revision: 3941
URL: http://svn.gnome.org/viewvc/banshee?rev=3941&view=rev

Log:
2008-05-21  Aaron Bockover  <abock gnome org>

    * src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs:
    Return the full HttpWebResponse instead of the response stream

    * src/Core/Banshee.Services/Banshee.Metadata.MusicBrainz/MusicBrainzQueryJob.cs:
    Updated to reflect API change above

    * src/Core/Banshee.Services/Banshee.Metadata.Rhapsody/RhapsodyQueryJob.cs:
    Updated to reflect API change above and to check the content type on
    the response to ensure it's text/xml - Rhapsody now redirects to the
    best-match HTML page if there is no exact match - before they just gave
    a 404 response



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.MusicBrainz/MusicBrainzQueryJob.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Rhapsody/RhapsodyQueryJob.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.MusicBrainz/MusicBrainzQueryJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.MusicBrainz/MusicBrainzQueryJob.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.MusicBrainz/MusicBrainzQueryJob.cs	Wed May 21 19:36:22 2008
@@ -111,27 +111,34 @@
             Uri uri = new Uri(String.Format("http://musicbrainz.org/ws/1/release/?type=xml&artist={0}&title={1}";,
                 Track.ArtistName, Track.AlbumTitle));
 
-            XmlTextReader reader = new XmlTextReader(GetHttpStream(uri));
-
-            bool haveMatch = false;
+            HttpWebResponse response = GetHttpStream(uri);
+            if (response == null) {
+                return null;
+            }
             
-            while(reader.Read()) {
-                if(reader.NodeType == XmlNodeType.Element) {
-                    switch (reader.LocalName) {
-                        case "release":
-                            haveMatch = reader["ext:score"] == "100";
+            using (Stream stream = response.GetResponseStream ()) {
+                XmlTextReader reader = new XmlTextReader(stream);
+    
+                bool haveMatch = false;
+                
+                while(reader.Read()) {
+                    if(reader.NodeType == XmlNodeType.Element) {
+                        switch (reader.LocalName) {
+                            case "release":
+                                haveMatch = reader["ext:score"] == "100";
+                                break;
+                            case "asin":
+                                if(haveMatch) {
+                                    return reader.ReadString();
+                                }
+                            break;
+                        default:
                             break;
-                        case "asin":
-                            if(haveMatch) {
-                                return reader.ReadString();
-                            }
-                        break;
-                    default:
-                        break;
+                        }
                     }
                 }
             }
-
+            
             return null;
         }
     }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Rhapsody/RhapsodyQueryJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Rhapsody/RhapsodyQueryJob.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata.Rhapsody/RhapsodyQueryJob.cs	Wed May 21 19:36:22 2008
@@ -68,13 +68,18 @@
             Uri data_uri = new Uri(base_uri, String.Format("/{0}/data.xml", artwork_id.Replace('-', '/')));
         
             XmlDocument doc = new XmlDocument();
-            Stream stream = GetHttpStream(data_uri);
-            if(stream == null) {
+            HttpWebResponse response = GetHttpStream (data_uri);
+            if (response == null) {
                 return;
             }
-
-            using(stream) {
-                doc.Load(stream);
+            
+            string [] content_types = response.Headers.GetValues ("Content-Type");
+            if (content_types.Length == 0 || content_types[0] != "text/xml") {
+                return;
+            }
+            
+            using (Stream stream = response.GetResponseStream ()) {
+                doc.Load (stream);
             }
 
             XmlNode art_node = doc.DocumentElement.SelectSingleNode("/album/art/album-art[ size='large']/img");

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Metadata/MetadataServiceJob.cs	Wed May 21 19:36:22 2008
@@ -85,12 +85,12 @@
             tags.Add(tag);
         }
         
-        protected Stream GetHttpStream(Uri uri)
+        protected HttpWebResponse GetHttpStream(Uri uri)
         {
             return GetHttpStream(uri, null);
         }
 
-        protected Stream GetHttpStream(Uri uri, string [] ignoreMimeTypes)
+        protected HttpWebResponse GetHttpStream(Uri uri, string [] ignoreMimeTypes)
         {
             if(!NetworkDetect.Instance.Connected) {
                 throw new NetworkUnavailableException();
@@ -117,7 +117,7 @@
                 }
             }
             
-            return response.GetResponseStream();
+            return response;
         }
         
         protected bool SaveHttpStream(Uri uri, string path)
@@ -127,8 +127,12 @@
         
         protected bool SaveHttpStream(Uri uri, string path, string [] ignoreMimeTypes)
         {
-            Stream from_stream = GetHttpStream(uri, ignoreMimeTypes);
+            HttpWebResponse response = GetHttpStream(uri, ignoreMimeTypes);
+            Stream from_stream = response == null ? null : response.GetResponseStream ();
             if(from_stream == null) {
+                if (response != null) {
+                    response.Close ();
+                }
                 return false;
             }
             
@@ -139,6 +143,8 @@
                 FileMode.Create, FileAccess.ReadWrite));
                 
             Banshee.IO.File.Move (new SafeUri (tmp_path), new SafeUri (path));
+            
+            from_stream.Close ();
                 
             return true;
         }



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