refactor nico seiga manga support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class NicoSeigaMangaApiClient
|
||||
extend Memoist
|
||||
BASE_URL = "http://seiga.nicovideo.jp/api"
|
||||
BASE_URL = "https://seiga.nicovideo.jp/api"
|
||||
attr_reader :theme_id
|
||||
|
||||
def initialize(theme_id)
|
||||
@@ -24,7 +24,9 @@ class NicoSeigaMangaApiClient
|
||||
end
|
||||
|
||||
def image_ids
|
||||
theme_data_xml["response"]["image_list"]["image"].map {|x| x["id"]}
|
||||
images = theme_data_xml["response"]["image_list"]["image"]
|
||||
images = [images] unless images.is_a?(Array)
|
||||
images.map {|x| x["id"]}
|
||||
end
|
||||
|
||||
def tags
|
||||
|
||||
@@ -3,7 +3,6 @@ module Sources
|
||||
def self.all
|
||||
return [
|
||||
Strategies::Pixiv,
|
||||
Strategies::NicoSeigaManga, # must come before NicoSeiga
|
||||
Strategies::NicoSeiga,
|
||||
Strategies::Twitter,
|
||||
Strategies::Stash, # must come before DeviantArt
|
||||
|
||||
@@ -4,8 +4,10 @@ module Sources
|
||||
URL = %r!\Ahttps?://(?:\w+\.)?nico(?:seiga|video)\.jp!
|
||||
DIRECT1 = %r!\Ahttps?://lohas\.nicoseiga\.jp/priv/[0-9a-f]+!
|
||||
DIRECT2 = %r!\Ahttps?://lohas\.nicoseiga\.jp/o/[0-9a-f]+/\d+/\d+!
|
||||
DIRECT3 = %r!\Ahttps?://seiga\.nicovideo\.jp/images/source/\d+!
|
||||
PAGE = %r!\Ahttps?://seiga\.nicovideo\.jp/seiga/im(\d+)!i
|
||||
PROFILE = %r!\Ahttps?://seiga\.nicovideo\.jp/user/illust/(\d+)!i
|
||||
MANGA_PAGE = %r!\Ahttps?://seiga\.nicovideo\.jp/watch/mg(\d+)!i
|
||||
|
||||
def domains
|
||||
["nicoseiga.jp", "nicovideo.jp"]
|
||||
@@ -20,6 +22,12 @@ module Sources
|
||||
return [url]
|
||||
end
|
||||
|
||||
if theme_id
|
||||
return api_client.image_ids.map do |image_id|
|
||||
"https://seiga.nicovideo.jp/image/source/#{image_id}"
|
||||
end
|
||||
end
|
||||
|
||||
link = page.search("a#illust_link")
|
||||
|
||||
if link.any?
|
||||
@@ -65,6 +73,10 @@ module Sources
|
||||
if x =~ %r{/seiga/im\d+}
|
||||
return x
|
||||
end
|
||||
|
||||
if x =~ %r{/watch/mg\d+}
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
return super
|
||||
@@ -105,7 +117,7 @@ module Sources
|
||||
end
|
||||
|
||||
def normalizable_for_artist_finder?
|
||||
url =~ PAGE || url =~ PROFILE || url =~ DIRECT1 || url =~ DIRECT2
|
||||
url =~ PAGE || url =~ MANGA_PAGE || url =~ PROFILE || url =~ DIRECT1 || url =~ DIRECT2
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder
|
||||
@@ -127,7 +139,11 @@ module Sources
|
||||
public
|
||||
|
||||
def api_client
|
||||
NicoSeigaApiClient.new(illust_id: illust_id)
|
||||
if illust_id
|
||||
NicoSeigaApiClient.new(illust_id: illust_id)
|
||||
elsif theme_id
|
||||
NicoSeigaMangaApiClient.new(theme_id)
|
||||
end
|
||||
end
|
||||
memoize :api_client
|
||||
|
||||
@@ -139,6 +155,14 @@ module Sources
|
||||
return nil
|
||||
end
|
||||
|
||||
def theme_id
|
||||
if page_url =~ MANGA_PAGE
|
||||
return $1.to_i
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
def page
|
||||
doc = agent.get(page_url)
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class NicoSeigaManga < Base
|
||||
PAGE_URL = %r!\Ahttps?://seiga\.nicovideo\.jp/watch/mg(\d+)!i
|
||||
|
||||
def domains
|
||||
["nicoseiga.jp", "nicovideo.jp"]
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Nico Seiga (manga)"
|
||||
end
|
||||
|
||||
def image_urls
|
||||
api_client.image_ids.map do |image_id|
|
||||
"https://seiga.nicovideo.jp/image/source/#{image_id}"
|
||||
end
|
||||
end
|
||||
|
||||
def page_url
|
||||
[url, referer_url].each do |x|
|
||||
if x =~ PAGE_URL
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
return super
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_url
|
||||
end
|
||||
|
||||
def profile_url
|
||||
if url =~ PROFILE
|
||||
return url
|
||||
end
|
||||
|
||||
"http://seiga.nicovideo.jp/user/illust/#{api_client.user_id}"
|
||||
end
|
||||
|
||||
def artist_name
|
||||
api_client.moniker
|
||||
end
|
||||
|
||||
def artist_commentary_title
|
||||
api_client.title
|
||||
end
|
||||
|
||||
def artist_commentary_desc
|
||||
api_client.desc
|
||||
end
|
||||
|
||||
def headers
|
||||
super.merge(
|
||||
"Referer" => "https://seiga.nicovideo.jp"
|
||||
)
|
||||
end
|
||||
|
||||
def theme_id
|
||||
if page_url =~ PAGE_URL
|
||||
return $1
|
||||
end
|
||||
end
|
||||
|
||||
def api_client
|
||||
NicoSeigaMangaApiClient.new(theme_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user