diff --git a/lib/yt/collections/processing_details.rb b/lib/yt/collections/processing_details.rb new file mode 100644 index 00000000..f3c4d231 --- /dev/null +++ b/lib/yt/collections/processing_details.rb @@ -0,0 +1,30 @@ +require 'yt/collections/base' +require 'yt/models/processing_detail' + +module Yt + module Collections + # @private + class ProcessingDetails < Base + + private + + def attributes_for_new_item(data) + {data: data['processingDetails']} + end + + # @return [Hash] the parameters to submit to YouTube to get the + # YouTube's progress in processing the uploaded video file. + # @see https://developers.google.com/youtube/v3/docs/videos#processingDetails + def list_params + super.tap do |params| + params[:params] = processing_details_params + params[:path] = '/youtube/v3/videos' + end + end + + def processing_details_params + {max_results: 50, part: 'processingDetails', id: @parent.id} + end + end + end +end diff --git a/lib/yt/models/caption.rb b/lib/yt/models/caption.rb index bcbfe980..c68d404d 100644 --- a/lib/yt/models/caption.rb +++ b/lib/yt/models/caption.rb @@ -16,10 +16,14 @@ class Caption < Resource delegate :name, to: :snippet delegate :status, to: :snippet - # Downloads a caption file. + # Downloads a caption file to +path+. Pass +tfmt+ in +options+ to + # request a specific format (sbv, scc, srt, ttml, vtt). Defaults to srt. # @param [String] path A name for the downloaded file with caption content. - # @see https://developers.google.com/youtube/v3/docs/captions#resource - def download(path) + # @param [Hash] options Download options. + # @option options [String] :tfmt The caption format (sbv, scc, srt, ttml, vtt). Defaults to srt. + # @see https://developers.google.com/youtube/v3/docs/captions/download + def download(path, options = {}) + @tfmt = options[:tfmt] || "srt" case io when StringIO then File.open(path, 'w') { |f| f.write(io.read) } when Tempfile then io.close; FileUtils.mv(io.path, path) @@ -42,9 +46,10 @@ def download_params params[:exptected_response] = Net::HTTPOK params[:api_key] = Yt.configuration.api_key if Yt.configuration.api_key params[:path] = "/youtube/v3/captions/#{@id}" - if @auth.owner_name - params[:params] = {on_behalf_of_content_owner: @auth.owner_name} - end + extras = {} + extras[:on_behalf_of_content_owner] = @auth.owner_name if @auth.owner_name + extras[:tfmt] = @tfmt if @tfmt + params[:params] = extras unless extras.empty? end end end diff --git a/lib/yt/models/processing_detail.rb b/lib/yt/models/processing_detail.rb new file mode 100644 index 00000000..b8eb32e1 --- /dev/null +++ b/lib/yt/models/processing_detail.rb @@ -0,0 +1,21 @@ +require 'yt/models/base' + +module Yt + module Models + # @private + # Encapsulates basic information about processing the uploaded video file, + # including the processing status. + # @see https://developers.google.com/youtube/v3/docs/videos#processingDetails + class ProcessingDetail < Base + attr_reader :data + + def initialize(options = {}) + @data = options[:data] || {} + end + + # @return [String] the video's processing status. Possible values are: + # +'processing'+, +'succeeded'+, +'failed'+, +'terminated'+. + has_attribute :processing_status + end + end +end diff --git a/lib/yt/models/video.rb b/lib/yt/models/video.rb index d3f133fb..5216fd55 100644 --- a/lib/yt/models/video.rb +++ b/lib/yt/models/video.rb @@ -299,6 +299,14 @@ def age_restricted? # @return [String] the video container of the uploaded file. (e.g. 'mov'). delegate :container, to: :file_detail + ### PROCESSING DETAILS ### + + has_one :processing_detail + + # @!attribute [r] processing_status + # @return [String] the video's processing status. Possible values are: + # +'processing'+, +'succeeded'+, +'failed'+, +'terminated'+. + delegate :processing_status, to: :processing_detail ### RATING ### @@ -622,6 +630,9 @@ def initialize(options = {}) if options[:file_details] @file_detail = FileDetail.new data: options[:file_details] end + if options[:processing_details] + @processing_detail = ProcessingDetail.new data: options[:processing_details] + end if options[:live_streaming_details] @live_streaming_detail = LiveStreamingDetail.new data: options[:live_streaming_details] end diff --git a/spec/models/processing_detail_spec.rb b/spec/models/processing_detail_spec.rb new file mode 100644 index 00000000..3dde3c7a --- /dev/null +++ b/spec/models/processing_detail_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' +require 'yt/models/processing_detail' + +describe Yt::ProcessingDetail do + subject(:processing_detail) { Yt::ProcessingDetail.new data: data } + + describe '#data' do + let(:data) { {"key"=>"value"} } + specify 'returns the data the processing detail was initialized with' do + expect(processing_detail.data).to eq data + end + end + + describe '#processing_status' do + context 'given the processing_status' do + let(:data) { {"processingStatus"=>"processing"} } + it { expect(processing_detail.processing_status).to eq 'processing' } + end + end +end