Fix orario YouTube scheduledStartTime per dirette immediate.
Normalizza la data partita nel futuro richiesto dall'API: se scheduled_at è passato o assente usa now+5min, con messaggio d'errore più chiaro. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,10 +12,11 @@ module Youtube
|
||||
return mock_broadcast if @credential.blank? || missing_oauth_config?
|
||||
|
||||
client = authorized_client
|
||||
start_time = normalize_scheduled_start_time(scheduled_at)
|
||||
broadcast = Google::Apis::YoutubeV3::LiveBroadcast.new(
|
||||
snippet: Google::Apis::YoutubeV3::LiveBroadcastSnippet.new(
|
||||
title: title,
|
||||
scheduled_start_time: scheduled_at&.iso8601
|
||||
scheduled_start_time: start_time.iso8601
|
||||
),
|
||||
status: Google::Apis::YoutubeV3::LiveBroadcastStatus.new(
|
||||
privacy_status: privacy_status,
|
||||
@@ -92,8 +93,29 @@ module Youtube
|
||||
msg = error.message.to_s
|
||||
return "Il canale YouTube non ha la diretta attiva. Apri YouTube Studio con l’account del canale Match Live TV, abilita la live (verifica telefono se richiesto) e riprova." if msg.include?("liveStreamingNotEnabled")
|
||||
return "Credenziali YouTube non valide. Ricollega il canale dalla sezione Admin → YouTube." if msg.match?(/Unauthorized|invalid_grant/i)
|
||||
if msg.match?(/invalidScheduledStartTime|scheduledStartTimeRequired/i)
|
||||
return "Orario programmazione YouTube non valido. Riprova: la diretta partirà appena invii il segnale RTMP."
|
||||
end
|
||||
|
||||
msg
|
||||
end
|
||||
|
||||
# YouTube richiede scheduledStartTime obbligatorio e nel futuro (non accetta date partita già passate).
|
||||
def normalize_scheduled_start_time(scheduled_at)
|
||||
now = Time.current.utc
|
||||
minimum = now + 5.minutes
|
||||
maximum = now + 7.days
|
||||
|
||||
candidate =
|
||||
if scheduled_at.blank?
|
||||
minimum
|
||||
else
|
||||
scheduled_at.utc
|
||||
end
|
||||
|
||||
candidate = minimum if candidate < minimum
|
||||
candidate = maximum if candidate > maximum
|
||||
candidate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user