Class: CloudflareVttService
- Inherits:
-
Object
- Object
- CloudflareVttService
- Defined in:
- app/services/cloudflare_vtt_service.rb
Instance Method Summary collapse
-
#can_upload_vtt? ⇒ Boolean
Check if VTT upload is possible for this video.
-
#delete_vtt_captions(locale) ⇒ Boolean
Delete VTT captions from Cloudflare Stream for a specific language.
-
#initialize(video) ⇒ CloudflareVttService
constructor
A new instance of CloudflareVttService.
-
#upload_all_vtt_captions ⇒ Hash
Upload all available VTT captions to Cloudflare Stream (English + translations).
-
#upload_vtt_captions_en ⇒ Boolean
Upload English VTT captions to Cloudflare Stream.
-
#upload_vtt_captions_translated(locale) ⇒ Boolean
Upload translated VTT captions for a specific locale.
Constructor Details
#initialize(video) ⇒ CloudflareVttService
Returns a new instance of CloudflareVttService.
4 5 6 |
# File 'app/services/cloudflare_vtt_service.rb', line 4 def initialize(video) @video = video end |
Instance Method Details
#can_upload_vtt? ⇒ Boolean
Check if VTT upload is possible for this video
9 10 11 |
# File 'app/services/cloudflare_vtt_service.rb', line 9 def can_upload_vtt? @video.is_cloudflare? && @video.has_structured_transcript_json? end |
#delete_vtt_captions(locale) ⇒ Boolean
Delete VTT captions from Cloudflare Stream for a specific language
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/services/cloudflare_vtt_service.rb', line 54 def delete_vtt_captions(locale) return false unless @video.is_cloudflare? # Map locale to Cloudflare language code cloudflare_lang = if locale.to_s == 'en' 'en' else map_locale_to_cloudflare_lang(locale) end Rails.logger.info "Deleting #{cloudflare_lang} VTT captions from Cloudflare for video #{@video.id}..." cloudflare_api = CloudflareStreamApi.instance result = cloudflare_api.delete_captions(@video.cloudflare_uid, cloudflare_lang) if result Rails.logger.info "Successfully deleted #{cloudflare_lang} VTT captions from Cloudflare" true else Rails.logger.warn "Failed to delete #{cloudflare_lang} VTT captions from Cloudflare" false end end |
#upload_all_vtt_captions ⇒ Hash
Upload all available VTT captions to Cloudflare Stream (English + translations)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/cloudflare_vtt_service.rb', line 21 def upload_all_vtt_captions results = {} # Upload English polished captions if @video.has_polished_vtt? results['en'] = upload_vtt_captions_en end # Upload any available translations VideoProcessing::VideoTranslationService::SUPPORTED_LOCALES.each_key do |locale| if @video.has_translated_vtt?(locale) Rails.logger.info "Uploading translated VTT captions for #{locale}..." results[locale.to_s] = upload_vtt_captions_translated(locale) end end results end |
#upload_vtt_captions_en ⇒ Boolean
Upload English VTT captions to Cloudflare Stream
15 16 17 |
# File 'app/services/cloudflare_vtt_service.rb', line 15 def upload_vtt_captions_en upload_vtt_captions_for_locale('en', 'polished') end |
#upload_vtt_captions_translated(locale) ⇒ Boolean
Upload translated VTT captions for a specific locale
43 44 45 46 47 48 49 |
# File 'app/services/cloudflare_vtt_service.rb', line 43 def upload_vtt_captions_translated(locale) return false unless @video.has_translated_vtt?(locale) # Map locale to Cloudflare language code cloudflare_lang = map_locale_to_cloudflare_lang(locale) upload_vtt_captions_for_locale(cloudflare_lang, nil, locale) end |