diff --git a/app/logical/apng_inspector.rb b/app/logical/apng_inspector.rb index 30ce02676..dffad8081 100644 --- a/app/logical/apng_inspector.rb +++ b/app/logical/apng_inspector.rb @@ -86,7 +86,7 @@ class APNGInspector end @corrupted = !read_success || actl_corrupted - return !@corrupted + self end def corrupted? @@ -109,4 +109,4 @@ class APNGInspector return framedata.unpack("N".freeze)[0] end -end \ No newline at end of file +end diff --git a/app/models/post.rb b/app/models/post.rb index 4aa4e9649..4528afe37 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -255,24 +255,6 @@ class Post < ApplicationRecord file_ext =~ /jpg|jpeg|gif|png/i end - def is_animated_gif? - if file_ext =~ /gif/i && File.exists?(file_path) - return Magick::Image.ping(file_path).length > 1 - else - return false - end - end - - def is_animated_png? - if file_ext =~ /png/i && File.exists?(file_path) - apng = APNGInspector.new(file_path) - apng.inspect! - return apng.animated? - else - return false - end - end - def is_flash? file_ext =~ /swf/i end @@ -765,7 +747,6 @@ class Post < ApplicationRecord return tags if !Danbooru.config.enable_dimension_autotagging tags -= %w(incredibly_absurdres absurdres highres lowres huge_filesize flash webm mp4) - tags -= %w(animated_gif animated_png) if new_record? if has_dimensions? if image_width >= 10_000 || image_height >= 10_000 @@ -794,14 +775,6 @@ class Post < ApplicationRecord tags << "huge_filesize" end - if is_animated_gif? - tags << "animated_gif" - end - - if is_animated_png? - tags << "animated_png" - end - if is_flash? tags << "flash" end diff --git a/app/models/upload.rb b/app/models/upload.rb index 1446155c2..a46984a9a 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -80,10 +80,14 @@ class Upload < ApplicationRecord end end - def tag_audio - if is_video? && video.audio_channels.present? - self.tag_string = "#{tag_string} video_with_sound" - end + def automatic_tags + return "" unless Danbooru.config.enable_dimension_autotagging + + tags = [] + tags << "video_with_sound" if is_video_with_audio? + tags << "animated_gif" if is_animated_gif? + tags << "animated_png" if is_animated_png? + tags.join(" ") end def validate_video_duration @@ -109,9 +113,9 @@ class Upload < ApplicationRecord calculate_hash(file_path) validate_md5_uniqueness validate_md5_confirmation - tag_audio validate_video_duration calculate_file_size(file_path) + self.tag_string = "#{tag_string} #{automatic_tags}" self.image_width, self.image_height = calculate_dimensions generate_resizes(file_path) move_file @@ -219,9 +223,21 @@ class Upload < ApplicationRecord %w(webm mp4).include?(file_ext) end + def is_video_with_audio? + is_video? && video.audio_channels.present? + end + def is_ugoira? %w(zip).include?(file_ext) end + + def is_animated_gif? + file_ext == "gif" && Magick::Image.ping(file_path).length > 1 + end + + def is_animated_png? + file_ext == "png" && APNGInspector.new(file_path).inspect!.animated? + end end module ResizerMethods