Class: YouTube::RemoteCaptionsStatus

Inherits:
Object
  • Object
show all
Defined in:
app/services/youtube/remote_captions_status.rb

Overview

Reads caption track metadata from YouTube via captions.list (same API used before push).
Only works when OAuth is healthy and the connected channel can manage the video.

Defined Under Namespace

Classes: Summary, Track

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(video, client: nil, oauth_service: nil) ⇒ RemoteCaptionsStatus

Returns a new instance of RemoteCaptionsStatus.



27
28
29
30
31
# File 'app/services/youtube/remote_captions_status.rb', line 27

def initialize(video, client: nil, oauth_service: nil)
  @video = video
  @client = client
  @oauth_service = oauth_service
end

Class Method Details

.summary(video, client: nil, oauth_service: nil) ⇒ Object



23
24
25
# File 'app/services/youtube/remote_captions_status.rb', line 23

def self.summary(video, client: nil, oauth_service: nil)
  new(video, client: client, oauth_service: oauth_service).summary
end

Instance Method Details

#summaryObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/youtube/remote_captions_status.rb', line 33

def summary
  return Summary.new(state: :skipped, tracks: [], error_message: nil) if @video.youtube_id.blank?
  return Summary.new(state: :skipped, tracks: [], error_message: nil) unless oauth_healthy?

  items = api_client.list_captions(@video.youtube_id)
  tracks = items.map { |c| build_track(c) }
  Summary.new(state: :loaded, tracks: tracks, error_message: nil)
rescue OauthService::TokenRefreshError => e
  Summary.new(state: :failed, tracks: [], error_message: e.message)
rescue ApiClient::ApiError => e
  Summary.new(state: :failed, tracks: [], error_message: e.message)
end