Files
danbooru/app/models/media_metadata.rb
evazion c2adf279ee ugoira: remove the PixivUgoiraFrameData model.
Remove the last remaining uses of the PixivUgoiraFrameData model. As of
32bfb8407, Ugoira frame data is now stored in the MediaMetadata model,
under the `Ugoira:FrameDelays` EXIF field.

The pixiv_ugoira_frame_data table still exists, but it can be removed
after this commit is deployed.

Fixes #5264: Error when replacing with ugoira.
2022-10-10 18:21:30 -05:00

36 lines
956 B
Ruby

# frozen_string_literal: true
# MediaMetadata represents the EXIF and other metadata associated with a
# MediaAsset (an uploaded image or video file). The `metadata` field contains a
# JSON hash of the file's metadata as returned by ExifTool.
#
# @see ExifTool
# @see https://exiftool.org/TagNames/index.html
class MediaMetadata < ApplicationRecord
self.table_name = "media_metadata"
attribute :id
attribute :created_at
attribute :updated_at
attribute :media_asset_id
attribute :metadata
belongs_to :media_asset
def self.search(params, current_user)
q = search_attributes(params, [:id, :created_at, :updated_at, :media_asset, :metadata], current_user: current_user)
q.apply_default_order(params)
end
def file=(file_or_path)
self.metadata = MediaFile.open(file_or_path).metadata
end
def metadata
ExifTool::Metadata.new(self[:metadata])
end
def frame_delays
metadata["Ugoira:FrameDelays"].to_a
end
end