Add warning when Pixiv post is a gallery of multiple images

This commit is contained in:
Toks
2014-06-13 16:33:38 -04:00
parent cb1f00b448
commit 3230ab8781
7 changed files with 28 additions and 4 deletions

View File

@@ -85,6 +85,12 @@
$("#source-record").html(new_artist_link);
if (data.page_count > 1) {
$("#gallery-warning").show();
} else {
$("#gallery-warning").hide();
}
$("#source-info span#loading-data").hide();
$("#source-info ul").show();
}

View File

@@ -26,7 +26,7 @@ div#c-uploads {
margin: 1em 0;
padding: 1em;
border: 1px solid gray;
min-height: 4em;
min-height: 5em;
p {
margin: 0;

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -10,6 +10,7 @@
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
<p><%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %></p>
<% end %>
<p><%= content_tag "span", "Gallery. Tags may not apply to all images.", :id => "gallery-warning", :style => "display: none;" %></p>
<ul>
<li><strong>Artist</strong>: <span id="source-artist"></span></li>

View File

@@ -5,6 +5,7 @@
<div id="source-info">
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
<p><%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %></p>
<p><%= content_tag "span", "Gallery. Tags may not apply to all images.", :id => "gallery-warning", :style => "display: none;" %></p>
<ul>
<li><strong>Artist</strong>: <span id="source-artist"></span></li>