Completa modulo Replay: S3, retention, sync YouTube e gestione società.

Streaming chunked da Garage, purge con delete YouTube, privacy sincronizzata,
archivio club migliorato, retention 30/90 separata da stato abbonamento.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-08 09:33:59 +02:00
parent ae36d17adb
commit 74eee24293
17 changed files with 385 additions and 34 deletions

View File

@@ -0,0 +1,66 @@
module Youtube
# Aggiorna privacy o elimina un VOD YouTube collegato a un replay.
class VideoLifecycleService
class Error < StandardError; end
def initialize(recording)
@recording = recording
@team = recording.team
@session = recording.stream_session
end
def update_privacy!(privacy_status:)
video_id = @recording.youtube_video_id
return if video_id.blank? || video_id.to_s.start_with?("mock_")
privacy = map_privacy(privacy_status)
client = authorized_client
video = Google::Apis::YoutubeV3::Video.new(
id: video_id,
status: Google::Apis::YoutubeV3::VideoStatus.new(
privacy_status: privacy,
self_declared_made_for_kids: false
)
)
client.update_video("status", video)
merge_youtube_meta!("privacy_status" => privacy)
true
rescue Google::Apis::Error => e
raise Error, e.message
end
def delete!
video_id = @recording.youtube_video_id
return if video_id.blank? || video_id.to_s.start_with?("mock_")
client = authorized_client
client.delete_video(video_id)
true
rescue Google::Apis::Error => e
raise Error, e.message
end
private
def map_privacy(status)
status.to_s == "public" ? "public" : "unlisted"
end
def merge_youtube_meta!(attrs)
meta = @recording.metadata.is_a?(Hash) ? @recording.metadata.dup : {}
publish = meta.fetch("youtube_publish", {}).merge(attrs)
@recording.update!(metadata: meta.merge("youtube_publish" => publish))
end
def youtube_channel
@session&.platform == "youtube" ? "team" : nil
end
def authorized_client
credential = CredentialResolver.new(@team, channel: youtube_channel).resolve
raise Error, "Credenziali YouTube non disponibili" if credential.blank?
OauthRefresh.new(credential).apply!(Google::Apis::YoutubeV3::YouTubeService.new)
end
end
end