Class: YouTube::ThumbnailService
- Inherits:
-
Object
- Object
- YouTube::ThumbnailService
- Defined in:
- app/services/youtube/thumbnail_service.rb
Overview
Pushes the video poster/thumbnail to YouTube.
Resolution priority:
- youtube_thumbnail_image (Image library — CRM “YouTube thumbnail” override)
- poster_image (Image record with ImageKit hosting)
- Dragonfly poster attachment
- Cloudflare Stream thumbnail
YouTube requirements: JPG/PNG/GIF/BMP, max 2MB, 1280x720 recommended.
Constant Summary collapse
- MAX_FILE_SIZE =
2.megabytes
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
-
.source_url_for_youtube_push(video) ⇒ Object
Public URL of the image that #push_thumbnail would upload (poster image, Dragonfly, or Cloudflare still).
Instance Method Summary collapse
-
#initialize(account: nil, client: nil) ⇒ ThumbnailService
constructor
A new instance of ThumbnailService.
-
#push_thumbnail(video) ⇒ Boolean
Push the video's poster image to YouTube as the video thumbnail.
- #source_url_for_youtube_push(video) ⇒ Object
Constructor Details
#initialize(account: nil, client: nil) ⇒ ThumbnailService
Returns a new instance of ThumbnailService.
22 23 24 25 |
# File 'app/services/youtube/thumbnail_service.rb', line 22 def initialize(account: nil, client: nil) @client = client || YouTube::ApiClient.new(account: account) @logger = Rails.logger end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
20 21 22 |
# File 'app/services/youtube/thumbnail_service.rb', line 20 def client @client end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
20 21 22 |
# File 'app/services/youtube/thumbnail_service.rb', line 20 def logger @logger end |
Class Method Details
.source_url_for_youtube_push(video) ⇒ Object
Public URL of the image that #push_thumbnail would upload (poster image, Dragonfly, or Cloudflare still).
28 29 30 |
# File 'app/services/youtube/thumbnail_service.rb', line 28 def self.source_url_for_youtube_push(video) new.source_url_for_youtube_push(video) end |
Instance Method Details
#push_thumbnail(video) ⇒ Boolean
Push the video's poster image to YouTube as the video thumbnail.
39 40 41 42 43 44 45 46 |
# File 'app/services/youtube/thumbnail_service.rb', line 39 def push_thumbnail(video) raise ArgumentError, 'Video has no YouTube ID' if video.youtube_id.blank? url = thumbnail_source_url(video) raise ArgumentError, 'Video has no poster/thumbnail to push' if url.blank? download_and_push(video.youtube_id, url) end |
#source_url_for_youtube_push(video) ⇒ Object
32 33 34 |
# File 'app/services/youtube/thumbnail_service.rb', line 32 def source_url_for_youtube_push(video) thumbnail_source_url(video) end |