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
|
||||
|
||||
def image_urls
|
||||
urls = []
|
||||
return urls if api_client&.api_response.blank?
|
||||
|
||||
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?
|
||||
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?
|
||||
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
|
||||
urls
|
||||
end
|
||||
|
||||
def image_url
|
||||
return url if image_urls.blank? || api_client.blank?
|
||||
def image_url_for(url)
|
||||
return url if api_client.blank?
|
||||
|
||||
img = case 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)
|
||||
resp = api_client.login.head(url)
|
||||
if resp.uri.to_s =~ %r{https?://.+/(\w+/\d+/\d+)\z}i
|
||||
"https://lohas.nicoseiga.jp/priv/#{$1}"
|
||||
else
|
||||
img
|
||||
url
|
||||
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_2.image_url)
|
||||
|
||||
expected = %w[
|
||||
https://seiga.nicovideo.jp/image/source/10315315
|
||||
https://seiga.nicovideo.jp/image/source/10315318
|
||||
https://seiga.nicovideo.jp/image/source/10315319
|
||||
https://seiga.nicovideo.jp/image/source/10315320
|
||||
https://seiga.nicovideo.jp/image/source/10315321
|
||||
https://seiga.nicovideo.jp/image/source/10315322
|
||||
https://seiga.nicovideo.jp/image/source/10315323
|
||||
https://seiga.nicovideo.jp/image/source/10315324
|
||||
https://seiga.nicovideo.jp/image/source/10315316
|
||||
expected = [
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315315},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315318},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315319},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315320},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315321},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315322},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315323},
|
||||
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10315324},
|
||||
%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
|
||||
|
||||
should "get the canonical url" do
|
||||
|
||||
Reference in New Issue
Block a user