pixiv: fixup bugs in 1c620f805.
* Fix error when uploading non-ugoira files. * Fix sample image URLs not being rewritten to full images correctly. We have to get the full image URL from the API because given an /img-master/ URL, we don't know what the original file extension is.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
module Source
|
||||
class URL::Pixiv < Source::URL
|
||||
attr_reader :work_id, :page, :username, :user_id, :full_image_url
|
||||
attr_reader :work_id, :page, :username, :user_id
|
||||
|
||||
def self.match?(url)
|
||||
return false if Source::URL::Fanbox.match?(url) || Source::URL::PixivSketch.match?(url)
|
||||
@@ -30,19 +30,12 @@ module Source
|
||||
in *, ("img-original" | "img-master" | "img-zip-ugoira" | "img-inf" | "custom-thumb"), "img", year, month, day, hour, min, sec, file if image_url?
|
||||
parse_filename
|
||||
|
||||
if work_id.present? && is_ugoira?
|
||||
@full_image_url = "https://i.pximg.net/img-zip-ugoira/img/#{year}/#{month}/#{day}/#{hour}/#{min}/#{sec}/#{work_id}_ugoira1920x1080.zip"
|
||||
elsif work_id.present? && page.present? && file_ext.present?
|
||||
@full_image_url = "https://i.pximg.net/img-original/img/#{year}/#{month}/#{day}/#{hour}/#{min}/#{sec}/#{work_id}_p#{page}.#{file_ext}"
|
||||
end
|
||||
|
||||
# http://img18.pixiv.net/img/evazion/14901720.png
|
||||
# http://i2.pixiv.net/img18/img/evazion/14901720.png
|
||||
# http://i1.pixiv.net/img07/img/pasirism/18557054_p1.png
|
||||
in *, "img", username, file if image_url?
|
||||
parse_filename
|
||||
@username = username
|
||||
@full_image_url = url # XXX these URLs all return 404, so we can't convert them to a working full image URL.
|
||||
|
||||
# https://www.pixiv.net/en/artworks/46324488
|
||||
# https://www.pixiv.net/artworks/46324488
|
||||
@@ -90,7 +83,7 @@ module Source
|
||||
# http://i1.pixiv.net/img07/img/pasirism/18557054_p1.png
|
||||
in /^\d+$/ => work_id, /^p\d+$/ => page, *rest
|
||||
@work_id = work_id
|
||||
@page = page.delete_prefix("p")
|
||||
@page = page.delete_prefix("p").to_i
|
||||
|
||||
# https://i.pximg.net/img-original/img/2019/05/27/17/59/33/74932152_ugoira0.jpg
|
||||
# https://i.pximg.net/img-zip-ugoira/img/2016/04/09/14/25/29/56268141_ugoira1920x1080.zip
|
||||
|
||||
@@ -41,10 +41,12 @@ module Sources
|
||||
end
|
||||
|
||||
def image_urls
|
||||
if parsed_url.image_url?
|
||||
[parsed_url.full_image_url]
|
||||
elsif is_ugoira?
|
||||
if is_ugoira?
|
||||
[api_ugoira[:originalSrc]]
|
||||
elsif parsed_url.image_url? && parsed_url.page
|
||||
[original_urls[parsed_url.page]]
|
||||
elsif parsed_url.image_url?
|
||||
[parsed_url.to_s]
|
||||
else
|
||||
original_urls
|
||||
end
|
||||
@@ -122,7 +124,7 @@ module Sources
|
||||
|
||||
def download_file!(url = image_url)
|
||||
file = super(url)
|
||||
file.frame_data = ugoira_frame_data
|
||||
file.frame_data = ugoira_frame_data if is_ugoira?
|
||||
file
|
||||
end
|
||||
|
||||
@@ -169,7 +171,6 @@ module Sources
|
||||
end
|
||||
|
||||
def ugoira_frame_data
|
||||
return nil unless is_ugoira?
|
||||
api_ugoira[:frames]
|
||||
end
|
||||
|
||||
|
||||
@@ -58,10 +58,10 @@ module Downloads
|
||||
|
||||
assert_rewritten(@p0_full_size_image, @medium_page)
|
||||
assert_rewritten(@p0_full_size_image, @manga_page)
|
||||
assert_rewritten(@p1_full_size_image, @manga_big_p1_page)
|
||||
assert_rewritten(@p0_full_size_image, @manga_big_p1_page)
|
||||
assert_downloaded(@p0_file_size, @medium_page)
|
||||
assert_downloaded(@p0_file_size, @manga_page)
|
||||
assert_downloaded(@p1_file_size, @manga_big_p1_page)
|
||||
assert_downloaded(@p0_file_size, @manga_big_p1_page)
|
||||
end
|
||||
|
||||
should "download the full size image instead of the thumbnail" do
|
||||
|
||||
Reference in New Issue
Block a user