#1866: Support pixiv small "_s" thumbnail source rewriting

This commit is contained in:
Toks
2013-11-26 14:36:39 -05:00
parent 306c4e6900
commit 940909ca9c
3 changed files with 4217 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ module Downloads
if url =~ /https?:\/\/(?:\w+\.)?pixiv\.net/
url, headers = rewrite_headers(url, headers)
url, headers = rewrite_html_pages(url, headers)
url, headers = rewrite_small_images(url, headers)
url, headers = rewrite_small_and_medium_images(url, headers)
url, headers = rewrite_small_manga_pages(url, headers)
end
@@ -30,10 +30,13 @@ module Downloads
end
end
def rewrite_small_images(url, headers)
def rewrite_small_and_medium_images(url, headers)
if url =~ %r!(/img/.+?/.+?)_m.+$!
match = $1
url.sub!(match + "_m", match)
elsif url =~ %r!(/img/.+?/.+?)_s.+$!
match = $1
url.sub!(match + "_s", match)
end
return [url, headers]

File diff suppressed because it is too large Load Diff

View File

@@ -29,13 +29,13 @@ module Downloads
end
should "work" do
assert_equal(185778, ::File.size(@tempfile.path))
assert_equal(185_778, ::File.size(@tempfile.path))
end
end
context "a download for a small image" do
context "a download for a small image thumbnail" do
setup do
@source = "http://img02.pixiv.net/img/wanwandoh/4348318_m.jpg"
@source = "http://img02.pixiv.net/img/wanwandoh/4348318_s.jpg"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
VCR.use_cassette("download-pixiv-small", :record => :new_episodes) do
@@ -48,7 +48,26 @@ module Downloads
end
should "work" do
assert_equal(185778, ::File.size(@tempfile.path))
assert_equal(185_778, ::File.size(@tempfile.path))
end
end
context "a download for a medium image thumbnail" do
setup do
@source = "http://img02.pixiv.net/img/wanwandoh/4348318_m.jpg"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
VCR.use_cassette("download-pixiv-medium", :record => :new_episodes) do
@download.download!
end
end
should "instead download the original version" do
assert_equal("http://img02.pixiv.net/img/wanwandoh/4348318.jpg", @download.source)
end
should "work" do
assert_equal(185_778, ::File.size(@tempfile.path))
end
end
end