Nicoseiga: rewrite tests and fix several bugs
* Fixed a bug where manga posts with a single tag would raise an error * Fixed a bug where dic.nicovideo.jp/oekaki posts weren't uploadable due to SSL issues * Added support for more manga corner cases
This commit is contained in:
@@ -40,7 +40,7 @@ module Danbooru
|
|||||||
attr_accessor :max_size, :http
|
attr_accessor :max_size, :http
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
delegate :get, :head, :put, :post, :delete, :cache, :follow, :max_size, :timeout, :auth, :basic_auth, :headers, :cookies, :use, :public_only, :download_media, to: :new
|
delegate :get, :head, :put, :post, :delete, :cache, :follow, :max_size, :timeout, :auth, :basic_auth, :headers, :cookies, :use, :public_only, :with_legacy_ssl, :download_media, to: :new
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@@ -136,6 +136,18 @@ module Danbooru
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# allow requests to sites using unsafe legacy renegotiations (such as dic.nicovideo.jp)
|
||||||
|
# see https://github.com/openssl/openssl/commit/72d2670bd21becfa6a64bb03fa55ad82d6d0c0f3
|
||||||
|
def with_legacy_ssl
|
||||||
|
dup.tap do |o|
|
||||||
|
o.http = o.http.dup.tap do |http|
|
||||||
|
ctx = OpenSSL::SSL::SSLContext.new
|
||||||
|
ctx.options |= OpenSSL::SSL::OP_LEGACY_SERVER_CONNECT
|
||||||
|
http.default_options = http.default_options.with_ssl_context(ctx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
concerning :DownloadMethods do
|
concerning :DownloadMethods do
|
||||||
# Download a file from `url` and return a {MediaFile}.
|
# Download a file from `url` and return a {MediaFile}.
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -19,12 +19,7 @@ class NicoSeigaApiClient
|
|||||||
when "illust"
|
when "illust"
|
||||||
[api_response["id"]]
|
[api_response["id"]]
|
||||||
when "manga"
|
when "manga"
|
||||||
manga_api_response.map do |x|
|
manga_api_response.map { |x| Source::URL.parse(x.dig("meta", "source_url"))&.image_id }.compact
|
||||||
case x["meta"]["source_url"]
|
|
||||||
when %r{/thumb/(\d+)\w}i then Regexp.last_match(1)
|
|
||||||
when %r{nicoseiga\.cdn\.nimg\.jp/drm/image/\w+/(\d+)\w}i then Regexp.last_match(1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,11 +32,21 @@ class NicoSeigaApiClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
api_response.dig("tag_list", "tag").to_a.map { |t| t["name"] }.compact
|
tags = api_response.dig("tag_list", "tag")
|
||||||
|
if tags.instance_of? Hash
|
||||||
|
# When a manga post has a single tag, the XML parser thinks it's a hash instead of an array of hashes,
|
||||||
|
# so we need to manually turn it into the latter. Example: https://seiga.nicovideo.jp/watch/mg302561
|
||||||
|
tags = [tags]
|
||||||
|
end
|
||||||
|
tags.to_a.map { |t| t["name"] }.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_id
|
def user_id
|
||||||
api_response["user_id"]
|
if api_response["user_id"].to_i == 0 # anonymous: https://nico.ms/mg310193
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
api_response["user_id"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_name
|
def user_name
|
||||||
@@ -80,6 +85,7 @@ class NicoSeigaApiClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def user_api_response(user_id)
|
def user_api_response(user_id)
|
||||||
|
return {} unless user_id.present?
|
||||||
resp = get("#{XML_API}/user/info?id=#{user_id}")
|
resp = get("#{XML_API}/user/info?id=#{user_id}")
|
||||||
return {} if resp.blank? || resp.code.to_i == 404
|
return {} if resp.blank? || resp.code.to_i == 404
|
||||||
Hash.from_xml(resp.to_s)["response"]["user"]
|
Hash.from_xml(resp.to_s)["response"]["user"]
|
||||||
|
|||||||
@@ -95,6 +95,14 @@ module Source
|
|||||||
parsed_url.manga_id || parsed_referer&.manga_id
|
parsed_url.manga_id || parsed_referer&.manga_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def http
|
||||||
|
if parsed_url.oekaki_id.present?
|
||||||
|
super.with_legacy_ssl
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def api_client
|
def api_client
|
||||||
if illust_id.present?
|
if illust_id.present?
|
||||||
NicoSeigaApiClient.new(work_id: illust_id, type: "illust", http: http)
|
NicoSeigaApiClient.new(work_id: illust_id, type: "illust", http: http)
|
||||||
|
|||||||
@@ -18,8 +18,7 @@
|
|||||||
# Unhandled URLs
|
# Unhandled URLs
|
||||||
#
|
#
|
||||||
# * https://lohas.nicoseiga.jp/material/5746c5/4459092
|
# * https://lohas.nicoseiga.jp/material/5746c5/4459092
|
||||||
# * https://dic.nicovideo.jp/oekaki/52833.png
|
|
||||||
#
|
|
||||||
module Source
|
module Source
|
||||||
class URL::NicoSeiga < Source::URL
|
class URL::NicoSeiga < Source::URL
|
||||||
attr_reader :illust_id, :manga_id, :image_id, :oekaki_id, :sm_video_id, :nm_video_id, :user_id, :username, :profile_url
|
attr_reader :illust_id, :manga_id, :image_id, :oekaki_id, :sm_video_id, :nm_video_id, :user_id, :username, :profile_url
|
||||||
@@ -92,6 +91,10 @@ module Source
|
|||||||
in "dcdn.cdn.nimg.jpg", *, /^\d+$/ => image_id
|
in "dcdn.cdn.nimg.jpg", *, /^\d+$/ => image_id
|
||||||
@image_id = image_id
|
@image_id = image_id
|
||||||
|
|
||||||
|
# https://deliver.cdn.nicomanga.jp/thumb/7891081p?1590171867
|
||||||
|
in "deliver.cdn.nicomanga.jp", "thumb", /^(\d+)p$/ => image_id
|
||||||
|
@image_id = $1
|
||||||
|
|
||||||
# https://deliver.cdn.nicomanga.jp/thumb/aHR0cHM6Ly9kZWxpdmVyLmNkbi5uaWNvbWFuZ2EuanAvdGh1bWIvODEwMDk2OHA_MTU2NTY5OTg4MA.webp (page: https://seiga.nicovideo.jp/watch/mg316708, full image: https://lohas.nicoseiga.jp/priv/1f6d38ef2ba6fc9d9e27823babc4cf721cef16ec/1646906617/8100969)
|
# https://deliver.cdn.nicomanga.jp/thumb/aHR0cHM6Ly9kZWxpdmVyLmNkbi5uaWNvbWFuZ2EuanAvdGh1bWIvODEwMDk2OHA_MTU2NTY5OTg4MA.webp (page: https://seiga.nicovideo.jp/watch/mg316708, full image: https://lohas.nicoseiga.jp/priv/1f6d38ef2ba6fc9d9e27823babc4cf721cef16ec/1646906617/8100969)
|
||||||
in "deliver.cdn.nicomanga.jp", *rest
|
in "deliver.cdn.nicomanga.jp", *rest
|
||||||
# unhandled
|
# unhandled
|
||||||
@@ -131,7 +134,7 @@ module Source
|
|||||||
|
|
||||||
# https://www.nicovideo.jp/user/4572975
|
# https://www.nicovideo.jp/user/4572975
|
||||||
# https://www.nicovideo.jp/user/20446930/mylist/28674289
|
# https://www.nicovideo.jp/user/20446930/mylist/28674289
|
||||||
in ("www.nicovideo.jp"), "user", /^\d+$/ => user_id, *rest
|
in "www.nicovideo.jp", "user", /^\d+$/ => user_id, *rest
|
||||||
@user_id = user_id
|
@user_id = user_id
|
||||||
@profile_url = "https://www.nicovideo.jp/user/#{user_id}"
|
@profile_url = "https://www.nicovideo.jp/user/#{user_id}"
|
||||||
|
|
||||||
@@ -191,8 +194,8 @@ module Source
|
|||||||
"https://www.nicovideo.jp/watch/sm#{sm_video_id}"
|
"https://www.nicovideo.jp/watch/sm#{sm_video_id}"
|
||||||
elsif oekaki_id.present?
|
elsif oekaki_id.present?
|
||||||
"https://dic.nicovideo.jp/oekaki_id/#{oekaki_id}"
|
"https://dic.nicovideo.jp/oekaki_id/#{oekaki_id}"
|
||||||
#elsif image_id.present?
|
# elsif image_id.present?
|
||||||
# "https://seiga.nicovideo.jp/image/source/#{image_id}"
|
# "https://seiga.nicovideo.jp/image/source/#{image_id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module SourceTestHelper
|
|||||||
# * If deleted is true, it skips the downloading check, but it still tries everything else and makes sure nothing breaks.
|
# * If deleted is true, it skips the downloading check, but it still tries everything else and makes sure nothing breaks.
|
||||||
# * Any passed kwargs parameter is tested against the strategy.
|
# * Any passed kwargs parameter is tested against the strategy.
|
||||||
|
|
||||||
def strategy_should_work(url, arguments)
|
def strategy_should_work(url, arguments = {})
|
||||||
# XXX: can't use **kwargs because of a bug with shoulda-context
|
# XXX: can't use **kwargs because of a bug with shoulda-context
|
||||||
referer, download_size, deleted = [:referer, :download_size, :deleted].map { |arg| arguments.delete(arg) }
|
referer, download_size, deleted = [:referer, :download_size, :deleted].map { |arg| arguments.delete(arg) }
|
||||||
|
|
||||||
@@ -86,15 +86,15 @@ module SourceTestHelper
|
|||||||
# check any method that is passed as kwargs, in order to hardcode as few things as possible
|
# check any method that is passed as kwargs, in order to hardcode as few things as possible
|
||||||
# XXX can't use **kwargs because of a bug with shoulda-context, so we're using a hash temporarily
|
# XXX can't use **kwargs because of a bug with shoulda-context, so we're using a hash temporarily
|
||||||
methods_to_test.each do |method_name, expected_value|
|
methods_to_test.each do |method_name, expected_value|
|
||||||
actual_value = strategy.try(method_name)
|
actual_value = strategy.public_send(method_name)
|
||||||
|
|
||||||
should "make sure that '#{method_name}' matches" do
|
should "make sure that '#{method_name}' matches" do
|
||||||
if expected_value.instance_of? Regexp
|
if expected_value.instance_of? Regexp
|
||||||
assert_match(expected_value, actual_value)
|
assert_match(expected_value, actual_value)
|
||||||
elsif expected_value.instance_of? Array
|
elsif expected_value.instance_of? Array
|
||||||
if expected_value.first.instance_of? Regexp
|
if expected_value.first.instance_of? Regexp
|
||||||
actual_values = actual_value.sort
|
# We don't sort actual_value here because sites like nicoseiga have variable values right in the middle of the url, like timestamps
|
||||||
expected_value.sort.each_with_index { |each_value, index| assert_match(each_value, actual_values[index]) }
|
expected_value.zip(actual_value).map { |expected_regex, actual_string| assert_match(expected_regex, actual_string) }
|
||||||
else
|
else
|
||||||
assert_equal(expected_value.sort, actual_value.sort)
|
assert_equal(expected_value.sort, actual_value.sort)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,157 +6,188 @@ module Sources
|
|||||||
skip "NicoSeiga credentials not configured" unless Source::Extractor::NicoSeiga.enabled?
|
skip "NicoSeiga credentials not configured" unless Source::Extractor::NicoSeiga.enabled?
|
||||||
end
|
end
|
||||||
|
|
||||||
context "The source site for nico seiga" do
|
context "A nicoseiga post url" do
|
||||||
setup do
|
tags = [
|
||||||
@site_1 = Source::Extractor.find("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
|
["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"],
|
||||||
@site_2 = Source::Extractor.find("http://seiga.nicovideo.jp/seiga/im4937663")
|
["コジコジ", "https://seiga.nicovideo.jp/tag/%E3%82%B3%E3%82%B8%E3%82%B3%E3%82%B8"],
|
||||||
@site_3 = Source::Extractor.find("https://seiga.nicovideo.jp/watch/mg470189?track=ct_episode")
|
["さくらももこ", "https://seiga.nicovideo.jp/tag/%E3%81%95%E3%81%8F%E3%82%89%E3%82%82%E3%82%82%E3%81%93"],
|
||||||
end
|
["ドット絵", "https://seiga.nicovideo.jp/tag/%E3%83%89%E3%83%83%E3%83%88%E7%B5%B5"],
|
||||||
|
["ニコニコ大百科", "https://seiga.nicovideo.jp/tag/%E3%83%8B%E3%82%B3%E3%83%8B%E3%82%B3%E5%A4%A7%E7%99%BE%E7%A7%91"],
|
||||||
should "get the profile" do
|
["お絵カキコ", "https://seiga.nicovideo.jp/tag/%E3%81%8A%E7%B5%B5%E3%82%AB%E3%82%AD%E3%82%B3"],
|
||||||
assert_equal("https://seiga.nicovideo.jp/user/illust/7017777", @site_1.profile_url)
|
]
|
||||||
assert_equal("https://seiga.nicovideo.jp/user/illust/7017777", @site_2.profile_url)
|
strategy_should_work(
|
||||||
assert_equal("https://seiga.nicovideo.jp/user/illust/20797022", @site_3.profile_url)
|
"http://seiga.nicovideo.jp/seiga/im4937663",
|
||||||
end
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/4937663}],
|
||||||
|
download_size: 2_032,
|
||||||
should "get the artist name" do
|
page_url: "https://seiga.nicovideo.jp/seiga/im4937663",
|
||||||
assert_equal("osamari", @site_1.artist_name)
|
tags: tags,
|
||||||
assert_equal("osamari", @site_2.artist_name)
|
artist_name: "osamari",
|
||||||
assert_equal("風呂", @site_3.artist_name)
|
tag_name: "nicoseiga7017777",
|
||||||
end
|
profile_url: "https://seiga.nicovideo.jp/user/illust/7017777",
|
||||||
|
artist_commentary_title: "コジコジ",
|
||||||
should "get the artist commentary" do
|
artist_commentary_desc: "コジコジのドット絵\nこんなかわいらしい容姿で毒を吐くコジコジが堪らん(切実)"
|
||||||
assert_equal("コジコジ", @site_2.artist_commentary_title)
|
)
|
||||||
assert_equal("コジコジのドット絵\nこんなかわいらしい容姿で毒を吐くコジコジが堪らん(切実)", @site_2.artist_commentary_desc)
|
|
||||||
|
|
||||||
assert_equal("ハコ女子 1ハコ目", @site_3.artist_commentary_title)
|
|
||||||
assert_equal("同じクラスの箱田さんはいつもハコを被っている。しかしてその素顔は…? twitter(@hakojoshi1)にてだいたい毎日更新中。こっちだともうちょっと先まで読めるよ。", @site_3.artist_commentary_desc)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the image url(s)" do
|
|
||||||
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_1.image_urls.sole)
|
|
||||||
assert_match(%r{^https?://lohas\.nicoseiga\.jp/priv/}, @site_2.image_urls.sole)
|
|
||||||
|
|
||||||
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(9, @site_3.image_urls.size)
|
|
||||||
9.times { |n| assert_match(expected[n], @site_3.image_urls[n]) }
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the page url" do
|
|
||||||
assert_equal("https://seiga.nicovideo.jp/seiga/im4937663", @site_1.page_url)
|
|
||||||
assert_equal("https://seiga.nicovideo.jp/seiga/im4937663", @site_2.page_url)
|
|
||||||
assert_equal("https://seiga.nicovideo.jp/watch/mg470189", @site_3.page_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get the tags" do
|
|
||||||
assert_not(@site_1.tags.empty?)
|
|
||||||
first_tag = @site_1.tags.first
|
|
||||||
assert_equal(["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
|
|
||||||
|
|
||||||
assert_not(@site_2.tags.empty?)
|
|
||||||
first_tag = @site_2.tags.first
|
|
||||||
assert_equal(["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
|
|
||||||
|
|
||||||
assert_not(@site_3.tags.empty?)
|
|
||||||
first_tag = @site_3.tags.first
|
|
||||||
assert_equal(["4コマ漫画", "https://seiga.nicovideo.jp/manga/tag/4%E3%82%B3%E3%83%9E%E6%BC%AB%E7%94%BB"], first_tag)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "convert a page into a json representation" do
|
|
||||||
assert_nothing_raised { @site_1.to_h }
|
|
||||||
assert_nothing_raised { @site_2.to_h }
|
|
||||||
assert_nothing_raised { @site_3.to_h }
|
|
||||||
end
|
|
||||||
|
|
||||||
should "work for a https://lohas.nicoseiga.jp/thumb/${id}i url" do
|
|
||||||
site = Source::Extractor.find("https://lohas.nicoseiga.jp/thumb/6844226i")
|
|
||||||
|
|
||||||
assert_match(%r!https?://lohas.nicoseiga.jp/priv/[a-f0-9]{40}/[0-9]+/6844226!, site.image_urls.sole)
|
|
||||||
assert_match("https://seiga.nicovideo.jp/seiga/im6844226", site.page_url)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A manga upload through bookmarklet" do
|
context "A nicoseiga image url" do
|
||||||
setup do
|
tags = [
|
||||||
@url = "https://seiga.nicovideo.jp/image/source/9146749"
|
["アニメ", "https://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"],
|
||||||
@ref = "https://seiga.nicovideo.jp/watch/mg389884"
|
["コジコジ", "https://seiga.nicovideo.jp/tag/%E3%82%B3%E3%82%B8%E3%82%B3%E3%82%B8"],
|
||||||
@site = Source::Extractor.find(@url, @ref)
|
["さくらももこ", "https://seiga.nicovideo.jp/tag/%E3%81%95%E3%81%8F%E3%82%89%E3%82%82%E3%82%82%E3%81%93"],
|
||||||
end
|
["ドット絵", "https://seiga.nicovideo.jp/tag/%E3%83%89%E3%83%83%E3%83%88%E7%B5%B5"],
|
||||||
|
["ニコニコ大百科", "https://seiga.nicovideo.jp/tag/%E3%83%8B%E3%82%B3%E3%83%8B%E3%82%B3%E5%A4%A7%E7%99%BE%E7%A7%91"],
|
||||||
should "get the correct pic" do
|
["お絵カキコ", "https://seiga.nicovideo.jp/tag/%E3%81%8A%E7%B5%B5%E3%82%AB%E3%82%AD%E3%82%B3"],
|
||||||
assert_match(%r!https?://lohas.nicoseiga.jp/priv/[a-f0-9]{40}/[0-9]+/9146749!, @site.image_urls.sole)
|
]
|
||||||
end
|
strategy_should_work(
|
||||||
|
"http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663",
|
||||||
should "get the page url" do
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/4937663}],
|
||||||
assert_equal(@ref, @site.page_url)
|
download_size: 2_032,
|
||||||
end
|
page_url: "https://seiga.nicovideo.jp/seiga/im4937663",
|
||||||
|
tags: tags,
|
||||||
|
artist_name: "osamari",
|
||||||
|
tag_name: "nicoseiga7017777",
|
||||||
|
profile_url: "https://seiga.nicovideo.jp/user/illust/7017777",
|
||||||
|
artist_commentary_title: "コジコジ",
|
||||||
|
artist_commentary_desc: "コジコジのドット絵\nこんなかわいらしい容姿で毒を吐くコジコジが堪らん(切実)"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A manga image" do
|
context "A nicoseiga manga url" do
|
||||||
should "work" do
|
image_urls = [
|
||||||
@source = Source::Extractor.find("https://drm.cdn.nicomanga.jp/image/d4a2faa68ec34f95497db6601a4323fde2ccd451_9537/8017978p?1570012695")
|
%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_match(%r{\Ahttps://lohas\.nicoseiga\.jp/priv/\h{40}/\d+/8017978\z}, @source.image_urls.sole)
|
strategy_should_work(
|
||||||
end
|
"https://seiga.nicovideo.jp/watch/mg470189?track=ct_episode",
|
||||||
|
image_urls: image_urls,
|
||||||
|
page_url: "https://seiga.nicovideo.jp/watch/mg470189",
|
||||||
|
artist_name: "風呂",
|
||||||
|
profile_url: "https://seiga.nicovideo.jp/user/illust/20797022",
|
||||||
|
artist_commentary_title: "ハコ女子 1ハコ目",
|
||||||
|
artist_commentary_desc: "同じクラスの箱田さんはいつもハコを被っている。しかしてその素顔は…? twitter(@hakojoshi1)にてだいたい毎日更新中。こっちだともうちょっと先まで読めるよ。"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A nico.ms illust URL" do
|
context "A https://lohas.nicoseiga.jp/thumb/${id}i url" do
|
||||||
should "work" do
|
strategy_should_work(
|
||||||
@source = Source::Extractor.find("https://nico.ms/im10922621")
|
"https://lohas.nicoseiga.jp/thumb/6844226i",
|
||||||
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/6844226}],
|
||||||
assert_match(%r{\Ahttps://lohas\.nicoseiga\.jp/priv/\h{40}/\d+/10922621\z}, @source.image_urls.sole)
|
page_url: "https://seiga.nicovideo.jp/seiga/im6844226"
|
||||||
end
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A nico.ms manga URL" do
|
context "An image/source/123 url with referrer" do
|
||||||
should "work" do
|
strategy_should_work(
|
||||||
@source = Source::Extractor.find("https://nico.ms/mg310193")
|
"https://seiga.nicovideo.jp/image/source/9146749",
|
||||||
|
referer: "https://seiga.nicovideo.jp/watch/mg389884",
|
||||||
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/9146749}],
|
||||||
|
page_url: "https://seiga.nicovideo.jp/watch/mg389884"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal(19, @source.image_urls.size)
|
context "A drm.cdn.nicomanga.jp image url" do
|
||||||
assert_equal("https://seiga.nicovideo.jp/watch/mg310193", @source.page_url)
|
strategy_should_work(
|
||||||
end
|
"https://drm.cdn.nicomanga.jp/image/d4a2faa68ec34f95497db6601a4323fde2ccd451_9537/8017978p?1570012695",
|
||||||
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017978}]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A nico.ms illust url" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://nico.ms/im10922621",
|
||||||
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/10922621}],
|
||||||
|
page_url: "https://seiga.nicovideo.jp/seiga/im10922621",
|
||||||
|
profile_url: "https://seiga.nicovideo.jp/user/illust/2258804"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A nico.ms manga url from an anonymous user" do
|
||||||
|
image_urls = [
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017978},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017979},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017980},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017981},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017982},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017983},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017984},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017985},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017986},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017987},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017988},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017989},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017990},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017991},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017992},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017993},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017994},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017995},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/8017996},
|
||||||
|
]
|
||||||
|
|
||||||
|
strategy_should_work(
|
||||||
|
"https://nico.ms/mg310193",
|
||||||
|
image_urls: image_urls,
|
||||||
|
artist_name: nil,
|
||||||
|
profile_url: nil,
|
||||||
|
artist_commentary_title: "ライブダンジョン! 第1話前半"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "An anonymous illust" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://seiga.nicovideo.jp/seiga/im520647",
|
||||||
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/520647}],
|
||||||
|
artist_name: nil,
|
||||||
|
profile_url: nil
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A nicoseiga video" do
|
context "A nicoseiga video" do
|
||||||
should "not raise anything" do
|
strategy_should_work(
|
||||||
site = Source::Extractor.find("https://www.nicovideo.jp/watch/sm36465441")
|
"https://www.nicovideo.jp/watch/sm36465441"
|
||||||
assert_nothing_raised { site.to_h }
|
)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "An anonymous picture" do
|
|
||||||
should "still work" do
|
|
||||||
site = Source::Extractor.find("https://seiga.nicovideo.jp/seiga/im520647")
|
|
||||||
|
|
||||||
assert_nothing_raised { site.to_h }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "An age-restricted picture" do
|
context "An age-restricted picture" do
|
||||||
should "still work" do
|
strategy_should_work(
|
||||||
site = Source::Extractor.find("http://seiga.nicovideo.jp/seiga/im9208126")
|
"http://seiga.nicovideo.jp/seiga/im9208126",
|
||||||
|
image_urls: [%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/9208126}],
|
||||||
assert_match(%r!https?://lohas.nicoseiga.jp/priv/[a-f0-9]{40}/[0-9]+/9208126!, site.image_urls.sole)
|
artist_name: "ちふり",
|
||||||
assert_nothing_raised { site.to_h }
|
profile_url: "https://seiga.nicovideo.jp/user/illust/61431040",
|
||||||
end
|
tags: ["R-15"],
|
||||||
|
artist_commentary_title: "ゾーヤさんといっしょ"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "An oekaki picture" do
|
context "An oekaki direct url" do
|
||||||
should "still work" do
|
strategy_should_work(
|
||||||
site = Source::Extractor.find("https://dic.nicovideo.jp/oekaki/52833.png")
|
"https://dic.nicovideo.jp/oekaki/52833.png",
|
||||||
assert_nothing_raised { site.to_h }
|
image_urls: ["https://dic.nicovideo.jp/oekaki/52833.png"]
|
||||||
end
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A nicoseiga manga page with a single tag (source of XML misparsing)" do
|
||||||
|
image_urls = [
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/7891076},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/7891080},
|
||||||
|
%r{https://lohas\.nicoseiga\.jp/priv/\h+/\d+/7891081},
|
||||||
|
]
|
||||||
|
strategy_should_work(
|
||||||
|
"https://seiga.nicovideo.jp/watch/mg302561",
|
||||||
|
image_urls: image_urls,
|
||||||
|
page_url: "https://seiga.nicovideo.jp/watch/mg302561",
|
||||||
|
tags: [["ロリ", "https://seiga.nicovideo.jp/manga/tag/%E3%83%AD%E3%83%AA"]],
|
||||||
|
artist_name: "とろてい",
|
||||||
|
tag_name: "nicoseiga1848060"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "A commentary with spoiler" do
|
context "A commentary with spoiler" do
|
||||||
@@ -219,34 +250,7 @@ module Sources
|
|||||||
assert(Source::URL.profile_url?("https://3d.nicovideo.jp/u/siobi"))
|
assert(Source::URL.profile_url?("https://3d.nicovideo.jp/u/siobi"))
|
||||||
assert(Source::URL.profile_url?("http://game.nicovideo.jp/atsumaru/users/7757217"))
|
assert(Source::URL.profile_url?("http://game.nicovideo.jp/atsumaru/users/7757217"))
|
||||||
|
|
||||||
refute(Source::URL.profile_url?("https://seiga.nicovideo.jp"))
|
assert_not(Source::URL.profile_url?("https://seiga.nicovideo.jp"))
|
||||||
end
|
|
||||||
|
|
||||||
context "downloading a 'http://seiga.nicovideo.jp/seiga/:id' url" do
|
|
||||||
should "download the original file" do
|
|
||||||
@source = "http://seiga.nicovideo.jp/seiga/im4937663"
|
|
||||||
@rewrite = %r{https://lohas.nicoseiga.jp/priv/\h{40}/\d+/4937663}
|
|
||||||
assert_rewritten(@rewrite, @source)
|
|
||||||
assert_downloaded(2_032, @source)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "downloading a 'http://lohas.nicoseiga.jp/o/:hash/:id' url" do
|
|
||||||
should "download the original file" do
|
|
||||||
@source = "http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663"
|
|
||||||
@rewrite = %r{https://lohas.nicoseiga.jp/priv/\h{40}/\d+/4937663}
|
|
||||||
assert_rewritten(@rewrite, @source)
|
|
||||||
assert_downloaded(2_032, @source)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "downloading a 'https://lohas.nicoseiga.jp/thumb/:id' url" do
|
|
||||||
should "download the original file" do
|
|
||||||
@source = "https://lohas.nicoseiga.jp/thumb/4937663i"
|
|
||||||
@rewrite = %r{https://lohas.nicoseiga.jp/priv/\h{40}/\d+/4937663}
|
|
||||||
assert_rewritten(@rewrite, @source)
|
|
||||||
assert_downloaded(2_032, @source)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user