Class: YouTube::ThumbnailPanelState

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

Overview

Heatwave push URL + best YouTube CDN thumbnail from videos.list snippet (what viewers see).

Defined Under Namespace

Classes: Summary

Constant Summary collapse

THUMBNAIL_KEYS =
%i[maxres high standard medium default].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ThumbnailPanelState.



26
27
28
29
30
# File 'app/services/youtube/thumbnail_panel_state.rb', line 26

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



22
23
24
# File 'app/services/youtube/thumbnail_panel_state.rb', line 22

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

Instance Method Details

#summaryObject



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

def summary
  hw = ThumbnailService.source_url_for_youtube_push(@video)

  return Summary.new(heatwave_url: hw, youtube_best_url: nil, remote_state: :skipped, error_message: nil) if @video.youtube_id.blank?
  return Summary.new(heatwave_url: hw, youtube_best_url: nil, remote_state: :skipped, error_message: nil) unless oauth_healthy?

  yt = api_client.get_video(@video.youtube_id, parts: 'snippet')
  url = best_thumbnail_url(yt&.snippet&.thumbnails)
  Summary.new(heatwave_url: hw, youtube_best_url: url, remote_state: :loaded, error_message: nil)
rescue OauthService::TokenRefreshError, ApiClient::ApiError => e
  Summary.new(heatwave_url: hw, youtube_best_url: nil, remote_state: :failed, error_message: e.message)
end