Abilita l'embed YouTube sulle dirette e tiene la copia locale se il VOD non è incorporabile.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -46,10 +46,11 @@ module Recordings
|
||||
return Result.new(status: :pending, message: "vod_not_ready")
|
||||
end
|
||||
|
||||
info = enable_embed_if_needed!(info)
|
||||
apply_verified!(info)
|
||||
Rails.logger.info(
|
||||
"[Recordings::VerifyYoutubeReplay] ok recording=#{@recording.id} " \
|
||||
"youtube_video_id=#{info.video_id}"
|
||||
"youtube_video_id=#{info.video_id} embeddable=#{info.embeddable}"
|
||||
)
|
||||
Result.new(status: :ok, message: "verified")
|
||||
rescue Youtube::VodStatus::Error => e
|
||||
@@ -68,6 +69,7 @@ module Recordings
|
||||
"thumbnail_url" => info.thumbnail_url,
|
||||
"privacy_status" => info.privacy_status,
|
||||
"upload_status" => info.upload_status,
|
||||
"embeddable" => info.embeddable,
|
||||
"verified_via" => "live_broadcast"
|
||||
).compact
|
||||
|
||||
@@ -82,5 +84,23 @@ module Recordings
|
||||
|
||||
@recording.update!(attrs)
|
||||
end
|
||||
|
||||
def enable_embed_if_needed!(info)
|
||||
return info if info.embeddable != false
|
||||
return info if info.video_id.to_s.start_with?("mock_")
|
||||
|
||||
session = @recording.stream_session
|
||||
Youtube::BroadcastService.new(session.match.team).enable_video_embed!(
|
||||
info.video_id,
|
||||
privacy_status: info.privacy_status
|
||||
)
|
||||
refreshed = Youtube::VodStatus.new(@recording.team, channel: "team").fetch(info.video_id)
|
||||
refreshed.ready ? refreshed : info
|
||||
rescue Youtube::BroadcastService::Error, Youtube::VodStatus::Error => e
|
||||
Rails.logger.warn(
|
||||
"[Recordings::VerifyYoutubeReplay] enable_embed recording=#{@recording.id}: #{e.message}"
|
||||
)
|
||||
info
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,8 @@ module Youtube
|
||||
),
|
||||
content_details: Google::Apis::YoutubeV3::LiveBroadcastContentDetails.new(
|
||||
enable_auto_start: true,
|
||||
enable_auto_stop: false
|
||||
enable_auto_stop: false,
|
||||
enable_embed: true
|
||||
)
|
||||
)
|
||||
result = client.insert_live_broadcast("snippet,status,contentDetails", broadcast)
|
||||
@@ -97,6 +98,24 @@ module Youtube
|
||||
:skipped
|
||||
end
|
||||
|
||||
def enable_video_embed!(video_id, privacy_status: "unlisted")
|
||||
return if video_id.blank? || video_id.to_s.start_with?("mock_")
|
||||
return if @credential.blank? || missing_oauth_config?
|
||||
|
||||
client = authorized_client
|
||||
video = Google::Apis::YoutubeV3::Video.new(
|
||||
id: video_id,
|
||||
status: Google::Apis::YoutubeV3::VideoStatus.new(
|
||||
embeddable: true,
|
||||
privacy_status: privacy_status.presence || "unlisted",
|
||||
self_declared_made_for_kids: false
|
||||
)
|
||||
)
|
||||
client.update_video("status", video)
|
||||
rescue Google::Apis::Error => e
|
||||
raise Error, e.message
|
||||
end
|
||||
|
||||
def complete_broadcast!(broadcast_id)
|
||||
return if broadcast_id.blank?
|
||||
return if @credential.blank? || missing_oauth_config?
|
||||
|
||||
@@ -13,6 +13,7 @@ module Youtube
|
||||
:thumbnail_url,
|
||||
:privacy_status,
|
||||
:upload_status,
|
||||
:embeddable,
|
||||
keyword_init: true
|
||||
)
|
||||
|
||||
@@ -32,7 +33,8 @@ module Youtube
|
||||
duration_secs: nil,
|
||||
thumbnail_url: nil,
|
||||
privacy_status: "unlisted",
|
||||
upload_status: "processed"
|
||||
upload_status: "processed",
|
||||
embeddable: true
|
||||
)
|
||||
end
|
||||
|
||||
@@ -51,7 +53,8 @@ module Youtube
|
||||
duration_secs: parse_duration(item.content_details&.duration),
|
||||
thumbnail_url: item.snippet&.thumbnails&.high&.url || item.snippet&.thumbnails&.default&.url,
|
||||
privacy_status: item.status&.privacy_status,
|
||||
upload_status: upload_status
|
||||
upload_status: upload_status,
|
||||
embeddable: item.status&.embeddable != false
|
||||
)
|
||||
rescue Google::Apis::Error => e
|
||||
raise Error, e.message
|
||||
|
||||
Reference in New Issue
Block a user