diff --git a/app/logical/nico_seiga_manga_api_client.rb b/app/logical/nico_seiga_manga_api_client.rb index 7649dd139..a33263e65 100644 --- a/app/logical/nico_seiga_manga_api_client.rb +++ b/app/logical/nico_seiga_manga_api_client.rb @@ -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 diff --git a/app/logical/sources/strategies.rb b/app/logical/sources/strategies.rb index b8bdba71a..e2294e643 100644 --- a/app/logical/sources/strategies.rb +++ b/app/logical/sources/strategies.rb @@ -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 diff --git a/app/logical/sources/strategies/nico_seiga.rb b/app/logical/sources/strategies/nico_seiga.rb index d62cadf5e..78b218e2e 100644 --- a/app/logical/sources/strategies/nico_seiga.rb +++ b/app/logical/sources/strategies/nico_seiga.rb @@ -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) diff --git a/app/logical/sources/strategies/nico_seiga_manga.rb b/app/logical/sources/strategies/nico_seiga_manga.rb deleted file mode 100644 index 59705fc8a..000000000 --- a/app/logical/sources/strategies/nico_seiga_manga.rb +++ /dev/null @@ -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