Merge pull request #3167 from evazion/feat-dtextify-pixiv-artcomm

Convert Pixiv commentaries to DText (fix #2458)
This commit is contained in:
Albert Yi
2017-06-19 13:22:31 -07:00
committed by GitHub
3 changed files with 29 additions and 7 deletions

View File

@@ -94,8 +94,8 @@ class PixivApiClient
@user_id = json["user"]["id"]
@moniker = json["user"]["account"]
@page_count = json["page_count"].to_i
@artist_commentary_title = json["title"]
@artist_commentary_desc = json["caption"]
@artist_commentary_title = json["title"].to_s
@artist_commentary_desc = json["caption"].to_s
@tags = [json["tags"], json["tools"]].flatten.compact.reject {|x| x =~ /^http:/}
if page_count > 1
@@ -173,4 +173,4 @@ private
access_token
end
end
end
end

View File

@@ -107,6 +107,23 @@ module Sources
@metadata.pages
end
def self.to_dtext(text)
text = text.gsub(%r!https?://www\.pixiv\.net/member_illust\.php\?mode=medium&illust_id=([0-9]+)!i) do |match|
pixiv_id = $1
%(pixiv ##{pixiv_id} "»":[/posts?tags=pixiv:#{pixiv_id}])
end
text = text.gsub(%r!https?://www\.pixiv\.net/member\.php\?id=([0-9]+)!i) do |match|
member_id = $1
profile_url = "https://www.pixiv.net/member.php?id=#{member_id}"
search_params = {"search[url_matches]" => profile_url}.to_param
%("user/#{member_id}":[#{profile_url}] "»":[/artists?#{search_params}])
end
text
end
def illust_id_from_url
if sample_image? || full_image? || work_page?
illust_id_from_url!