fix bug with source::site

This commit is contained in:
r888888888
2017-11-17 17:26:33 -08:00
parent c0ddf266fc
commit 3c524aa5e6
6 changed files with 10 additions and 13 deletions

View File

@@ -6,7 +6,7 @@ div.list-of-forum-posts {
} }
article { article {
border: 1px solid #999; border: 1px solid #AAA;
margin: 1em 0em; margin: 1em 0em;
word-wrap: break-word; word-wrap: break-word;
box-shadow: 1px 1px 2px #AAA; box-shadow: 1px 1px 2px #AAA;

View File

@@ -18,7 +18,6 @@ module Downloads
protected protected
def rewrite_html_url(url, headers) def rewrite_html_url(url, headers)
return [url, headers] unless Sources::Strategies::ArtStation.url_match?(url) return [url, headers] unless Sources::Strategies::ArtStation.url_match?(url)
source = Sources::Site.new(url) source = Sources::Site.new(url)
source.get source.get
[source.image_url, headers] [source.image_url, headers]

View File

@@ -17,16 +17,14 @@ module Sources
end end
def initialize(url, referer_url: nil) def initialize(url, referer_url: nil)
@url = url
Site.strategies.each do |strategy| Site.strategies.each do |strategy|
if strategy.url_match?(url) || strategy.url_match?(referer_url) if strategy.url_match?(url) || strategy.url_match?(referer_url)
@strategy = strategy.new(url, referer_url) @strategy = strategy.new(url, referer_url)
break return
end end
raise NoStrategyError.new
end end
raise NoStrategyError.new
end end
def referer_url def referer_url

View File

@@ -6,9 +6,9 @@ module Sources::Strategies
self.project_id(url).present? self.project_id(url).present?
end end
# https://www.artstation.com/artwork/04XA4" # https://www.artstation.com/artwork/04XA4
# https://dantewontdie.artstation.com/projects/YZK5q" # https://dantewontdie.artstation.com/projects/YZK5q
# https://www.artstation.com/artwork/cody-from-sf" # https://www.artstation.com/artwork/cody-from-sf
def self.project_id(url) def self.project_id(url)
if url =~ %r!\Ahttps?://\w+\.artstation\.com/(?:artwork|projects)/(?<project_id>[a-z0-9-]+)\z!i if url =~ %r!\Ahttps?://\w+\.artstation\.com/(?:artwork|projects)/(?<project_id>[a-z0-9-]+)\z!i
$~[:project_id] $~[:project_id]

View File

@@ -11,7 +11,7 @@ module Downloads
end end
should "download the large image instead" do should "download the large image instead" do
assert_equal("https://cdnb3.artstation.com/p/assets/images/images/003/716/071/original/aoi-ogata-hate-city.jpg?1476754974", @download.source) assert_equal("https://cdnb3.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974", @download.source)
end end
end end
@@ -37,7 +37,7 @@ module Downloads
end end
should "download the original image instead" do should "download the original image instead" do
assert_equal("https://cdna.artstation.com/p/assets/images/images/006/066/534/original/yinan-cui-reika.jpg?1495781565", @download.source) assert_equal("https://cdna.artstation.com/p/assets/images/images/006/066/534/large/yinan-cui-reika.jpg?1495781565", @download.source)
end end
end end
end end

View File

@@ -11,7 +11,7 @@ module Downloads
end end
should "set the html page as the source" do should "set the html page as the source" do
assert_equal("http://orig00.deviantart.net/82ef/f/2016/271/7/1/aaaaaa_by_starbitt-daj8b46.gif", @download.source) assert_equal("https://orig00.deviantart.net/82ef/f/2016/271/7/1/aaaaaa_by_starbitt-daj8b46.gif", @download.source)
end end
should "work" do should "work" do