[banshee/stable-2.4] Migo.Syndication: Handle feeds with malformed enclosure URLs



commit a1f3471557def3cfafc25c9daebb1bffa6562c48
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Wed May 16 18:22:47 2012 +0200

    Migo.Syndication: Handle feeds with malformed enclosure URLs
    
    When parsing an RSS feed, don't create an enclosure if the URL is empty.
    We were onyl considering when the URL is missing, but a present but
    empty value is just as useless.
    
    Catch exceptions when downloading an enclosure. This prevents us from
    crashing when we already have an empty enclosure URL in the database.
    
    Public announcement: Do yourselves a favor and go and read one of Cory
    Doctorow's books, available at http://craphound.com/

 .../Migo/Migo.Syndication/EnclosureManager.cs      |   34 +++++++++++---------
 src/Libraries/Migo/Migo.Syndication/RssParser.cs   |    6 ++-
 2 files changed, 23 insertions(+), 17 deletions(-)
---
diff --git a/src/Libraries/Migo/Migo.Syndication/EnclosureManager.cs b/src/Libraries/Migo/Migo.Syndication/EnclosureManager.cs
index 16e591f..31efc8d 100644
--- a/src/Libraries/Migo/Migo.Syndication/EnclosureManager.cs
+++ b/src/Libraries/Migo/Migo.Syndication/EnclosureManager.cs
@@ -117,21 +117,25 @@ namespace Migo.Syndication
                     Feed parentFeed = enclosure.Item.Feed;
 
                     if (parentFeed != null) {
-                        task = download_manager.CreateDownloadTask (enclosure.Url, enclosure);
-                        //Console.WriteLine ("Task DL path:  {0}", task.LocalPath);
-                        task.Name = String.Format ("{0} - {1}", parentFeed.Title, enclosure.Item.Title);
-
-                        //task.StatusChanged
-                        task.Completed += OnDownloadTaskCompletedHandler;
-
-                        // Race condition...
-                        // Should only be added when the task is associated or
-                        // it can be canceled before it is added to the progress manager.
-
-                        // Add a pre-association dict and move tasks to the
-                        // queued dict once they've been offically added.
-
-                        queued_downloads.Add (enclosure, task);
+                        try {
+                            task = download_manager.CreateDownloadTask (enclosure.Url, enclosure);
+                            //Console.WriteLine ("Task DL path:  {0}", task.LocalPath);
+                            task.Name = String.Format ("{0} - {1}", parentFeed.Title, enclosure.Item.Title);
+    
+                            //task.StatusChanged
+                            task.Completed += OnDownloadTaskCompletedHandler;
+    
+                            // Race condition...
+                            // Should only be added when the task is associated or
+                            // it can be canceled before it is added to the progress manager.
+    
+                            // Add a pre-association dict and move tasks to the
+                            // queued dict once they've been offically added.
+    
+                            queued_downloads.Add (enclosure, task);
+                        } catch (Exception e) {
+                            Log.Exception ("Could not download podcast enclosure", e);
+                        }
                     }
                 }
 
diff --git a/src/Libraries/Migo/Migo.Syndication/RssParser.cs b/src/Libraries/Migo/Migo.Syndication/RssParser.cs
index 994042d..9024120 100644
--- a/src/Libraries/Migo/Migo.Syndication/RssParser.cs
+++ b/src/Libraries/Migo/Migo.Syndication/RssParser.cs
@@ -193,8 +193,9 @@ namespace Migo.Syndication
                 FeedEnclosure enclosure = new FeedEnclosure ();
 
                 enclosure.Url = GetXmlNodeText (node, "enclosure/@url");
-                if (enclosure.Url == null)
+                if (String.IsNullOrEmpty (enclosure.Url)) {
                     return null;
+                }
 
                 enclosure.FileSize = Math.Max (0, GetInt64 (node, "enclosure/@length"));
                 enclosure.MimeType = GetXmlNodeText (node, "enclosure/@type");
@@ -236,8 +237,9 @@ namespace Migo.Syndication
 
                 FeedEnclosure enclosure = new FeedEnclosure ();
                 enclosure.Url = GetXmlNodeText (node, "@url");
-                if (enclosure.Url == null)
+                if (String.IsNullOrEmpty (enclosure.Url)) {
                     return null;
+                }
 
                 enclosure.FileSize = Math.Max (0, GetInt64 (node, "@fileSize"));
                 enclosure.MimeType = GetXmlNodeText (node, "@type");



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