From 1d5db37f56f9f3ac369858a70107a1cf5dcbfc4c Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 10 Oct 2022 03:58:54 -0500 Subject: [PATCH] posts: automatically tag AI-generated on NovelAI posts. Automatically add the AI-generated tag to posts that have the `PNG:Software=NovelAI` EXIF attribute. This is not foolproof because this metadata may get removed if an AI-generated post is resaved or uploaded to a site that strips EXIF metadata. It also only works for NovelAI. Currently it detects 29 out of 177 AI-generated uploads on Danbooru. --- app/logical/exif_tool.rb | 5 +++++ app/models/media_asset.rb | 2 +- app/models/post.rb | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/logical/exif_tool.rb b/app/logical/exif_tool.rb index 5b7907fbc..34f76cb0a 100644 --- a/app/logical/exif_tool.rb +++ b/app/logical/exif_tool.rb @@ -80,6 +80,11 @@ class ExifTool loop_count.in?(0..10) end + # https://danbooru.donmai.us/media_assets?search[metadata][PNG:Software]=NovelAI + def is_ai_generated? + metadata["PNG:Software"] == "NovelAI" + end + # @see http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension # @see https://wiki.mozilla.org/APNG_Specification#.60acTL.60:_The_Animation_Control_Chunk # @see https://danbooru.donmai.us/posts?tags=-exif:GIF:AnimationIterations=Infinite+animated_gif diff --git a/app/models/media_asset.rb b/app/models/media_asset.rb index ab7bbbb89..2f0504493 100644 --- a/app/models/media_asset.rb +++ b/app/models/media_asset.rb @@ -24,7 +24,7 @@ class MediaAsset < ApplicationRecord has_many :ai_tags delegate :metadata, to: :media_metadata - delegate :is_non_repeating_animation?, :is_greyscale?, :is_rotated?, to: :metadata + delegate :is_non_repeating_animation?, :is_greyscale?, :is_rotated?, :is_ai_generated?, to: :metadata scope :public_only, -> { where(is_public: true) } scope :private_only, -> { where(is_public: false) } diff --git a/app/models/post.rb b/app/models/post.rb index 5a7377f74..e99eefc12 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -465,6 +465,7 @@ class Post < ApplicationRecord tags << "greyscale" if media_asset.is_greyscale? tags << "exif_rotation" if media_asset.is_rotated? tags << "non-repeating_animation" if media_asset.is_non_repeating_animation? + tags << "ai-generated" if media_asset.is_ai_generated? tags end