YouTube live immediata: relay sempre attivo e attivazione broadcast.
Il relay parte dal job overlay ogni 2s; scheduledStartTime ~90s invece di 5 min; transition testing/live quando l'ingest RTMP raggiunge YouTube. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -50,6 +50,28 @@ module Youtube
|
||||
raise Error, friendly_api_error(e)
|
||||
end
|
||||
|
||||
# Porta in onda appena c’è ingest su YouTube (non attendere scheduledStartTime).
|
||||
def activate_broadcast!(broadcast_id)
|
||||
return if broadcast_id.blank?
|
||||
return if @credential.blank? || missing_oauth_config?
|
||||
|
||||
client = authorized_client
|
||||
item = client.list_live_broadcasts("status", id: broadcast_id).items&.first
|
||||
return unless item
|
||||
|
||||
status = item.status.life_cycle_status.to_s
|
||||
return if status == "live"
|
||||
|
||||
if %w[ready created].include?(status)
|
||||
client.transition_live_broadcast("testing", broadcast_id, "id,status")
|
||||
status = "testing"
|
||||
end
|
||||
client.transition_live_broadcast("live", broadcast_id, "id,status") if status == "testing"
|
||||
rescue Google::Apis::Error => e
|
||||
Rails.logger.warn("[Youtube::BroadcastService] activate #{broadcast_id}: #{e.message}")
|
||||
nil
|
||||
end
|
||||
|
||||
def complete_broadcast!(broadcast_id)
|
||||
return if broadcast_id.blank?
|
||||
return if @credential.blank? || missing_oauth_config?
|
||||
@@ -100,10 +122,10 @@ module Youtube
|
||||
msg
|
||||
end
|
||||
|
||||
# YouTube richiede scheduledStartTime obbligatorio e nel futuro (non accetta date partita già passate).
|
||||
# YouTube richiede scheduledStartTime nel futuro; per «vai subito» usiamo ~1 min (auto_start al RTMP).
|
||||
def normalize_scheduled_start_time(scheduled_at)
|
||||
now = Time.current.utc
|
||||
minimum = now + 5.minutes
|
||||
minimum = now + 90.seconds
|
||||
maximum = now + 7.days
|
||||
|
||||
candidate =
|
||||
|
||||
Reference in New Issue
Block a user