uploads/batch now supports pixiv
This commit is contained in:
@@ -28,10 +28,9 @@ class UploadsController < ApplicationController
|
||||
end
|
||||
|
||||
def batch
|
||||
if params[:url] =~ /twitter/
|
||||
@service = TwitterService.new
|
||||
end
|
||||
@urls = @service.image_urls(params[:url])
|
||||
@source = Sources::Site.new(params[:url])
|
||||
@source.get
|
||||
@urls = @source.image_urls
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :get, :get_size, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :to => :strategy
|
||||
delegate :get, :get_size, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :image_urls, :to => :strategy
|
||||
|
||||
def self.strategies
|
||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter]
|
||||
|
||||
@@ -67,6 +67,10 @@ module Sources
|
||||
template.params[:ref] || template.params[:url]
|
||||
end
|
||||
|
||||
def image_urls
|
||||
[image_url]
|
||||
end
|
||||
|
||||
protected
|
||||
def agent
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -63,6 +63,7 @@ module Sources
|
||||
@zip_url, @ugoira_frame_data, @ugoira_content_type = get_zip_url_from_page(page)
|
||||
@tags = get_tags_from_page(page)
|
||||
@page_count = get_page_count_from_page(page)
|
||||
@gallery_link = get_gallery_link(page)
|
||||
|
||||
is_manga = @page_count > 1
|
||||
|
||||
@@ -87,8 +88,29 @@ module Sources
|
||||
image_url || zip_url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
results = []
|
||||
|
||||
if @gallery_link
|
||||
agent.get("http://www.pixiv.net/" + @gallery_link) do |page|
|
||||
results = page.search("a.full-size-container").map {|x| "http://www.pixiv.net" + x.attr("href")}
|
||||
end
|
||||
end
|
||||
|
||||
results
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_gallery_link(page)
|
||||
link = page.search("a.multiple").first
|
||||
if link
|
||||
link.attr("href")
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
# 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
|
||||
def rewrite_new_medium_images(thumbnail_url)
|
||||
|
||||
@@ -18,5 +18,9 @@ module Sources::Strategies
|
||||
@profile_url = "https://twitter.com/" + attrs[:user][:screen_name]
|
||||
@image_url = attrs[:entities][:media][0][:media_url] + ":orig"
|
||||
end
|
||||
|
||||
def image_urls
|
||||
TwitterService.new.image_urls(url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
1833
test/fixtures/vcr_cassettes/pixiv-gallery.yml
vendored
Normal file
1833
test/fixtures/vcr_cassettes/pixiv-gallery.yml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,6 +19,20 @@ module Sources
|
||||
PixivWebAgent.stubs(:phpsessid).returns(PHPSESSID)
|
||||
end
|
||||
|
||||
context "A gallery page" do
|
||||
setup do
|
||||
VCR.use_cassette("pixiv-gallery", :record => :none) do
|
||||
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482")
|
||||
@site.get
|
||||
@image_urls = @site.image_urls
|
||||
end
|
||||
end
|
||||
|
||||
should "get all the image urls" do
|
||||
assert_equal(["http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=49270482&page=0", "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=49270482&page=1"], @image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "An ugoira source site for pixiv" do
|
||||
setup do
|
||||
VCR.use_cassette("ugoira-converter", :record => :none) do
|
||||
|
||||
Reference in New Issue
Block a user