From c75d2d208eb9ed6d9e364003456ab40ee884fd3f Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 5 Oct 2014 12:13:38 -0500 Subject: [PATCH] normalize_for_artist_finder!: Don't crash on bad URLs If we can't normalize the URL (because of bad IDs, it's malformed, or the HTML page changed), just return the unnormalized URL. --- app/logical/sources/site.rb | 8 +++++++- app/logical/sources/strategies/pixiv.rb | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/logical/sources/site.rb b/app/logical/sources/site.rb index 9c13ba32b..933a32050 100644 --- a/app/logical/sources/site.rb +++ b/app/logical/sources/site.rb @@ -1,6 +1,8 @@ # encoding: UTF-8 module Sources + class Error < Exception ; end + class Site attr_reader :url, :strategy delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :to => :strategy @@ -22,7 +24,11 @@ module Sources def normalize_for_artist_finder! if available? - return strategy.normalize_for_artist_finder! + begin + return strategy.normalize_for_artist_finder! + rescue Sources::Error + return url + end else return url end diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index 7f55679b4..67d107c82 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -149,7 +149,7 @@ module Sources if not stacc_link.nil? stacc_link.attr("href").sub(%r!^/stacc/!i, '') else - raise "Couldn't find Pixiv moniker in page: #{normalized_url}" + raise Sources::Error.new("Couldn't find Pixiv moniker in page: #{normalized_url}") end end @@ -162,7 +162,7 @@ module Sources thumbnail_url = elements.first.attr("src") return rewrite_thumbnails(thumbnail_url, is_manga) else - raise "Couldn't find image thumbnail URL in page: #{normalized_url}" + raise Sources::Error.new("Couldn't find image thumbnail URL in page: #{normalized_url}") end end @@ -217,7 +217,7 @@ module Sources metadata = CSV.parse(response.content.force_encoding("UTF-8")).first if metadata.nil? - raise "Couldn't get Pixiv API metadata from #{spapi_url}." + raise Sources::Error.new("Couldn't get Pixiv API metadata from #{spapi_url}.") else yield metadata end @@ -255,7 +255,7 @@ module Sources $1 else - raise "Couldn't get illust ID from URL: #{url}" + raise Sources::Error.new("Couldn't get illust ID from URL: #{url}") end end