This commit is contained in:
r888888888
2015-05-21 15:05:55 -07:00
parent af86099ac5
commit 2ddc93723c
17 changed files with 3156 additions and 3554 deletions

View File

@@ -15,6 +15,8 @@ module Downloads
url, headers = rewrite_thumbnails(url, headers)
url, headers = rewrite_old_small_manga_pages(url, headers)
url, headers = rewrite_to_thumbnails(url, headers) if data.delete(:get_thumbnail)
data[:artist_commentary_title] = source.artist_commentary_title
data[:artist_commentary_desc] = source.artist_commentary_desc
end
# http://i2.pixiv.net/img-zip-ugoira/img/2014/08/05/06/01/10/44524589_ugoira1920x1080.zip

View File

@@ -3,29 +3,35 @@ module Downloads
class Twitter < Base
def rewrite(url, headers, data = {})
if url =~ %r!^https?://(?:mobile\.)?twitter\.com!
url, headers = rewrite_status_page(url, headers)
url, headers = rewrite_status_page(url, headers, data)
elsif url =~ %r{^https?://pbs\.twimg\.com}
url, headers = rewrite_thumbnails(url, headers)
url, headers = rewrite_thumbnails(url, headers, data)
end
return [url, headers, data]
end
protected
def rewrite_status_page(url, headers)
source = ::Sources::Strategies::Twitter.new(url)
source.get
def rewrite_status_page(url, headers, data)
source = build_source(url)
url = source.image_url
return [url, headers]
data[:artist_commentary_desc] = source.artist_commentary_desc
return [url, headers, data]
end
def rewrite_thumbnails(url, headers)
def rewrite_thumbnails(url, headers, data)
if url =~ %r{^(https?://pbs\.twimg\.com/media/[^:]+)}
url = $1 + ":orig"
end
return [url, headers]
end
def build_source(url)
::Sources::Strategies::Twitter.new(url).tap do |x|
x.get
end
end
end
end
end

View File

@@ -7,6 +7,7 @@ class PixivApiClient
class WorksResponse
attr_reader :json, :pages, :moniker, :page_count
attr_reader :artist_commentary_title, :artist_commentary_desc
def initialize(json)
# Sample response:
@@ -91,6 +92,8 @@ class PixivApiClient
@json = json
@moniker = json["user"]["account"]
@page_count = json["page_count"].to_i
@artist_commentary_title = json["title"]
@artist_commentary_desc = json["caption"]
if page_count > 1
@pages = json["metadata"]["pages"].map {|x| x["image_urls"]["large"]}

View File

@@ -3,7 +3,11 @@
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, :image_urls, :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,
:has_artist_commentary?, :artist_commentary_title,
:artist_commentary_desc, :to => :strategy
def self.strategies
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter]

View File

@@ -3,6 +3,7 @@ module Sources
class Base
attr_reader :url
attr_reader :artist_name, :profile_url, :image_url, :tags, :page_count
attr_reader :artist_commentary_title, :artist_commentary_desc
def self.url_match?(url)
false
@@ -43,6 +44,11 @@ module Sources
false
end
# Determines whether or not to automatically create an ArtistCommentary
def has_artist_commentary?
false
end
def normalize_for_artist_finder!
url
end

View File

@@ -35,6 +35,10 @@ module Sources
@pixiv_moniker
end
def has_artist_commentary?
@artist_commentary_desc.present?
end
def normalized_for_artist_finder?
url =~ %r!http://img\.pixiv\.net/img/#{MONIKER}/?$!i
end
@@ -47,15 +51,18 @@ module Sources
if has_moniker?
moniker = get_moniker_from_url
else
illust_id = illust_id_from_url(url)
metadata = get_metadata_from_papi(illust_id)
moniker = metadata.moniker
@illust_id = illust_id_from_url(url)
@metadata = get_metadata_from_papi(@illust_id)
moniker = @metadata.moniker
end
"http://img.pixiv.net/img/#{moniker}/"
end
def get
@illust_id = illust_id_from_url(url)
@metadata = get_metadata_from_papi(@illust_id)
page = agent.get(URI.parse(normalized_url))
if page.search("body.not-logged-in").any?
@@ -71,6 +78,8 @@ module Sources
@tags = get_tags_from_page(page)
@page_count = get_page_count_from_page(page)
@gallery_link = get_gallery_link(page)
@artist_commentary_title = @metadata.artist_commentary_title
@artist_commentary_desc = @metadata.artist_commentary_desc
is_manga = @page_count > 1
@@ -122,10 +131,7 @@ module Sources
def rewrite_new_medium_images(thumbnail_url)
if thumbnail_url =~ %r!/c/\d+x\d+/img-master/img/#{TIMESTAMP}/\d+_p\d+_\w+\.jpg!i
page = manga_page_from_url(@url).to_i
illust_id = illust_id_from_url(@url)
metadata = get_metadata_from_papi(illust_id)
thumbnail_url = metadata.pages[page]
thumbnail_url = @metadata.pages[page]
end
thumbnail_url
@@ -154,9 +160,7 @@ module Sources
def rewrite_old_small_and_medium_images(thumbnail_url, is_manga)
if thumbnail_url =~ %r!/img/#{MONIKER}/\d+_[ms]\.#{EXT}!i
if is_manga.nil?
illust_id = illust_id_from_url(@url)
metadata = get_metadata_from_papi(illust_id)
page_count = metadata.page_count
page_count = @metadata.page_count
is_manga = page_count > 1
end
@@ -300,8 +304,7 @@ module Sources
end
def normalized_url
illust_id = illust_id_from_url(@url)
"http://www.pixiv.net/member_illust.php?mode=medium&illust_id=#{illust_id}"
"http://www.pixiv.net/member_illust.php?mode=medium&illust_id=#{@illust_id}"
end
def get_metadata_from_papi(illust_id)

View File

@@ -18,6 +18,12 @@ module Sources::Strategies
@artist_name = attrs[:user][:name]
@profile_url = "https://twitter.com/" + attrs[:user][:screen_name]
@image_url = attrs[:entities][:media][0][:media_url] + ":orig"
@artist_commentary_title = ""
@artist_commentary_desc = attrs[:text]
end
def has_artist_commentary?
@artist_commentary_desc.present?
end
def image_urls