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.
This commit is contained in:
@@ -9,11 +9,11 @@
|
||||
# zip file, so it must be passed around separately.
|
||||
class MediaFile::Ugoira < MediaFile
|
||||
class Error < StandardError; end
|
||||
attr_accessor :frame_data
|
||||
attr_accessor :frame_delays
|
||||
|
||||
def initialize(file, frame_data: {}, **options)
|
||||
def initialize(file, frame_delays: [], **options)
|
||||
super(file, **options)
|
||||
@frame_data = frame_data
|
||||
@frame_delays = frame_delays
|
||||
end
|
||||
|
||||
def close
|
||||
@@ -39,22 +39,18 @@ class MediaFile::Ugoira < MediaFile
|
||||
end
|
||||
|
||||
def frame_count
|
||||
frame_data.count
|
||||
frame_delays.count
|
||||
end
|
||||
|
||||
def frame_rate
|
||||
frame_count / duration
|
||||
end
|
||||
|
||||
def frame_delays
|
||||
frame_data.map { |frame| frame["delay"] }
|
||||
end
|
||||
|
||||
# Convert a ugoira to a webm.
|
||||
# XXX should take width and height and resize image
|
||||
def convert
|
||||
raise NotImplementedError, "can't convert ugoira to webm: ffmpeg or mkvmerge not installed" unless self.class.videos_enabled?
|
||||
raise RuntimeError, "can't convert ugoira to webm: no ugoira frame data was provided" unless frame_data.present?
|
||||
raise RuntimeError, "can't convert ugoira to webm: no ugoira frame data was provided" unless frame_delays.present?
|
||||
|
||||
Dir.mktmpdir("ugoira-#{md5}") do |tmpdir|
|
||||
output_file = Tempfile.new(["ugoira-conversion", ".webm"], binmode: true)
|
||||
@@ -80,9 +76,9 @@ class MediaFile::Ugoira < MediaFile
|
||||
timecodes_path = File.join(tmpdir, "timecodes.tc")
|
||||
File.open(timecodes_path, "w+") do |f|
|
||||
f.write("# timecode format v2\n")
|
||||
frame_data.each do |img|
|
||||
frame_delays.each do |delay|
|
||||
f.write("#{delay_sum}\n")
|
||||
delay_sum += (img["delay"] || img["delay_msec"])
|
||||
delay_sum += delay
|
||||
end
|
||||
f.write("#{delay_sum}\n")
|
||||
f.write("#{delay_sum}\n")
|
||||
|
||||
@@ -115,9 +115,9 @@ module Source
|
||||
end
|
||||
|
||||
def download_file!(url)
|
||||
file = super(url)
|
||||
file.frame_data = ugoira_frame_data if is_ugoira?
|
||||
file
|
||||
media_file = super(url)
|
||||
media_file.frame_delays = ugoira_frame_delays if is_ugoira?
|
||||
media_file
|
||||
end
|
||||
|
||||
def translate_tag(tag)
|
||||
@@ -162,8 +162,8 @@ module Source
|
||||
parsed_url.username || api_illust[:userAccount]
|
||||
end
|
||||
|
||||
def ugoira_frame_data
|
||||
api_ugoira[:frames]
|
||||
def ugoira_frame_delays
|
||||
api_ugoira[:frames].pluck("delay")
|
||||
end
|
||||
|
||||
memoize :illust_id, :api_client, :api_illust, :api_pages, :api_ugoira
|
||||
|
||||
Reference in New Issue
Block a user