Files
danbooru/script/fixes/079_fix_duration.rb
evazion 0731b07d27 posts: store duration of animations and videos.
Start storing the duration of animations and videos in the `duration`
field on the media_assets table. This had to wait until 3d30bfd69 was
deployed, which had to wait until Postgres was upgraded in order to add
the duration column to the media_assets table without downtime.

Also add a fix script to backfill the duration on existing posts. Usage:

    TAGS=animated ./script/fixes/079_fix_duration.rb
2021-10-07 03:21:08 -05:00

16 lines
564 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "../../config/environment"
tags = ENV.fetch("TAGS", "animated")
posts = Post.system_tag_match(tags)
assets = posts.joins(:media_asset).where(media_asset: { duration: nil })
posts.find_each do |post|
media_file = MediaFile.open(post.file(:original), frame_data: post.pixiv_ugoira_frame_data&.data)
post.media_asset.update!(duration: media_file.duration)
puts "id=#{post.id}, md5=#{post.md5}, ext=#{post.file_ext}, duration=#{post.media_asset.duration}"
rescue StandardError => e
puts "error[id=#{post.id}]: #{e}"
end