kaltura_fu 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -12,19 +12,36 @@ About Kaltura
12
12
  About Kaltura_Fu
13
13
  ------------------
14
14
 
15
- kaltura_fu is a gem for rails that extends the basic functionality of the Kaltura ruby client and adds in some Rails view helpers to generate video players, thumbnails, and the uploader. The Kaltura session and client are managed in a singleton pattern, and there are additional modules that allow you to more perform basic API actions in a more efficient manner.
15
+ Kaltura_Fu is a gem that wraps the Kaltura-Ruby API wrapper and also adds some convenience methods for Rails'
16
+ ActionView. The intent of this library is to provide a far easier means to communicate with your Kaltura server.
17
+ It's just too much of a pain to update simple things like the metadata fields with the default kaltura-ruby client.
16
18
 
17
19
  Installation:
18
20
  -------------
19
21
  Install the gem with the command:
20
22
 
21
- gem install kaltura_fu --pre
23
+ gem install kaltura_fu
22
24
  Run:
23
25
 
24
26
  script/generate kaltura_fu_install
25
27
 
26
28
  This will install the kaltura.yml file into your application's config directory and the kaltura_upload.js into the application's public/javascripts directory.
27
29
 
30
+ Testing:
31
+ --------
32
+
33
+ The Kaltura_Fu library is being tested against the following version of Ruby:
34
+
35
+ * 1.8.7(MRI)
36
+ * 1.8.7(EE)
37
+ * 1.9.2(YARV)
38
+ * Rubinius
39
+
40
+ In order to test this gem (for local development), you'll need to have access to a Kaltura server.
41
+ I use a local installation of KalturaCE. You'll have to add a config file under spec/config/kaltura.yml and
42
+ add in a small video file named video.flv in the same folder. Since Kaltura provides no testing in kaltura-ruby,
43
+ I tend to use this library as a test suite for fixes for that library as well.
44
+
28
45
 
29
46
  Documentation:
30
47
  ------
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
4
- :patch: 5
5
3
  :build:
4
+ :minor: 2
5
+ :patch: 0
data/kaltura_fu.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kaltura_fu}
8
- s.version = "0.1.5"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Patrick Robertson"]
12
- s.date = %q{2010-11-05}
12
+ s.date = %q{2010-11-06}
13
13
  s.email = %q{patrick.robertson@velir.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -29,18 +29,17 @@ Gem::Specification.new do |s|
29
29
  "lib/kaltura_fu/configuration.rb",
30
30
  "lib/kaltura_fu/entry.rb",
31
31
  "lib/kaltura_fu/entry/class_methods.rb",
32
+ "lib/kaltura_fu/entry/flavor.rb",
32
33
  "lib/kaltura_fu/entry/instance_methods.rb",
33
34
  "lib/kaltura_fu/entry/metadata.rb",
34
35
  "lib/kaltura_fu/entry/metadata/class_and_instance_methods.rb",
35
36
  "lib/kaltura_fu/entry/metadata/class_methods.rb",
36
- "lib/kaltura_fu/flavor.rb",
37
37
  "lib/kaltura_fu/railtie.rb",
38
- "lib/kaltura_fu/report.rb",
39
- "lib/kaltura_fu/video.rb",
40
38
  "lib/kaltura_fu/view_helpers.rb",
41
39
  "rails/init.rb",
42
40
  "spec/debug.log",
43
41
  "spec/entry_spec.rb",
42
+ "spec/flavor_spec.rb",
44
43
  "spec/kaltura_fu_spec.rb",
45
44
  "spec/metadata_spec.rb",
46
45
  "spec/spec.opts",
@@ -54,6 +53,7 @@ Gem::Specification.new do |s|
54
53
  s.summary = %q{Rails gem for making Kaltura integrations easier.}
55
54
  s.test_files = [
56
55
  "spec/entry_spec.rb",
56
+ "spec/flavor_spec.rb",
57
57
  "spec/kaltura_fu_spec.rb",
58
58
  "spec/metadata_spec.rb",
59
59
  "spec/spec_helper.rb"
@@ -1,10 +1,10 @@
1
1
  module KalturaFu
2
2
  module Configuration
3
3
 
4
- @@config = {}
5
- @@client = nil
6
- @@client_configuration = nil
7
- @@session_key = nil
4
+ @@config = {} #A Has containing the Kaltura server information
5
+ @@client = nil #An insantiated Kaltura::Client class
6
+ @@client_configuration = nil #Configuration values for the @@client.
7
+ @@session_key = nil #The Kaltura ks to use.
8
8
 
9
9
  def config
10
10
  @@config ||= {}
@@ -57,5 +57,5 @@ module KalturaFu
57
57
  end
58
58
 
59
59
  end #ClassMethods
60
- end
61
- end
60
+ end #Entry
61
+ end #KalturaFu
@@ -0,0 +1,117 @@
1
+ module KalturaFu
2
+ module Entry
3
+ ##
4
+ # The flavor module mixes in instance methods for a class that includes the Entry module. This
5
+ # module primarily provides means to operate on the original upload to Kaltura. It also contains
6
+ # a very important method for checking the overall status of a specific entry.
7
+ #
8
+ # @author Patrick Robertson
9
+ ##
10
+ module Flavor
11
+ ##
12
+ # Checks each flavor under a Kaltura entry for readiness. It is possible under v3 of the Kaltura API
13
+ # to receive a 'ready' status for the entry while flavors are still encoding. Attempting to view the entry
14
+ # with a player will result in a 'Media is converting' error screen. This prevents that occurance.
15
+ #
16
+ # @param [String] video_id Kaltura entry_id of the video.
17
+ #
18
+ # @return [Number] Kaltura::Constants::FlavorAssetStatus. 2 is ready.
19
+ ##
20
+ def check_status(entry_id)
21
+ KalturaFu.check_for_client_session
22
+
23
+ entry_status = get_status(entry_id)
24
+ if entry_status == Kaltura::Constants::Entry::Status::READY
25
+ flavor_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(entry_id)
26
+ error_count = 0
27
+ not_ready_count = 0
28
+ ready_count = 0
29
+ flavor_array.each do |flavor|
30
+ case flavor.status
31
+ when Kaltura::Constants::FlavorAssetStatus::READY || Kaltura::Constants::FlavorAssetStatus::DELETED || Kaltura::Constants::FlavorAssetStatus::NOT_APPLICABLE
32
+ ready_count +=1
33
+ when Kaltura::Constants::FlavorAssetStatus::ERROR
34
+ error_count +=1
35
+ when Kaltura::Constants::FlavorAssetStatus::QUEUED || Kaltura::Constants::FlavorAssetStatus::CONVERTING
36
+ not_ready_count +=1
37
+ end
38
+ end
39
+ #puts "errors: #{error_count} ready:#{ready_count} not_ready:#{not_ready_count} total:#{video_array.size} \n"
40
+ if error_count > 0
41
+ Kaltura::Constants::FlavorAssetStatus::ERROR
42
+ elsif not_ready_count > 0
43
+ Kaltura::Constants::FlavorAssetStatus::CONVERTING
44
+ else
45
+ Kaltura::Constants::FlavorAssetStatus::READY
46
+ end
47
+ else
48
+ entry_status
49
+ end
50
+ end
51
+
52
+ ##
53
+ # Returns the flavor ID of the original file uploaded to Kaltura.
54
+ #
55
+ # @param [String] video_id Kaltura entry_id of the video.
56
+ #
57
+ # @return [String] flavor_id
58
+ ##
59
+ def original_flavor(entry_id)
60
+ KalturaFu.check_for_client_session
61
+
62
+ flavor_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(entry_id)
63
+ ret_flavor = nil
64
+
65
+ flavor_array.each do |flavor|
66
+ if flavor.is_original
67
+ ret_flavor = flavor.id.to_s
68
+ break
69
+ end
70
+ end
71
+ ret_flavor
72
+ end
73
+
74
+ ##
75
+ # Returns the file extension of the original file uploaded to Kaltura for a given entry
76
+ #
77
+ # @param [String] video_id Kaltura entry_id of the video.
78
+ #
79
+ # @return [String] file extension
80
+ ##
81
+ def original_file_extension(entry_id)
82
+ KalturaFu.check_for_client_session
83
+
84
+ flavor_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(entry_id)
85
+ source_extension = nil
86
+ flavor_array.each do |flavor|
87
+ if flavor.is_original
88
+ source_extension = flavor.file_ext
89
+ break
90
+ end
91
+ end
92
+ source_extension
93
+ end
94
+
95
+ ##
96
+ # Returns a download URL suitable to be used for iTunes one-click syndication. serveFlavor is not documented in KalturaAPI v3
97
+ # nor is the ?novar=0 paramter.
98
+ #
99
+ # @param [String] video_id Kaltura entry_id of the video
100
+ #
101
+ # @return [String] URL that works with RSS/iTunes syndication. Normal flavor serving is flakey with syndication.
102
+ ##
103
+ def original_download_url(video_id)
104
+ KalturaFu.check_for_client_session
105
+
106
+ service_url = KalturaFu.config[:service_url] || "http://www.kaltura.com"
107
+ partner_id = KalturaFu.config[:partner_id]
108
+ subpartner_id = (partner_id.to_i * 100).to_s
109
+ flavor = original_flavor(video_id)
110
+ extension = original_file_extension(video_id)
111
+
112
+ "#{service_url}/p/#{partner_id}/sp/#{subpartner_id}/serveFlavor/flavorId/#{flavor}/name/#{flavor}.#{extension}?novar=0"
113
+ end
114
+
115
+ end #Flavor
116
+ end #Entry
117
+ end #KalturaFu
@@ -1,5 +1,8 @@
1
1
  module KalturaFu
2
2
  module Entry
3
+ ##
4
+ # Instance level methods for the Entry module.
5
+ ##
3
6
  module InstanceMethods
4
7
  ##
5
8
  # Deletes a Kaltura entry. Unlike the base API delete method, this returns true/false based on success.
@@ -18,7 +21,7 @@ module KalturaFu
18
21
  rescue Kaltura::APIError => e
19
22
  false
20
23
  end
21
- end
24
+ end
22
25
 
23
26
  end
24
27
  end
@@ -2,6 +2,10 @@ module KalturaFu
2
2
  module Entry
3
3
  module Metadata
4
4
 
5
+ ##
6
+ # It is necessary to have the check for valid Kaltura MediaEntry methods available at both
7
+ # the class and instance level, so they are thrown into this module.
8
+ ##
5
9
  module ClassAndInstanceMethods
6
10
 
7
11
  ##
@@ -2,6 +2,13 @@ require 'active_support'
2
2
 
3
3
  module KalturaFu
4
4
  module Entry
5
+
6
+ ##
7
+ # The Metadata module provides methods that get/set and add metadata to the
8
+ # Kaltura installation.
9
+ #
10
+ # @author Patrick Robertson
11
+ ##
5
12
  module Metadata
6
13
 
7
14
  ##
@@ -1,5 +1,95 @@
1
1
  module KalturaFu
2
- module Entry
2
+
3
+ ##
4
+ # The entry module provides a slightly more intuitive interface to the
5
+ # Kaltura media service. It determines what retrieval and setting actions
6
+ # you can perform based upon the version of the Kaltura-Ruby library using
7
+ # reflection. This allows Kaltura_Fu to be a bit more future proof than the
8
+ # Kaltura API client itself! The tradeoff is that getting/adding/setting
9
+ # attributes are defined dynamically. The current behavior is that the first
10
+ # call to a dynamic method will then define all of Kaltura's media entries
11
+ # methods. This allows the module to be slightly lighter weight in the event
12
+ # that it is included in a class but never used, and faster than using method_missing
13
+ # lookups for 100% of the dynamic methods. The first call will be slower though,
14
+ # as it generates numerous other methods.
15
+ #
16
+ # == Usage
17
+ # The entry module is intended to be used to link Rails Models to Kaltura MediaEntry's.
18
+ # However, you should not perform these actions during a web application request. Doing
19
+ # so will slow down your request unecessarily. There is nearly nothing gained from adding a
20
+ # round trip to your Kaltura server to make an update synchronus. Instead, this module
21
+ # should mostly be used in processing a background request from an observer.
22
+ #
23
+ # == Uploading to Kaltura
24
+ # The entry module provides convienance to uploading directly to your installation of
25
+ # Kaltura. For your web application, there are two Kaltura flash widgets that perform
26
+ # a much better job of uploading files though. This functionality has been used in
27
+ # production environments that use lecture capture. A video file is placed in a folder,
28
+ # a script picks the file up, and then uploads it into Kaltura.
29
+ #
30
+ # The Kaltura API supports uploading media from files, URL's, and also has a batch action.
31
+ # The implementation of Kaltura Fu currently ignores the URL and batch methods, instead
32
+ # focusing on file uploading.
33
+ #
34
+ # @example A basic file upload example:
35
+ # media_file = File.new("/path/to/video.mp4")
36
+ # upload(media_file,:source => :file)
37
+ #
38
+ # @example A file upload with metadata fields populated:
39
+ # media_file = File.new("/path/to/video.mp4")
40
+ # upload(media_file, :source => :file,
41
+ # :name => "My Rad video",
42
+ # :description => "I'm capable of such rad things.",
43
+ # :tags => "rad,rowdy,video,h.264",
44
+ # :categories => "raditude"
45
+ # )
46
+ # == Getting, Setting, and Adding Metadata
47
+ # The entry module provides an easy mean to retrieve the current state and modify a Kaltura entry.
48
+ # For metadata fields that act as a list of objects, it also provides an easy way to append values
49
+ # onto the list. It uses get_ and set_ instead of the more common Ruby practice of using just the
50
+ # attribute and attribute= so that you can include this module in your model without conflict. Also,
51
+ # when you are performing actions on the category fields, the module is making sure these are available
52
+ # in the KMC by calling Kaltura's Category service.
53
+ #
54
+ # @example Retrieving metadata:
55
+ # get_name("1_q34aa52a")
56
+ # get_categories("1_q34aa52a")
57
+ #
58
+ # @example Setting metadata:
59
+ # set_name("1_q34aa52a", "waffles")
60
+ # set_categories("1_q34aa52a", "HD,h.264,live recording")
61
+ #
62
+ # @example Appending tags to an existing set:
63
+ # add_tags("1_q34aa52a","eductation, lecture capture")
64
+ #
65
+ # == Checking the Status of an Entry
66
+ # One unfortunate aspect of the Kaltura API is that an entry will report it's status as "ready"
67
+ # while flavors are still encoding. When you embed the entry on a webpage, it will render an
68
+ # error "Media is currently converting". The only solution is to instead check the status of
69
+ # each flavor instead to ensure total readiness.
70
+ #
71
+ # @example Checking an entries status:
72
+ # check_status("1_q34aa52a")
73
+ #
74
+ # == Retrieving Status About the Source Video
75
+ # Occasionally, you need to interact with the original video in some form or another with Kaltura.
76
+ # One production situation I have encountered in the past is maintaining a copy of the source video
77
+ # on a large data store seperate from Kaltura. It is extremely difficult to work with the download
78
+ # URL that Kaltura provides for that.
79
+ #
80
+ # @example Getting the Flavor ID of the original video associated with an entry:
81
+ # original_flavor("1_q34aa52a")
82
+ #
83
+ # @example Getting the file extension of the original video associated with an entry:
84
+ # original_file_extension("1_q34aa52a")
85
+ #
86
+ # @example Getting a usable download URL for the entries original file:
87
+ # original_download_url("1_q34aa52a")
88
+ #
89
+ # @author Patrick Robertson
90
+ ##
91
+ module Entry
92
+
3
93
  ##
4
94
  # @private
5
95
  ##
@@ -8,6 +98,7 @@ module KalturaFu
8
98
  base.class_eval do
9
99
  include Metadata
10
100
  include InstanceMethods
101
+ include Flavor
11
102
  end
12
103
  super
13
104
  end
data/lib/kaltura_fu.rb CHANGED
@@ -1,33 +1,52 @@
1
+ #--
2
+ # Copyright (c) 2010 Velir Studios
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  ##
2
- # The KalturaFu module provides a singleton implementation for Kaltura API interaction. It stores session and API client information so that they do not need to be reset.
25
+ # The KalturaFu module provides a singleton implementation for Kaltura API interaction.
26
+ # It stores session and API client information so that they do not need to be reset.
27
+ #
3
28
  # @author Patrick Robertson
4
29
  #
5
- # @example Initilize a session:
6
- # KalturaFu.generate_session_key #=> "OTQyNzA2NzAxNzZmNDQyMTA1YzBiNzA5YWFjNzQ0ODNjODQ5MjZkM3wyMDM4MjI7MjAzODIyOzEyODUzNTA2ODg7MjsxMjg1MjY0Mjg4LjI2NTs7"
7
- # @example Retrieve a client object:
8
- # client = KalturaFu.client #=> #<Kaltura::Client:0x1071e39f0 @session_service=#<Kaltura::Service::SessionService:0x1071e3900 @client=#<Kaltura::Client:0x1071e39f0 ...>>, @calls_queue=[], @should_log=false, @is_multirequest=false, @ks="OTQyNzA2NzAxNzZmNDQyMTA1YzBiNzA5YWFjNzQ0ODNjODQ5MjZkM3wyMDM4MjI7MjAzODIyOzEyODUzNTA2ODg7MjsxMjg1MjY0Mjg4LjI2NTs7", @config=#<Kaltura::Configuration:0x1071e39c8 @client_tag="ruby", @format=2, @service_url="http://www.kaltura.com", @partner_id="20322323", @timeout=10>>
9
- # @example Clear a session:
10
- # KalturaFu.clear_session_key! #=> nil
11
30
  ##
12
31
  require 'rubygems'
13
32
  require 'kaltura'
33
+ require 'active_support/all'
14
34
 
15
35
  module KalturaFu
16
36
 
17
37
  #Initilize the configuration and send the ViewHelpers into ActionView::Base when it's a Rails 3 app.
18
38
  require 'kaltura_fu/railtie' if defined?(Rails) && Rails.version.split(".").first == "3"
19
39
 
20
- autoload :Video, 'kaltura_fu/video'
21
- autoload :Category, 'kaltura_fu/category'
22
- autoload :Report, 'kaltura_fu/report'
23
40
  autoload :Configuration, 'kaltura_fu/configuration'
24
41
  autoload :Entry, 'kaltura_fu/entry'
25
42
 
26
43
  module Entry
44
+
27
45
  autoload :Metadata, 'kaltura_fu/entry/metadata'
28
46
  autoload :ClassMethods, 'kaltura_fu/entry/class_methods'
29
47
  autoload :InstanceMethods, 'kaltura_fu/entry/instance_methods'
30
-
48
+ autoload :Flavor, 'kaltura_fu/entry/flavor'
49
+
31
50
  module Metadata
32
51
  autoload :ClassMethods, 'kaltura_fu/entry/metadata/class_methods'
33
52
  autoload :ClassAndInstanceMethods, 'kaltura_fu/entry/metadata/class_and_instance_methods'
data/spec/entry_spec.rb CHANGED
@@ -70,4 +70,5 @@ describe "Kaltura Fu's Entry Class Methods" do
70
70
  check = @tester.delete_entry(entry_id)
71
71
  check.should be_true
72
72
  end
73
+
73
74
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ class FlavorSpecTester
4
+ include KalturaFu::Entry
5
+ end
6
+
7
+ class EntryUploader
8
+ include KalturaFu::Entry
9
+ end
10
+
11
+ describe "Actions specific to an entries flavors" do
12
+ before(:all) do
13
+ KalturaFuTestConfiguration.setup
14
+ end
15
+
16
+ before(:each) do
17
+ @entry_id = EntryUploader.upload(KalturaFuTestConfiguration.video,:source=>:file)
18
+ end
19
+
20
+ after(:each) do
21
+ EntryUploader.new.delete_entry(@entry_id)
22
+ end
23
+
24
+ it "should return a status of not-ready when a video uploads" do
25
+ flavor = FlavorSpecTester.new
26
+ flavor.check_status(@entry_id).should_not == Kaltura::Constants::FlavorAssetStatus::READY
27
+ end
28
+
29
+ it "should respond to original_flavor" do
30
+ flavor = FlavorSpecTester.new
31
+
32
+ flavor.should respond_to :original_flavor
33
+ end
34
+
35
+ it "should be able to get the original flavor ID without an error" do
36
+ flavor = FlavorSpecTester.new
37
+
38
+ lambda{flavor.original_flavor(@entry_id)}.should_not raise_error
39
+ end
40
+
41
+ it "should respond to original_file_extension" do
42
+ flavor = FlavorSpecTester.new
43
+
44
+ flavor.should respond_to :original_file_extension
45
+ end
46
+
47
+ it "should be able to get the original file extension without error" do
48
+ flavor = FlavorSpecTester.new
49
+
50
+ lambda{flavor.original_file_extension(@entry_id)}.should_not raise_error
51
+ end
52
+
53
+ it "should have a file extension of FLV for the test video" do
54
+ flavor = FlavorSpecTester.new
55
+
56
+ extension = nil
57
+ extension = flavor.original_file_extension(@entry_id)
58
+ extension.should == "flv"
59
+ end
60
+
61
+ it "should respond to original_download_url" do
62
+ flavor = FlavorSpecTester.new
63
+
64
+ flavor.should respond_to :original_download_url
65
+ end
66
+
67
+ it "shouldn't blow up when I call original_download_url" do
68
+ flavor = FlavorSpecTester.new
69
+
70
+ lambda {flavor.original_download_url(@entry_id)}.should_not raise_error
71
+ end
72
+
73
+ it "original_download_url should look like a reasonable URL" do
74
+ flavor = FlavorSpecTester.new
75
+
76
+ url = flavor.original_download_url(@entry_id)
77
+ test_url = "#{KalturaFu.config[:service_url]}/p/#{KalturaFu.config[:partner_id]}/sp/#{KalturaFu.config[:subpartner_id]}/serveFlavor/flavorId/#{flavor.original_flavor(@entry_id)}/name/#{flavor.original_flavor(@entry_id)}.#{flavor.original_file_extension(@entry_id)}?novar=0"
78
+ url.should == test_url
79
+ end
80
+
81
+ it "should respond to changes in service_url" do
82
+ flavor = FlavorSpecTester.new
83
+ old_service_url = KalturaFu.config[:service_url]
84
+ KalturaFu.config[:service_url] = "http://www.waffles.com"
85
+
86
+ url = flavor.original_download_url(@entry_id)
87
+ test_url = "http://www.waffles.com/p/#{KalturaFu.config[:partner_id]}/sp/#{KalturaFu.config[:subpartner_id]}/serveFlavor/flavorId/#{flavor.original_flavor(@entry_id)}/name/#{flavor.original_flavor(@entry_id)}.#{flavor.original_file_extension(@entry_id)}?novar=0"
88
+ KalturaFu.config[:service_url] = old_service_url
89
+ url.should == test_url
90
+ end
91
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaltura_fu
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Patrick Robertson
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-11-05 00:00:00 -04:00
18
+ date: 2010-11-06 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 27
28
30
  segments:
29
31
  - 1
30
32
  - 3
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 3
43
46
  segments:
44
47
  - 0
45
48
  version: "0"
@@ -53,6 +56,7 @@ dependencies:
53
56
  requirements:
54
57
  - - ">="
55
58
  - !ruby/object:Gem::Version
59
+ hash: 9
56
60
  segments:
57
61
  - 0
58
62
  - 4
@@ -83,18 +87,17 @@ files:
83
87
  - lib/kaltura_fu/configuration.rb
84
88
  - lib/kaltura_fu/entry.rb
85
89
  - lib/kaltura_fu/entry/class_methods.rb
90
+ - lib/kaltura_fu/entry/flavor.rb
86
91
  - lib/kaltura_fu/entry/instance_methods.rb
87
92
  - lib/kaltura_fu/entry/metadata.rb
88
93
  - lib/kaltura_fu/entry/metadata/class_and_instance_methods.rb
89
94
  - lib/kaltura_fu/entry/metadata/class_methods.rb
90
- - lib/kaltura_fu/flavor.rb
91
95
  - lib/kaltura_fu/railtie.rb
92
- - lib/kaltura_fu/report.rb
93
- - lib/kaltura_fu/video.rb
94
96
  - lib/kaltura_fu/view_helpers.rb
95
97
  - rails/init.rb
96
98
  - spec/debug.log
97
99
  - spec/entry_spec.rb
100
+ - spec/flavor_spec.rb
98
101
  - spec/kaltura_fu_spec.rb
99
102
  - spec/metadata_spec.rb
100
103
  - spec/spec.opts
@@ -114,6 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
117
  requirements:
115
118
  - - ">="
116
119
  - !ruby/object:Gem::Version
120
+ hash: 3
117
121
  segments:
118
122
  - 0
119
123
  version: "0"
@@ -122,6 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
126
  requirements:
123
127
  - - ">="
124
128
  - !ruby/object:Gem::Version
129
+ hash: 3
125
130
  segments:
126
131
  - 0
127
132
  version: "0"
@@ -134,6 +139,7 @@ specification_version: 3
134
139
  summary: Rails gem for making Kaltura integrations easier.
135
140
  test_files:
136
141
  - spec/entry_spec.rb
142
+ - spec/flavor_spec.rb
137
143
  - spec/kaltura_fu_spec.rb
138
144
  - spec/metadata_spec.rb
139
145
  - spec/spec_helper.rb
@@ -1,89 +0,0 @@
1
- module KalturaFu
2
- ##
3
- # The Flavor module provides interactions for adding and removing specific encodings from a Kaltura entry.
4
- ##
5
- module Flavor
6
-
7
- ##
8
- # Adds a specific encoding profile to a Kaltura entry.
9
- #
10
- # @param [String] video_id The Kaltura media entry.
11
- # @param [Integer] flavor_param_id The ID of the FlavorParam (individual encoding profile) to use.
12
- #
13
- # @return [nil] Returns nothing.
14
- #
15
- # @raie [RuntimeError] Raises a runtime error if the video_id doesn't exist.
16
- #
17
- # @since 0.1.3
18
- #
19
- # @todo Make this method return something.
20
- ##
21
- def add_flavor_to_video(video_id,flavor_param_id)
22
- self.check_for_client_session
23
-
24
- if video_exists?(video_id)
25
- @@client.flavor_asset_service.convert(video_id,flavor_param_id)
26
- end
27
- end
28
-
29
- ##
30
- # Finds a specific flavor object given a Kaltura entry and FlavorParam. This is useful if you want to
31
- # delete a specific type of encoding from a Video programatically.
32
- #
33
- # @param [String] video_id The Kaltura media entry.
34
- # @param [Integer] flavor_param_id The ID of the FlavorParam (individual encoding profile) to use.
35
- #
36
- # @return [Kaltura::FlavorAsset] Returns the requested FlavorAsset.
37
- #
38
- # @raise [RuntimeError] Raises a runtime error if the video_id doesn't exist.
39
- #
40
- # @since 0.1.3
41
- #
42
- # @todo Ensure a graceful error when the FlavorAsset isn't found as well.
43
- ##
44
- def find_flavor_from_entry(video_id,flavor_param_id)
45
- self.check_for_client_session
46
- return_flavor = nil
47
-
48
- if video_exists?(video_id)
49
- flavor_array = @@client.flavor_asset_service.get_flavor_assets_with_params(video_id)
50
- flavor_array.each do |flavor_object|
51
- if flavor_object.flavor_params.id == flavor_param_id
52
- return_flavor = flavor_object.flavor_asset.id
53
- end
54
- end
55
- end
56
- end
57
-
58
- ##
59
- # Removes either a specific flavor asset. If you know the exact Flavor you wish to delete
60
- # you can specify it. Otherwise, you can specify the videos entry_id and a specific
61
- # FlavorParam (encoding profile) and it will locate and remove the Flavor for you.
62
- #
63
- # @param [String] entry_or_flavor The Kaltura entry_id or the FlavorAsset ID.
64
- # @param [Integer] flavor_param_id An optional flavorParam encoding profile to seek.
65
- #
66
- # @return [Boolean] Returns true if the removal was succesful.
67
- #
68
- # @raise [RuntimeError] Raises a runtime error if the video's entry_id doesn't exist.
69
- #
70
- # @since 0.1.3
71
- #
72
- # @todo Ensure that a missing FlavorParam or FlavorAsset doesn't cause unexpected behavior.
73
- ##
74
- def remove_flavor_from_video(entry_or_flavor, flavor_param_id=nil)
75
- self.check_for_client_session
76
- ret_val = false
77
-
78
- if flavor_param_id.nil?
79
- @@client.flavor_asset_service.delete(entry_or_flavor)
80
- ret_val = true
81
- else
82
- flavor_to_delete = self.find_flavor_from_entry(entry_or_flavor,flavor_param_id)
83
- self.remove_flavor_from_video(flavor_to_delete)
84
- end
85
- ret_val
86
- end
87
-
88
- end
89
- end
@@ -1,147 +0,0 @@
1
- module KalturaFu
2
-
3
- ##
4
- # The Report module provides class methods to retrieve analytic information and reports from Kaltura entries.
5
- #
6
- # @author Patrick Robertson
7
- ##
8
- module Report
9
-
10
- ##
11
- # Returns an Array of hashes that contains a Kaltura content drop-off report ordered by # of plays descending.
12
- # Kaltura treats # of plays as a string, so 5 comes before 353.
13
- #
14
- # @param [Date] from_date The starting date for the report. The end date is currently always today.
15
- # @param [String] video_list a comma delimited list of Kaltura entry_id's to report upon.
16
- #
17
- # @return [Array] An array of Hashes that contains the entry_id, total plays, and then plays for 25%, 50%, 75% and 100% through the content.
18
- ##
19
- def generate_report(from_date,video_list)
20
- hash_array = []
21
-
22
- KalturaFu.check_for_client_session
23
-
24
- report_filter = Kaltura::Filter::ReportInputFilter.new
25
- report_filter.from_date = from_date.to_i
26
- report_filter.to_date = Time.now.utc.to_i
27
- report_pager = Kaltura::FilterPager.new
28
- report_pager.page_size = 1000
29
-
30
- report_raw = KalturaFu.client.report_service.get_table(Kaltura::Constants::ReportType::CONTENT_DROPOFF,
31
- report_filter,
32
- report_pager,
33
- Kaltura::Constants::Media::OrderBy::PLAYS_DESC,
34
- video_list)
35
- unless report_raw.data.nil?
36
- report_split_by_entry = report_raw.data.split(";")
37
- report_split_by_entry.each do |row|
38
- segment = row.split(",")
39
- row_hash = {}
40
- row_hash[:entry_id] = segment.at(0)
41
- row_hash[:plays] = segment.at(2)
42
- row_hash[:play_through_25] = segment.at(3)
43
- row_hash[:play_through_50] = segment.at(4)
44
- row_hash[:play_through_75] = segment.at(5)
45
- row_hash[:play_through_100] = segment.at(6)
46
- hash_array << row_hash
47
- end
48
-
49
- hash_array = hash_array.sort{|a,b| b[:plays].to_i <=> a[:plays].to_i}
50
- end
51
- hash_array
52
- end
53
-
54
- ##
55
- # creates a report CSV on the kaltura server and then returns the url to grab it. Unfortunately the MIME type of the resource is "text/plain"
56
- # instead of "text/csv" so there isn't a ton you can do with it.
57
- #
58
- # @param [Date] from_date The starting date for the report. The end date is currently always today.
59
- # @param [String] video_list a comma delimited list of Kaltura entry_id's to report upon.
60
- #
61
- # @return [String] URL to grab the report in CSV format.
62
- ##
63
- def generate_report_csv_url(from_date,video_list)
64
- report_title = "TTV Video Report"
65
- report_text = "I'm not sure what this is"
66
- headers = "Kaltura Entry,Plays,25% Play-through,50% Play-through, 75% Play-through, 100% Play-through, Play-Through Ratio"
67
-
68
- KalturaFu.check_for_client_session
69
-
70
- report_filter = Kaltura::Filter::ReportInputFilter.new
71
- report_filter.from_date = from_date.to_i
72
- report_filter.to_date = Time.now.utc.to_i
73
- report_pager = Kaltura::FilterPager.new
74
- report_pager.page_size = 1000
75
-
76
- report_url = KalturaFu.client.report_service.get_url_for_report_as_csv(report_title,
77
- report_text,
78
- headers,
79
- Kaltura::Constants::ReportType::CONTENT_DROPOFF,
80
- report_filter,
81
- "",
82
- report_pager,
83
- Kaltura::Constants::Media::OrderBy::PLAYS_DESC,
84
- video_list)
85
- report_url
86
- end
87
-
88
- ##
89
- # Returns a grand total of the plays broken down by content drop-off given a list of Kaltura entries.
90
- #
91
- # @param [Date] from_date The starting date for the report. The end date is currently always today.
92
- # @param [String] video_list a comma delimited list of Kaltura entry_id's to report upon.
93
- #
94
- # @return [Hash] a list that contains total plays and plays broken down to 25%, 50%, 75%, and 100% through content.
95
- ##
96
- def generate_report_total(from_date,video_list)
97
- row_hash = {}
98
-
99
- KalturaFu.check_for_client_session
100
-
101
- report_filter = Kaltura::Filter::ReportInputFilter.new
102
- report_filter.from_date = from_date.to_i
103
- report_filter.to_date = Time.now.utc.to_i
104
- report_raw = KalturaFu.client.report_service.get_total(Kaltura::Constants::ReportType::CONTENT_DROPOFF,
105
- report_filter,
106
- video_list)
107
- unless report_raw.data.nil?
108
- segment = report_raw.data.split(",")
109
- row_hash[:plays] = segment.at(0)
110
- row_hash[:play_through_25] = segment.at(1)
111
- row_hash[:play_through_50] = segment.at(2)
112
- row_hash[:play_through_75] = segment.at(3)
113
- row_hash[:play_through_100] = segment.at(4)
114
-
115
- row_hash
116
- end
117
- end
118
-
119
- ##
120
- # Returns the total number of Kaltura entries that had any plays during the reporting period.
121
- #
122
- # @param [Date] from_date The starting date for the report. The end date is currently always today.
123
- # @param [String] video_list a comma delimited list of Kaltura entry_id's to report upon.
124
- ##
125
- def generate_report_video_count(from_date,video_list)
126
- row_hash = {}
127
-
128
- KalturaFu.check_for_client_session
129
-
130
- report_filter = Kaltura::Filter::ReportInputFilter.new
131
- report_filter.from_date = from_date.to_i
132
- report_filter.to_date = Time.now.utc.to_i
133
- report_pager = Kaltura::FilterPager.new
134
- report_pager.page_size = 1000
135
-
136
- report_raw = KalturaFu.client.report_service.get_table(Kaltura::Constants::ReportType::CONTENT_DROPOFF,
137
- report_filter,
138
- report_pager,
139
- Kaltura::Constants::Media::OrderBy::PLAYS_DESC,
140
- video_list)
141
- unless report_raw.data.nil?
142
- report_raw.total_count
143
- end
144
- end
145
-
146
- end
147
- end
@@ -1,190 +0,0 @@
1
- module KalturaFu
2
- ##
3
- # the Video module provides class methods to retrieve and set information specific to Kaltura Entries.
4
- # @author Patrick Robertson
5
- ##
6
- module Video
7
-
8
- ##
9
- # Checks each flavor under a Kaltura entry for readiness. It is possible under v3 of the Kaltura API
10
- # to receive a 'ready' status for the entry while flavors are still encoding. Attempting to view the entry
11
- # with a player will result in a 'Media is converting' error screen. This prevents that occurance.
12
- #
13
- # @param [String] video_id Kaltura entry_id of the video.
14
- #
15
- # @return [Number] Kaltura::Constants::FlavorAssetStatus. 2 is ready.
16
- ##
17
- def check_video_status(video_id)
18
- KalturaFu.check_for_client_session
19
-
20
- video_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(video_id)
21
- status = Kaltura::Constants::FlavorAssetStatus::ERROR
22
- video_array.each do |video|
23
- status = video.status
24
- if video.status != Kaltura::Constants::FlavorAssetStatus::READY
25
- if video.status == Kaltura::Constants::FlavorAssetStatus::NOT_APPLICABLE
26
- status = Kaltura::Constants::FlavorAssetStatus::READY
27
- else
28
- break
29
- end
30
- end
31
- end
32
- status
33
- end
34
-
35
- ##
36
- # Deletes a Kaltura entry.
37
- #
38
- # @param [String] video_id Kaltura entry_id of the video.
39
- #
40
- # @return [Boolean] returns true if the delete was successful or false otherwise.
41
- ##
42
- def delete_video(video_id)
43
- KalturaFu.check_for_client_session
44
-
45
- begin
46
- KalturaFu.client.media_service.delete(video_id)
47
- true
48
- rescue Kaltura::APIError => e
49
- false
50
- end
51
- end
52
-
53
- ##
54
- # Returns the flavor of the original file uploaded to Kaltura.
55
- #
56
- # @param [String] video_id Kaltura entry_id of the video.
57
- #
58
- # @return [String] flavor_id
59
- ##
60
- def get_original_flavor(video_id)
61
- KalturaFu.check_for_client_session
62
-
63
- video_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(video_id)
64
- ret_flavor = nil
65
-
66
- video_array.each do |video|
67
- if video.is_original
68
- ret_flavor = video.id.to_s
69
- end
70
- end
71
- ret_flavor
72
- end
73
-
74
- ##
75
- # Returns the file extension of the original file uploaded to Kaltura for a given entry
76
- #
77
- # @param [String] video_id Kaltura entry_id of the video.
78
- #
79
- # @return [String] file extension
80
- ##
81
- def get_original_file_extension(video_id)
82
- KalturaFu.check_for_client_session
83
-
84
- video_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(video_id)
85
- source_extension = nil
86
- video_array.each do |video|
87
- if video.is_original
88
- source_extension = video.file_ext
89
- end
90
- end
91
- source_extension
92
- end
93
-
94
- ##
95
- # Returns the URL of the requested video.
96
- #
97
- # @param [String] video_id Kaltura entry_id of the video.
98
- # @param [Number] time optional paramter that will set the thumbnail to a particular second of the video
99
- # @param [Number] width optional width of the thumbnail. Defaults to the thumb_width config value.
100
- # @param [Number] height optional height of the thumbnail. Defaults to the thumb_height config value.
101
- #
102
- # @return [String] the thumbnail url.
103
- ##
104
- def get_thumbnail(video_id,time=nil,width=@@config[:thumb_width],height=@@config[:thumb_height])
105
- config = KalturaFu.config
106
-
107
- thumbnail_string = "#{config[:service_url]}/p/#{config[:partner_id]}/thumbnail/entry_id/#{video_id}/width/#{width}/height/#{height}"
108
- thumbnail_string += "/vid_sec/#{time}" unless time.nil?
109
- return thumbnail_string
110
- end
111
-
112
- ##
113
- # Gets a Kaltura::MediaEntry given a Kaltura entry.
114
- #
115
- # @param [String] video_id Kaltura entry_id of the video.
116
- #
117
- # @return [Kaltura::MediaEntry] The MediaEntry object for the Kaltura entry.
118
- ##
119
- def get_video_info(video_id)
120
- KalturaFu.check_for_client_session
121
-
122
- response = self.video_exists?(video_id)
123
- raise "ID: #{video_id} Not found!" unless response
124
- response
125
- end
126
-
127
- ##
128
- # Returns a download URL suitable to be used for iTunes one-click syndication. serveFlavor is not documented in KalturaAPI v3
129
- # nor is the ?novar=0 paramter.
130
- #
131
- # @param [String] video_id Kaltura entry_id of the video
132
- #
133
- # @return [String] URL that works with RSS/iTunes syndication. Normal flavor serving is flakey with syndication.
134
- ##
135
- def set_syndication_url(video_id)
136
- KalturaFu.check_for_client_session
137
-
138
- video_array = KalturaFu.client.flavor_asset_service.get_by_entry_id(video_id)
139
-
140
- download_url = nil
141
- video_array.each do |video|
142
- if video.is_original
143
- download_url = 'http://www.kaltura.com/p/203822/sp/20382200/serveFlavor/flavorId/' + video.id.to_s + '/name/' + video.id.to_s + '.' + video.file_ext.to_s + '?novar=0'
144
- end
145
- end
146
- download_url
147
- end
148
-
149
- ##
150
- # Sets the Kaltura entry description metadata.
151
- #
152
- # @param [String] video_id Kaltura entry_id of the video.
153
- # @param [String] description description to add to the Kaltura video.
154
- #
155
- # @return [Boolean] returns true if the update was successful or false otherwise.
156
- ##
157
- def set_video_description(video_id,description)
158
- KalturaFu.check_for_client_session
159
-
160
- if self.video_exists?(video_id)
161
- new_entry = Kaltura::MediaEntry.new
162
- new_entry.description = description
163
- KalturaFu.client.media_service.update(video_id,new_entry)
164
- true
165
- else
166
- false
167
- end
168
- end
169
-
170
- protected
171
- ##
172
- # Checks if a Kaltura entry exists.
173
- # @private
174
- def video_exists?(video_id)
175
- KalturaFu.check_for_client_session
176
-
177
- begin
178
- response = KalturaFu.client.media_service.get(video_id)
179
- rescue Kaltura::APIError => e
180
- response = nil
181
- end
182
- if response.nil?
183
- false
184
- else
185
- response
186
- end
187
- end
188
-
189
- end
190
- end