Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/yt/collections/processing_details.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 11 additions & 6 deletions lib/yt/models/caption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions lib/yt/models/processing_detail.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions lib/yt/models/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/models/processing_detail_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading