contrib/rss_downloader: move tag link to Config
[nit.git] / contrib / rss_downloader / src / rss_downloader.nit
index e662fac..3551686 100644 (file)
@@ -52,6 +52,9 @@ class Config
        # XML tag used for pattern recognition
        fun tag_title: String do return "title"
 
+       # XML tag of the link to act upon
+       fun tag_link: String do return "link"
+
        # Action to apply on each selected RSS element
        fun act_on(element: Element)
        do
@@ -151,11 +154,7 @@ class Downloader
                for element in matches do
                        var unique_id = element.unique_id(config)
 
-                       if local_path.to_path.exists then
-                               # Do not redownload a file (we assume that the file name is unique by itself)
-                               if sys.verbose then print "File exists, skipping {element}"
-                               continue
-                       else if history.has(unique_id) then
+                       if history.has(unique_id) then
                                # Do not download a file that is not unique according to `unique_id`
                                if not element.is_unique_exception(config) then
                                        # We make some exceptions
@@ -203,7 +202,7 @@ class Downloader
                        end
 
                        for dir in source_folder.files do if dir.stat.is_dir then
-                               folder_names.add dir.to_s
+                               folder_names.add dir.filename
                        end
                end
 
@@ -260,12 +259,16 @@ redef class Text
        fun to_rss_elements: Array[Element]
        do
                var xml = to_xml
+               if xml isa XMLError then
+                       print_error "RSS Parse Error: {xml.message}:{xml.location or else "null"}"
+                       return new Array[Element]
+               end
                var items = xml["rss"].first["channel"].first["item"]
 
                var elements = new Array[Element]
                for item in items do
                        var title = item[tool_config.tag_title].first.as(XMLStartTag).data
-                       var link = item["link"].first.as(XMLStartTag).data
+                       var link = item[tool_config.tag_link].first.as(XMLStartTag).data
 
                        elements.add new Element(title, link)
                end