4f7dd77
Index: lib/alexandria/book_providers/deastore.rb
4f7dd77
===================================================================
4f7dd77
--- lib/alexandria/book_providers/deastore.rb	(revision 1086)
4f7dd77
+++ lib/alexandria/book_providers/deastore.rb	(revision 1087)
4f7dd77
@@ -49,12 +49,18 @@
4f7dd77
       def get_book_from_search_result(result)
4f7dd77
         log.debug { "Fetching book from #{result[:url]}" }
4f7dd77
         html_data = agent.get(result[:url])
4f7dd77
+        #File.open("rsltflarn#{Time.now().usec()}.html", 'wb') do |f|
4f7dd77
+        #  f.write(html_data.body)
4f7dd77
+        #end
4f7dd77
         parse_result_data(html_data.body)
4f7dd77
       end
4f7dd77
 
4f7dd77
       def search(criterion, type)
4f7dd77
         criterion = criterion.convert("ISO-8859-1", "UTF-8") # still needed??
4f7dd77
         html_data = agent.get(create_search_uri(type, criterion))
4f7dd77
+        #File.open("flarn#{Time.now().usec()}.html", 'wb') do |f|
4f7dd77
+        #  f.write(html_data.body)
4f7dd77
+        #end
4f7dd77
         results = parse_search_result_data(html_data.body)
4f7dd77
         raise NoResultsError if results.empty?
4f7dd77
 
4f7dd77
@@ -89,7 +95,9 @@
4f7dd77
           search_term_encoded = CGI.escape(search_term)
4f7dd77
         end
4f7dd77
 
4f7dd77
-        BASE_SEARCH_URL % [search_type_code, search_term_encoded]
4f7dd77
+        uri = BASE_SEARCH_URL % [search_type_code, search_term_encoded]
4f7dd77
+        log.debug { uri }
4f7dd77
+        uri
4f7dd77
       end
4f7dd77
 
4f7dd77
       def parse_search_result_data(html)
4f7dd77
@@ -109,13 +117,21 @@
4f7dd77
             #  p Data di pubblicazione: \n     2009
4f7dd77
             #  p.prezzo (price)
4f7dd77
             
4f7dd77
-            cover_url = ''
4f7dd77
-            cover_images = div/'a/img'
4f7dd77
-            unless cover_images.empty?
4f7dd77
-              img = cover_images.first
4f7dd77
-              image_url = img['src']
4f7dd77
-              cover_url = "#{SITE}#{image_url}"
4f7dd77
-            end
4f7dd77
+#             cover_url = ''
4f7dd77
+#             cover_images = div/'a/img'
4f7dd77
+#             unless cover_images.empty?
4f7dd77
+#               img = cover_images.first
4f7dd77
+#               image_url = img['src']
4f7dd77
+#               if image_url =~ /^http/
4f7dd77
+#                 cover_url = '' # image_url
4f7dd77
+#               elsif image_url[0..0] != '/'
4f7dd77
+#                 cover_url = "#{SITE}/#{image_url}"
4f7dd77
+#               else
4f7dd77
+#                 cover_url = "#{SITE}#{image_url}"
4f7dd77
+#               end
4f7dd77
+#               log.debug { "Search Cover Image URL #{cover_url}" }
4f7dd77
+
4f7dd77
+#             end
4f7dd77
             
4f7dd77
             content = div/'div.scheda_content'
4f7dd77
             title_link = (content/:a).first
4f7dd77
@@ -167,12 +183,17 @@
4f7dd77
           end
4f7dd77
           
4f7dd77
           # author(s)
4f7dd77
+          authors = []
4f7dd77
           author_span = data%'span.int_scheda[text()*=Autore]'
4f7dd77
-          author_links = author_span/'a.info'
4f7dd77
-          authors = []
4f7dd77
-          author_links.each do |link|
4f7dd77
-            authors << normalize(link.inner_text)
4f7dd77
+          unless author_span
4f7dd77
+            author_span = data%'span.int_scheda[text()*=cura]' # editor
4f7dd77
           end
4f7dd77
+          if author_span
4f7dd77
+            author_links = author_span/'a.info'
4f7dd77
+            author_links.each do |link|
4f7dd77
+              authors << normalize(link.inner_text)
4f7dd77
+            end
4f7dd77
+          end
4f7dd77
 
4f7dd77
           # publisher
4f7dd77
           publisher_par = data%'span.int_scheda[text()*=Editore]/..'
4f7dd77
@@ -231,7 +252,19 @@
4f7dd77
           #cover
4f7dd77
           image_url = nil
4f7dd77
           if cover_link
4f7dd77
-            image_url = "#{SITE}#{cover_link}"
4f7dd77
+            if cover_link =~ /^http/
4f7dd77
+              # e.g. http://images.btol.com/ContentCafe/Jacket.aspx?\
4f7dd77
+              # Return=1&Type=M&Value=9788873641803&password=\
4f7dd77
+              # CC70580&userID=DEA40305
4f7dd77
+              # seems not to work, or to be blank anyway, so set to nil
4f7dd77
+              image_url = nil
4f7dd77
+            elsif cover_link[0..0] != '/'
4f7dd77
+              image_url = "#{SITE}/#{cover_link}"
4f7dd77
+            else
4f7dd77
+              image_url = "#{SITE}#{cover_link}"
4f7dd77
+            end
4f7dd77
+
4f7dd77
+            log.debug { "Cover Image URL:: #{image_url}" }
4f7dd77
           end
4f7dd77
 
4f7dd77
           book = Book.new(title, authors, isbn, publisher, publish_year, binding)
4f7dd77
@@ -239,7 +272,7 @@
4f7dd77
           return [book, image_url]
4f7dd77
         rescue Exception => ex
4f7dd77
           trace = ex.backtrace.join("\n> ")
4f7dd77
-          log.error { "Failed parsing Siciliano product page #{ex.message}\n#{trace}" }
4f7dd77
+          log.error { "Failed parsing DeaStore product page #{ex.message}\n#{trace}" }
4f7dd77
           return nil        
4f7dd77
         end
4f7dd77
       end