From 2f508f03cf04ce7cb24f0c2feb9bf4afedd2fc12 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 2 Dec 2022 15:41:00 -0600 Subject: [PATCH] Fix #5362: Suggest ai-generated as a translated tag from pixiv response --- app/logical/source/extractor/pixiv.rb | 9 ++++++++- test/unit/sources/pixiv_test.rb | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/logical/source/extractor/pixiv.rb b/app/logical/source/extractor/pixiv.rb index 46791f604..93b024d62 100644 --- a/app/logical/source/extractor/pixiv.rb +++ b/app/logical/source/extractor/pixiv.rb @@ -104,10 +104,17 @@ module Source end def tags - api_illust.dig(:tags, :tags).to_a.map do |item| + tags = api_illust.dig(:tags, :tags).to_a.map do |item| tag = item[:tag] [tag, "https://www.pixiv.net/search.php?s_mode=s_tag_full&#{{word: tag}.to_param}"] end + + if api_illust["aiType"] == 2 + # XXX There's no way to search for posts with the AI flag on Pixiv. The "AI" tag is the closest equivalent. + tags += [["AI", "https://www.pixiv.net/tags/AI/artworks"]] + end + + tags end def normalize_tag(tag) diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index 3ccf0325e..df9973e5a 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -185,6 +185,17 @@ module Sources ) end + context "An AI-generated post should get the AI tag" do + strategy_should_work( + "https://www.pixiv.net/en/artworks/103291492", + image_urls: ["https://i.pximg.net/img-original/img/2022/12/03/05/06/51/103291492_p0.png"], + artist_commentary_title: "Rem's present", + artist_name: "Anzatiridonia", + profile_url: "https://www.pixiv.net/users/33589885", + tags: %w[AI Re:ゼロから始める異世界生活 レム リゼロ レム(リゼロ) AIイラスト AnythingV3 Present sweater], + ) + end + context "fetching the commentary" do should "work when the description is blank" do get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981746")