Merge pull request #2782 from evazion/fix-2779
Fix #2779: Erroneous pixiv_id parsed for novel/background/profile images
This commit is contained in:
@@ -8,9 +8,12 @@ module Downloads
|
||||
end
|
||||
|
||||
def rewrite(url, headers, data = {})
|
||||
if url =~ /https?:\/\/(?:\w+\.)?pixiv\.net/
|
||||
if url =~ /\Ahttps?:\/\/(?:\w+\.)?pixiv\.net/
|
||||
url, headers = rewrite_headers(url, headers)
|
||||
url, headers = rewrite_cdn(url, headers)
|
||||
end
|
||||
|
||||
if url =~ /\Ahttps?:\/\/(?:\w+\.)?pixiv\.net/ && source.illust_id_from_url
|
||||
url, headers = rewrite_html_pages(url, headers)
|
||||
url, headers = rewrite_thumbnails(url, headers)
|
||||
url, headers = rewrite_old_small_manga_pages(url, headers)
|
||||
|
||||
@@ -7,7 +7,7 @@ module Sources
|
||||
:profile_url, :image_url, :tags, :artist_record, :unique_id,
|
||||
:page_count, :file_url, :ugoira_frame_data, :ugoira_content_type, :image_urls,
|
||||
:has_artist_commentary?, :artist_commentary_title,
|
||||
:artist_commentary_desc, :rewrite_thumbnails, :to => :strategy
|
||||
:artist_commentary_desc, :rewrite_thumbnails, :illust_id_from_url, :to => :strategy
|
||||
|
||||
def self.strategies
|
||||
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr]
|
||||
|
||||
@@ -82,6 +82,10 @@ module Sources
|
||||
[image_url]
|
||||
end
|
||||
|
||||
def tags
|
||||
@tags || []
|
||||
end
|
||||
|
||||
# Should be set to a url for sites that prevent hotlinking, or left nil for sites that don't.
|
||||
def fake_referer
|
||||
nil
|
||||
|
||||
@@ -56,7 +56,7 @@ module Sources
|
||||
if has_moniker?
|
||||
moniker = get_moniker_from_url
|
||||
else
|
||||
@illust_id = self.class.illust_id_from_url!(url)
|
||||
@illust_id = illust_id_from_url!
|
||||
@metadata = get_metadata_from_papi(@illust_id)
|
||||
moniker = @metadata.moniker
|
||||
end
|
||||
@@ -65,7 +65,8 @@ module Sources
|
||||
end
|
||||
|
||||
def get
|
||||
@illust_id = self.class.illust_id_from_url!(url)
|
||||
return unless illust_id_from_url
|
||||
@illust_id = illust_id_from_url
|
||||
@metadata = get_metadata_from_papi(@illust_id)
|
||||
|
||||
page = agent.get(URI.parse(normalized_url))
|
||||
@@ -111,9 +112,9 @@ module Sources
|
||||
@metadata.pages
|
||||
end
|
||||
|
||||
def self.illust_id_from_url(url)
|
||||
if url_match?(url)
|
||||
illust_id_from_url!(url)
|
||||
def illust_id_from_url
|
||||
if sample_image? || full_image? || work_page?
|
||||
illust_id_from_url!
|
||||
else
|
||||
nil
|
||||
end
|
||||
@@ -121,7 +122,7 @@ module Sources
|
||||
nil
|
||||
end
|
||||
|
||||
def self.illust_id_from_url!(url)
|
||||
def illust_id_from_url!
|
||||
# http://img18.pixiv.net/img/evazion/14901720.png
|
||||
#
|
||||
# http://i2.pixiv.net/img18/img/evazion/14901720.png
|
||||
@@ -155,8 +156,6 @@ module Sources
|
||||
raise Sources::Error.new("Couldn't get illust ID from URL: #{url}")
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# http://i1.pixiv.net/c/600x600/img-master/img/2014/10/02/13/51/23/46304396_p1_master1200.jpg
|
||||
# => http://i1.pixiv.net/img-original/img/2014/10/02/13/51/23/46304396_p1.png
|
||||
|
||||
@@ -1685,7 +1685,7 @@ class Post < ActiveRecord::Base
|
||||
|
||||
module PixivMethods
|
||||
def parse_pixiv_id
|
||||
self.pixiv_id = Sources::Strategies::Pixiv.illust_id_from_url(source)
|
||||
self.pixiv_id = Sources::Strategies::Pixiv.new(source).illust_id_from_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user