diff --git a/backend/app/jobs/recordings/verify_youtube_replay_job.rb b/backend/app/jobs/recordings/verify_youtube_replay_job.rb index fbb1015..811109a 100644 --- a/backend/app/jobs/recordings/verify_youtube_replay_job.rb +++ b/backend/app/jobs/recordings/verify_youtube_replay_job.rb @@ -15,7 +15,16 @@ module Recordings result = Recordings::VerifyYoutubeReplay.new(recording).call if result.ok? - Recordings::ClearTemporaryMediaJob.perform_async(recording.id, "verified") + recording.reload + embeddable = recording.metadata.is_a?(Hash) && recording.metadata.dig("youtube", "embeddable") != false + if embeddable + Recordings::ClearTemporaryMediaJob.perform_async(recording.id, "verified") + else + Rails.logger.warn( + "[Recordings::VerifyYoutubeReplayJob] keep_temp recording=#{recording.id} " \ + "youtube_not_embeddable" + ) + end return end diff --git a/backend/app/services/recordings/verify_youtube_replay.rb b/backend/app/services/recordings/verify_youtube_replay.rb index 252e40d..1ca5c96 100644 --- a/backend/app/services/recordings/verify_youtube_replay.rb +++ b/backend/app/services/recordings/verify_youtube_replay.rb @@ -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 diff --git a/backend/app/services/youtube/broadcast_service.rb b/backend/app/services/youtube/broadcast_service.rb index f731dc1..2f9f530 100644 --- a/backend/app/services/youtube/broadcast_service.rb +++ b/backend/app/services/youtube/broadcast_service.rb @@ -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? diff --git a/backend/app/services/youtube/vod_status.rb b/backend/app/services/youtube/vod_status.rb index 1d70a89..e919c5e 100644 --- a/backend/app/services/youtube/vod_status.rb +++ b/backend/app/services/youtube/vod_status.rb @@ -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 diff --git a/backend/app/views/public/replay/show.html.erb b/backend/app/views/public/replay/show.html.erb index e6ef7b7..0644588 100644 --- a/backend/app/views/public/replay/show.html.erb +++ b/backend/app/views/public/replay/show.html.erb @@ -14,33 +14,6 @@
<%= t("replay.show.processing_body") %>
- <% elsif @recording.ready? && @recording.replay_source == "youtube" && @recording.youtube_video_id.present? && !@recording.youtube_video_id.to_s.start_with?("mock_") %> - - - <% elsif @recording.ready? && @recording.storage_key.present? %>