Refactor Post#parse_pixiv_id to use illust_id_from_url (fix #2695).
* Make illust_id_from_url a public class method instead of a protected instance method so that Post#parse_pixiv_id can use it. * Also make illust_id_from_url swallow the exception that illust_id_from_url! throws so that parse_pixiv_id can use it.
This commit is contained in:
@@ -55,7 +55,7 @@ module Sources
|
|||||||
if has_moniker?
|
if has_moniker?
|
||||||
moniker = get_moniker_from_url
|
moniker = get_moniker_from_url
|
||||||
else
|
else
|
||||||
@illust_id = illust_id_from_url(url)
|
@illust_id = self.class.illust_id_from_url!(url)
|
||||||
@metadata = get_metadata_from_papi(@illust_id)
|
@metadata = get_metadata_from_papi(@illust_id)
|
||||||
moniker = @metadata.moniker
|
moniker = @metadata.moniker
|
||||||
end
|
end
|
||||||
@@ -64,7 +64,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
@illust_id = illust_id_from_url(url)
|
@illust_id = self.class.illust_id_from_url!(url)
|
||||||
@metadata = get_metadata_from_papi(@illust_id)
|
@metadata = get_metadata_from_papi(@illust_id)
|
||||||
|
|
||||||
page = agent.get(URI.parse(normalized_url))
|
page = agent.get(URI.parse(normalized_url))
|
||||||
@@ -109,6 +109,51 @@ module Sources
|
|||||||
def image_urls
|
def image_urls
|
||||||
@metadata.pages
|
@metadata.pages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.illust_id_from_url(url)
|
||||||
|
if url_match?(url)
|
||||||
|
illust_id_from_url!(url)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
rescue Sources::Error
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.illust_id_from_url!(url)
|
||||||
|
# http://img18.pixiv.net/img/evazion/14901720.png
|
||||||
|
#
|
||||||
|
# http://i2.pixiv.net/img18/img/evazion/14901720.png
|
||||||
|
# http://i2.pixiv.net/img18/img/evazion/14901720_m.png
|
||||||
|
# http://i2.pixiv.net/img18/img/evazion/14901720_s.png
|
||||||
|
# http://i1.pixiv.net/img07/img/pasirism/18557054_p1.png
|
||||||
|
# http://i1.pixiv.net/img07/img/pasirism/18557054_big_p1.png
|
||||||
|
#
|
||||||
|
# http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_64x64.jpg
|
||||||
|
# http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_s.png
|
||||||
|
#
|
||||||
|
# http://i1.pixiv.net/c/600x600/img-master/img/2014/10/02/13/51/23/46304396_p0_master1200.jpg
|
||||||
|
# http://i1.pixiv.net/img-original/img/2014/10/02/13/51/23/46304396_p0.png
|
||||||
|
#
|
||||||
|
# http://i1.pixiv.net/img-zip-ugoira/img/2014/10/03/17/29/16/46323924_ugoira1920x1080.zip
|
||||||
|
if url =~ %r!/(\d+)(?:_\w+)?\.(?:jpg|jpeg|png|gif|zip)!i
|
||||||
|
$1
|
||||||
|
|
||||||
|
# http://www.pixiv.net/member_illust.php?mode=medium&illust_id=18557054
|
||||||
|
# http://www.pixiv.net/member_illust.php?mode=big&illust_id=18557054
|
||||||
|
# http://www.pixiv.net/member_illust.php?mode=manga&illust_id=18557054
|
||||||
|
# http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=18557054&page=1
|
||||||
|
elsif url =~ /illust_id=(\d+)/i
|
||||||
|
$1
|
||||||
|
|
||||||
|
# http://www.pixiv.net/i/18557054
|
||||||
|
elsif url =~ %r!pixiv\.net/i/(\d+)!i
|
||||||
|
$1
|
||||||
|
|
||||||
|
else
|
||||||
|
raise Sources::Error.new("Couldn't get illust ID from URL: #{url}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
@@ -297,41 +342,6 @@ module Sources
|
|||||||
@metadata ||= PixivApiClient.new.works(illust_id)
|
@metadata ||= PixivApiClient.new.works(illust_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def illust_id_from_url(url)
|
|
||||||
# http://img18.pixiv.net/img/evazion/14901720.png
|
|
||||||
#
|
|
||||||
# http://i2.pixiv.net/img18/img/evazion/14901720.png
|
|
||||||
# http://i2.pixiv.net/img18/img/evazion/14901720_m.png
|
|
||||||
# http://i2.pixiv.net/img18/img/evazion/14901720_s.png
|
|
||||||
# http://i1.pixiv.net/img07/img/pasirism/18557054_p1.png
|
|
||||||
# http://i1.pixiv.net/img07/img/pasirism/18557054_big_p1.png
|
|
||||||
#
|
|
||||||
# http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_64x64.jpg
|
|
||||||
# http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_s.png
|
|
||||||
#
|
|
||||||
# http://i1.pixiv.net/c/600x600/img-master/img/2014/10/02/13/51/23/46304396_p0_master1200.jpg
|
|
||||||
# http://i1.pixiv.net/img-original/img/2014/10/02/13/51/23/46304396_p0.png
|
|
||||||
#
|
|
||||||
# http://i1.pixiv.net/img-zip-ugoira/img/2014/10/03/17/29/16/46323924_ugoira1920x1080.zip
|
|
||||||
if url =~ %r!/(\d+)(?:_\w+)?\.(?:jpg|jpeg|png|gif|zip)!i
|
|
||||||
$1
|
|
||||||
|
|
||||||
# http://www.pixiv.net/member_illust.php?mode=medium&illust_id=18557054
|
|
||||||
# http://www.pixiv.net/member_illust.php?mode=big&illust_id=18557054
|
|
||||||
# http://www.pixiv.net/member_illust.php?mode=manga&illust_id=18557054
|
|
||||||
# http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=18557054&page=1
|
|
||||||
elsif url =~ /illust_id=(\d+)/i
|
|
||||||
$1
|
|
||||||
|
|
||||||
# http://www.pixiv.net/i/18557054
|
|
||||||
elsif url =~ %r!pixiv\.net/i/(\d+)!i
|
|
||||||
$1
|
|
||||||
|
|
||||||
else
|
|
||||||
raise Sources::Error.new("Couldn't get illust ID from URL: #{url}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def work_page?
|
def work_page?
|
||||||
return true if url =~ %r!#{WEB}/member_illust\.php\?mode=(?:medium|big|manga|manga_big)&illust_id=\d+!i
|
return true if url =~ %r!#{WEB}/member_illust\.php\?mode=(?:medium|big|manga|manga_big)&illust_id=\d+!i
|
||||||
return true if url =~ %r!#{WEB}/i/\d+$!i
|
return true if url =~ %r!#{WEB}/i/\d+$!i
|
||||||
|
|||||||
@@ -1644,23 +1644,7 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
module PixivMethods
|
module PixivMethods
|
||||||
def parse_pixiv_id
|
def parse_pixiv_id
|
||||||
if source =~ %r!http://i\d\.pixiv\.net/img-inf/img/\d+/\d+/\d+/\d+/\d+/\d+/(\d+)_s.jpg!
|
self.pixiv_id = Sources::Strategies::Pixiv.illust_id_from_url(source)
|
||||||
self.pixiv_id = $1
|
|
||||||
elsif source =~ %r!http://img\d+\.pixiv\.net/img/[^\/]+/(\d+)!
|
|
||||||
self.pixiv_id = $1
|
|
||||||
elsif source =~ %r!http://i\d\.pixiv\.net/img\d+/img/[^\/]+/(\d+)!
|
|
||||||
self.pixiv_id = $1
|
|
||||||
elsif source =~ %r!http://i\d\.pixiv\.net/img-original/img/(?:\d+\/)+(\d+)_p!
|
|
||||||
self.pixiv_id = $1
|
|
||||||
elsif source =~ %r!http://i\d\.pixiv\.net/c/\d+x\d+/img-master/img/(?:\d+\/)+(\d+)_p!
|
|
||||||
self.pixiv_id = $1
|
|
||||||
elsif source =~ /pixiv\.net/ && source =~ /illust_id=(\d+)/
|
|
||||||
self.pixiv_id = $1
|
|
||||||
elsif source =~ %r!http://i\d\.pixiv\.net/img-zip-ugoira/img/(?:\d+\/)+(\d+)_ugoira!
|
|
||||||
self.pixiv_id = $1
|
|
||||||
else
|
|
||||||
self.pixiv_id = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user