uploads: fix NicoSeiga sources not working.
Fix uploads for NicoSeiga sources not working because the strategy
returned URLs like the one below in the list of image_urls, which
require a login to download:
https://seiga.nicovideo.jp/image/source/10315315
Also fix certain URLs like https://dic.nicovideo.jp/oekaki/52833.png not
working, because they didn't contain an image ID and the image_urls
method returned an empty list in this case.
This commit is contained in:
@@ -65,33 +65,25 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_urls
|
def image_urls
|
||||||
urls = []
|
|
||||||
return urls if api_client&.api_response.blank?
|
|
||||||
|
|
||||||
if image_id.present?
|
if image_id.present?
|
||||||
urls << "https://seiga.nicovideo.jp/image/source/#{image_id}"
|
[image_url_for("https://seiga.nicovideo.jp/image/source/#{image_id}")]
|
||||||
elsif illust_id.present?
|
elsif illust_id.present?
|
||||||
urls << "https://seiga.nicovideo.jp/image/source/#{illust_id}"
|
[image_url_for("https://seiga.nicovideo.jp/image/source/#{illust_id}")]
|
||||||
elsif manga_id.present? && api_client.image_ids.present?
|
elsif manga_id.present? && api_client.image_ids.present?
|
||||||
urls += api_client.image_ids.map { |id| "https://seiga.nicovideo.jp/image/source/#{id}" }
|
api_client.image_ids.map { |id| image_url_for("https://seiga.nicovideo.jp/image/source/#{id}") }
|
||||||
|
else
|
||||||
|
[image_url_for(url)]
|
||||||
end
|
end
|
||||||
urls
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_url
|
def image_url_for(url)
|
||||||
return url if image_urls.blank? || api_client.blank?
|
return url if api_client.blank?
|
||||||
|
|
||||||
img = case url
|
resp = api_client.login.head(url)
|
||||||
when DIRECT || CDN_DIRECT then "https://seiga.nicovideo.jp/image/source/#{image_id_from_url(url)}"
|
|
||||||
when SOURCE then url
|
|
||||||
else image_urls.first
|
|
||||||
end
|
|
||||||
|
|
||||||
resp = api_client.login.head(img)
|
|
||||||
if resp.uri.to_s =~ %r{https?://.+/(\w+/\d+/\d+)\z}i
|
if resp.uri.to_s =~ %r{https?://.+/(\w+/\d+/\d+)\z}i
|
||||||
"https://lohas.nicoseiga.jp/priv/#{$1}"
|
"https://lohas.nicoseiga.jp/priv/#{$1}"
|
||||||
else
|
else
|
||||||
img
|
url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -37,19 +37,20 @@ module Sources
|
|||||||
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_1.image_url)
|
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_1.image_url)
|
||||||
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_2.image_url)
|
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_2.image_url)
|
||||||
|
|
||||||
expected = %w[
|
expected = [
|
||||||
https://seiga.nicovideo.jp/image/source/10315315
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315315},
|
||||||
https://seiga.nicovideo.jp/image/source/10315318
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315318},
|
||||||
https://seiga.nicovideo.jp/image/source/10315319
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315319},
|
||||||
https://seiga.nicovideo.jp/image/source/10315320
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315320},
|
||||||
https://seiga.nicovideo.jp/image/source/10315321
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315321},
|
||||||
https://seiga.nicovideo.jp/image/source/10315322
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315322},
|
||||||
https://seiga.nicovideo.jp/image/source/10315323
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315323},
|
||||||
https://seiga.nicovideo.jp/image/source/10315324
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315324},
|
||||||
https://seiga.nicovideo.jp/image/source/10315316
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315316},
|
||||||
]
|
]
|
||||||
assert_equal(expected.sort, @site_3.image_urls.sort)
|
|
||||||
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_3.image_url)
|
assert_equal(9, @site_3.image_urls.size)
|
||||||
|
9.times { |n| assert_match(expected[n], @site_3.image_urls[n]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
should "get the canonical url" do
|
should "get the canonical url" do
|
||||||
|
|||||||
Reference in New Issue
Block a user