Add warning when Pixiv post is a gallery of multiple images
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :to => :strategy
|
||||
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :to => :strategy
|
||||
|
||||
def self.strategies
|
||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie]
|
||||
@@ -31,7 +31,8 @@ module Sources
|
||||
:translated_tags => translated_tags,
|
||||
:danbooru_name => artist_record.try(:first).try(:name),
|
||||
:danbooru_id => artist_record.try(:first).try(:id),
|
||||
:unique_id => unique_id
|
||||
:unique_id => unique_id,
|
||||
:page_count => page_count
|
||||
}.to_json
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ module Sources
|
||||
module Strategies
|
||||
class Base
|
||||
attr_reader :url
|
||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
||||
attr_reader :artist_name, :profile_url, :image_url, :tags, :page_count
|
||||
|
||||
def self.url_match?(url)
|
||||
false
|
||||
@@ -10,6 +10,7 @@ module Sources
|
||||
|
||||
def initialize(url)
|
||||
@url = url
|
||||
@page_count = 1
|
||||
end
|
||||
|
||||
# No remote calls are made until this method is called.
|
||||
|
||||
@@ -29,6 +29,7 @@ module Sources
|
||||
@artist_name, @profile_url = get_profile_from_page(page)
|
||||
@image_url = get_image_url_from_page(page)
|
||||
@tags = get_tags_from_page(page)
|
||||
@page_count = get_page_count_from_page(page)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,6 +82,19 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
def get_page_count_from_page(page)
|
||||
elements = page.search("ul.meta li").find_all do |node|
|
||||
node.text =~ /Manga/
|
||||
end
|
||||
|
||||
if elements.any?
|
||||
elements[0].text =~ /Manga (\d+)P/
|
||||
$1.to_i
|
||||
else
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
def normalized_url
|
||||
@normalized_url ||= begin
|
||||
if url =~ /\/(\d+)(?:_big)?(?:_m|_p\d+)?\.(?:jpg|jpeg|png|gif)/i
|
||||
|
||||
Reference in New Issue
Block a user