ニコニコ同期でオリジナルの投稿日時連携(#246) (#248)

#246

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #248
This commit was merged in pull request #248.
This commit is contained in:
2026-01-31 03:07:19 +09:00
parent 39ec57c142
commit 5a02be0517
2 changed files with 19 additions and 5 deletions
+10 -3
View File
@@ -47,11 +47,18 @@ namespace :nico do
code = datum['code']
post = Post.where('url REGEXP ?', "nicovideo\\.jp/watch/#{ Regexp.escape(code) }([^0-9]|$)")
.first
unless post
title = datum['title']
title = datum['title']
original_created_at = datum['uploaded_at'] && Time.iso8601(datum['uploaded_at'])
original_created_from = original_created_at&.change(sec: 0)
original_created_before = original_created_from&.+(1.minute)
if post
attrs = { title:, original_created_from:, original_created_before: }
post.update!(attrs) if attrs.any? { |k, v| post.public_send(k) != v }
else
url = "https://www.nicovideo.jp/watch/#{ code }"
thumbnail_base = fetch_thumbnail.(url) rescue nil
post = Post.new(title:, url:, thumbnail_base:, uploaded_user: nil)
post = Post.new(title:, url:, thumbnail_base:, uploaded_user: nil,
original_created_from:, original_created_before:)
if thumbnail_base.present?
post.thumbnail.attach(
io: URI.open(thumbnail_base),