kaltura_fu 0.1.0.prel
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +66 -0
- data/Rakefile +57 -0
- data/VERSION.yml +5 -0
- data/config/kaltura.yml +22 -0
- data/install.rb +1 -0
- data/javascripts/kaltura_upload.js +67 -0
- data/kaltura_fu.gemspec +65 -0
- data/lib/kaltura_fu/category.rb +112 -0
- data/lib/kaltura_fu/report.rb +147 -0
- data/lib/kaltura_fu/video.rb +190 -0
- data/lib/kaltura_fu/view_helpers.rb +182 -0
- data/lib/kaltura_fu.rb +112 -0
- data/rails/init.rb +22 -0
- data/spec/kaltura_fu_spec.rb +166 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/kaltura_fu_tasks.rake +45 -0
- data/test/kaltura_fu_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +108 -0
@@ -0,0 +1,190 @@
|
|
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
|
@@ -0,0 +1,182 @@
|
|
1
|
+
module KalturaFu
|
2
|
+
|
3
|
+
##
|
4
|
+
# The ViewHelpers module provides extensions to Rails ActionView class that allow interactions with Kaltura on rails view layer.
|
5
|
+
#
|
6
|
+
# @author Patrick Robertson
|
7
|
+
##
|
8
|
+
module ViewHelpers
|
9
|
+
# default UI Conf ID of the kdp player
|
10
|
+
DEFAULT_KPLAYER = '1339442'
|
11
|
+
# default embedded KDP width
|
12
|
+
PLAYER_WIDTH = '400'
|
13
|
+
# default embedded KDP height
|
14
|
+
PLAYER_HEIGHT = '330'
|
15
|
+
|
16
|
+
##
|
17
|
+
# Convienence to include SWFObject and the required Kaltura upload embed javascripts.
|
18
|
+
##
|
19
|
+
def include_kaltura_fu(*args)
|
20
|
+
content = javascript_include_tag('kaltura_upload')
|
21
|
+
content << "\n#{javascript_include_tag('http://ajax.googleapis.com' +
|
22
|
+
'/ajax/libs/swfobject/2.2/swfobject.js')}"
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Returns the thumbnail of the provided Kaltura Entry.
|
27
|
+
# @param [String] entry_id Kaltura entry_id
|
28
|
+
# @param [Hash] options the options for the thumbnail parameters.
|
29
|
+
# @option options [Array] :size ([]) an array of [width,height]
|
30
|
+
# @option options [String] :second (nil) the second of the Kaltura entry that the thumbnail should be of.
|
31
|
+
#
|
32
|
+
# @return [String] Image tag of the thumbnail resource.
|
33
|
+
##
|
34
|
+
def kaltura_thumbnail(entry_id,options={})
|
35
|
+
options[:size] ||= []
|
36
|
+
size_parameters = ""
|
37
|
+
seconds_parameter = ""
|
38
|
+
|
39
|
+
unless options[:size].empty?
|
40
|
+
size_parameters = "/width/#{options[:size].first}/height/" +
|
41
|
+
"#{options[:size].last}"
|
42
|
+
else
|
43
|
+
# if the thumbnail width and height are defined in the config,
|
44
|
+
# use it, assuming it wasn't locally overriden
|
45
|
+
if KalturaFu.config[:thumb_width] && KalturaFu.config[:thumb_height]
|
46
|
+
size_parameters = "/width/#{KalturaFu.config[:thumb_width]}/height/" +
|
47
|
+
"#{KalturaFu.config[:thumb_height]}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
unless options[:second].nil?
|
52
|
+
seconds_parameter = "/vid_sec/#{options[:second]}"
|
53
|
+
else
|
54
|
+
seconds_parameter = "/vid_sec/5"
|
55
|
+
end
|
56
|
+
|
57
|
+
image_tag("http://www.kaltura.com/p/#{KalturaFu.config[:partner_id]}" +
|
58
|
+
"/thumbnail/entry_id/#{entry_id}" +
|
59
|
+
seconds_parameter +
|
60
|
+
size_parameters)
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Returns the code needed to embed a KDPv3 player.
|
65
|
+
#
|
66
|
+
# @param [String] entry_id Kaltura entry_id
|
67
|
+
# @param [Hash] options the embed code options.
|
68
|
+
# @option options [String] :div_id ('kplayer') The div element that the flash object will be inserted into.
|
69
|
+
# @option options [Array] :size ([]) The [width,wight] of the player.
|
70
|
+
# @option options [Boolean] :use_url (false) flag to determine whether entry_id is an entry or a URL of a flash file.
|
71
|
+
# @option options [String] :player_conf_id (KalturaFu.config(:player_conf_id)) A UI Conf ID to override the player with.
|
72
|
+
#
|
73
|
+
# @return [String] returns a string representation of the html/javascript necessary to play a Kaltura entry.
|
74
|
+
##
|
75
|
+
def kaltura_player_embed(entry_id,options={})
|
76
|
+
player_conf_parameter = "/ui_conf_id/"
|
77
|
+
options[:div_id] ||= "kplayer"
|
78
|
+
options[:size] ||= []
|
79
|
+
options[:use_url] ||= false
|
80
|
+
width = PLAYER_WIDTH
|
81
|
+
height = PLAYER_HEIGHT
|
82
|
+
source_type = "entryId"
|
83
|
+
|
84
|
+
unless options[:size].empty?
|
85
|
+
width = options[:size].first
|
86
|
+
height = options[:size].last
|
87
|
+
end
|
88
|
+
|
89
|
+
if options[:use_url] == true
|
90
|
+
source_type = "url"
|
91
|
+
end
|
92
|
+
|
93
|
+
unless options[:player_conf_id].nil?
|
94
|
+
player_conf_parameter += "#{options[:player_conf_id]}"
|
95
|
+
else
|
96
|
+
unless KalturaFu.config[:player_conf_id].nil?
|
97
|
+
player_conf_parameter += "#{KalturaFu.config[:player_conf_id]}"
|
98
|
+
else
|
99
|
+
player_conf_parameter += "#{DEFAULT_KPLAYER}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
"<div id=\"#{options[:div_id]}\"></div>
|
104
|
+
<script type=\"text/javascript\">
|
105
|
+
var params= {
|
106
|
+
allowscriptaccess: \"always\",
|
107
|
+
allownetworking: \"all\",
|
108
|
+
allowfullscreen: \"true\",
|
109
|
+
wmode: \"opaque\"
|
110
|
+
};
|
111
|
+
var flashVars = {};
|
112
|
+
flashVars.sourceType = \"#{source_type}\";
|
113
|
+
flashVars.entryId = \"#{entry_id}\";
|
114
|
+
flashVars.emptyF = \"onKdpEmpty\";
|
115
|
+
flashVars.readyF = \"onKdpReady\";
|
116
|
+
|
117
|
+
var attributes = {
|
118
|
+
id: \"#{options[:div_id]}\",
|
119
|
+
name: \"#{options[:div_id]}\"
|
120
|
+
};
|
121
|
+
|
122
|
+
swfobject.embedSWF(\"http://www.kaltura.com/kwidget/wid/_#{KalturaFu.config[:partner_id]}" + player_conf_parameter + "\",\"#{options[:div_id]}\",\"#{width}\",\"#{height}\",\"10.0.0\",\"http://ttv.mit.edu/swfs/expressinstall.swf\",flashVars,params,attributes);
|
123
|
+
</script>"
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Returns the html/javascript necessary for a KSU widget.
|
128
|
+
#
|
129
|
+
# @param [Hash] options
|
130
|
+
# @option options [String] :div_id ('uploader') div that the flash object will be inserted into.
|
131
|
+
##
|
132
|
+
def kaltura_upload_embed(options={})
|
133
|
+
options[:div_id] ||="uploader"
|
134
|
+
"<div id=\"#{options[:div_id]}\"></div>
|
135
|
+
<script type=\"text/javascript\">
|
136
|
+
|
137
|
+
var params = {
|
138
|
+
allowScriptAccess: \"always\",
|
139
|
+
allowNetworking: \"all\",
|
140
|
+
wmode: \"transparent\"
|
141
|
+
};
|
142
|
+
var attributes = {
|
143
|
+
id: \"uploader\",
|
144
|
+
name: \"KUpload\"
|
145
|
+
};
|
146
|
+
var flashVars = {
|
147
|
+
uid: \"ANONYMOUS\",
|
148
|
+
partnerId: \"#{KalturaFu.config[:partner_id]}\",
|
149
|
+
subPId: \"#{KalturaFu.config[:subpartner_id]}\",
|
150
|
+
entryId: \"-1\",
|
151
|
+
ks: \"#{KalturaFu.session_key}\",
|
152
|
+
uiConfId: '1103',
|
153
|
+
jsDelegate: \"delegate\",
|
154
|
+
maxFileSize: \"999999999\",
|
155
|
+
maxTotalSize: \"999999999\"
|
156
|
+
};
|
157
|
+
|
158
|
+
swfobject.embedSWF(\"http://www.kaltura.com/kupload/ui_conf_id/1103\", \"uploader\", \"160\", \"26\", \"9.0.0\", \"expressInstall.swf\", flashVars, params,attributes);
|
159
|
+
|
160
|
+
</script>"
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# Creates a link_to tag that seeks to a certain time on a KDPv3 player.
|
165
|
+
#
|
166
|
+
# @param [String] content The text in the link tag.
|
167
|
+
# @param [Integer] seek_time The time in seconds to seek the player to.
|
168
|
+
# @param [Hash] options
|
169
|
+
#
|
170
|
+
# @option options [String] :div_id ('kplayer') The div of the KDP player.
|
171
|
+
##
|
172
|
+
def kaltura_seek_link(content,seek_time,options={})
|
173
|
+
options[:div_id] ||= "kplayer"
|
174
|
+
|
175
|
+
options[:onclick] = "$(#{options[:div_id]}).get(0).sendNotification('doSeek',#{seek_time});window.scrollTo(0,0);return false;"
|
176
|
+
options.delete(:div_id)
|
177
|
+
link_to(content,"#", options)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
end
|
data/lib/kaltura_fu.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
##
|
2
|
+
# @private
|
3
|
+
##
|
4
|
+
class Hash
|
5
|
+
|
6
|
+
##
|
7
|
+
# @private
|
8
|
+
##
|
9
|
+
def recursively_symbolize_keys
|
10
|
+
tmp = {}
|
11
|
+
for k, v in self
|
12
|
+
tmp[k] = if v.respond_to? :recursively_symbolize_keys
|
13
|
+
v.recursively_symbolize_keys
|
14
|
+
else
|
15
|
+
v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
tmp.symbolize_keys
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# 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.
|
24
|
+
# @author Patrick Robertson
|
25
|
+
#
|
26
|
+
# @example Initilize a session:
|
27
|
+
# KalturaFu.generate_session_key #=> "OTQyNzA2NzAxNzZmNDQyMTA1YzBiNzA5YWFjNzQ0ODNjODQ5MjZkM3wyMDM4MjI7MjAzODIyOzEyODUzNTA2ODg7MjsxMjg1MjY0Mjg4LjI2NTs7"
|
28
|
+
# @example Retrieve a client object:
|
29
|
+
# 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>>
|
30
|
+
# @example Clear a session:
|
31
|
+
# KalturaFu.clear_session_key! #=> nil
|
32
|
+
##
|
33
|
+
module KalturaFu
|
34
|
+
autoload :Video, 'kaltura_fu/video'
|
35
|
+
autoload :Category, 'kaltura_fu/category'
|
36
|
+
autoload :Report, 'kaltura_fu/report'
|
37
|
+
|
38
|
+
# Kaltura's ready state.
|
39
|
+
READY = Kaltura::Constants::FlavorAssetStatus::READY
|
40
|
+
|
41
|
+
|
42
|
+
@@config = {}
|
43
|
+
@@client = nil
|
44
|
+
@@client_configuration = nil
|
45
|
+
@@session_key = nil
|
46
|
+
mattr_reader :config
|
47
|
+
mattr_reader :client
|
48
|
+
mattr_reader :session_key
|
49
|
+
|
50
|
+
class << self
|
51
|
+
##
|
52
|
+
# @private
|
53
|
+
##
|
54
|
+
def config=(options)
|
55
|
+
@@config = options
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# @private
|
60
|
+
#
|
61
|
+
def create_client_config
|
62
|
+
@@client_configuration = Kaltura::Configuration.new(@@config[:partner_id])
|
63
|
+
unless @@config[:service_url].blank?
|
64
|
+
@@client_configuration.service_url = @@config[:service_url]
|
65
|
+
end
|
66
|
+
@@client_configuration
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# @private
|
71
|
+
##
|
72
|
+
def create_client
|
73
|
+
if @@client_configuration.nil?
|
74
|
+
self.create_client_config
|
75
|
+
end
|
76
|
+
@@client = Kaltura::Client.new(@@client_configuration)
|
77
|
+
@@client
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Generates a Kaltura ks and adds it to the KalturaFu client object.
|
82
|
+
#
|
83
|
+
# @return [String] a Kaltura KS.
|
84
|
+
##
|
85
|
+
def generate_session_key
|
86
|
+
self.check_for_client_session
|
87
|
+
|
88
|
+
@@session_key = @@client.session_service.start(@@config[:administrator_secret],'',Kaltura::Constants::SessionType::ADMIN)
|
89
|
+
@@client.ks = @@session_key
|
90
|
+
end
|
91
|
+
##
|
92
|
+
# Clears the current Kaltura ks.
|
93
|
+
##
|
94
|
+
def clear_session_key!
|
95
|
+
@@session_key = nil
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# @private
|
100
|
+
##
|
101
|
+
def check_for_client_session
|
102
|
+
if @@client.nil?
|
103
|
+
self.create_client
|
104
|
+
self.generate_session_key
|
105
|
+
true
|
106
|
+
else
|
107
|
+
true
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
#require 'kaltura-ruby'
|
5
|
+
require 'kaltura_fu'
|
6
|
+
|
7
|
+
ActionView::Base.send :include, KalturaFu::ViewHelpers
|
8
|
+
|
9
|
+
kaltura_yml = File.join(RAILS_ROOT,'config','kaltura.yml')
|
10
|
+
|
11
|
+
unless File.exists?(kaltura_yml)
|
12
|
+
raise RuntimeError, "Unable to find \"config/kaltura.yml\" file."
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
KalturaFu.config = YAML.load_file(kaltura_yml).recursively_symbolize_keys[RAILS_ENV.to_sym]
|
17
|
+
|
18
|
+
|
19
|
+
unless[:partner_id,:subpartner_id,:administrator_secret].all? {|key| KalturaFu.config.key?(key)}
|
20
|
+
raise RuntimeError, "Kaltura config requires :partner_id, :subpartner_id,"+
|
21
|
+
"and :administrator_secret keys"
|
22
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe KalturaFu, :type => :helper do
|
4
|
+
|
5
|
+
it "should have the proper javascript include tags" do
|
6
|
+
html = helper.include_kaltura_fu
|
7
|
+
|
8
|
+
html.should have_tag("script[src= ?]",
|
9
|
+
"http://ajax.googleapis.com/ajax/libs/swfobject" +
|
10
|
+
"/2.2/swfobject.js" )
|
11
|
+
|
12
|
+
html.should have_tag("script[src = ?]",
|
13
|
+
%r{/javascripts/kaltura_upload.js\?[0-9]*})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should create a plain thumbnail" do
|
17
|
+
html = helper.kaltura_thumbnail(12345)
|
18
|
+
|
19
|
+
|
20
|
+
if KalturaFu.config[:thumb_width] && KalturaFu.config[:thumb_height]
|
21
|
+
html.should have_tag("img[src = ?]" , "http://www.kaltura.com/p/" +
|
22
|
+
KalturaFu.config[:partner_id] +
|
23
|
+
"/thumbnail/entry_id/12345" + "/width/" +
|
24
|
+
KalturaFu.config[:thumb_width] + "/height/" +
|
25
|
+
KalturaFu.config[:thumb_height])
|
26
|
+
else
|
27
|
+
html.should have_tag("img[src = ?]",
|
28
|
+
"http://www.kaltura.com/p/" +
|
29
|
+
KalturaFu.config[:partner_id] +
|
30
|
+
"/thumbnail/entry_id/12345")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
it "should create an appropriately sized thumbnail" do
|
34
|
+
html = helper.kaltura_thumbnail(12345,:size=>[800,600])
|
35
|
+
|
36
|
+
html.should have_tag("img[src = ?]", "http://www.kaltura.com/p/" +
|
37
|
+
KalturaFu.config[:partner_id] +
|
38
|
+
"/thumbnail/entry_id/12345" + "/width/800" +
|
39
|
+
"/height/600")
|
40
|
+
end
|
41
|
+
it "should create a thumbnail at the right second" do
|
42
|
+
html = helper.kaltura_thumbnail(12345,:size=>[800,600],:second=> 6)
|
43
|
+
|
44
|
+
html.should have_tag("img[src = ?]", "http://www.kaltura.com/p/" +
|
45
|
+
KalturaFu.config[:partner_id] +
|
46
|
+
"/thumbnail/entry_id/12345" + "/vid_sec/6" +
|
47
|
+
"/width/800/height/600")
|
48
|
+
end
|
49
|
+
it "should embed a default player" do
|
50
|
+
html = helper.kaltura_player_embed(12345)
|
51
|
+
|
52
|
+
#check the outer div
|
53
|
+
html.should have_tag("div#kplayer")
|
54
|
+
|
55
|
+
# check the parameters
|
56
|
+
html.should have_tag("script",%r{allowscriptaccess: "always"})
|
57
|
+
html.should have_tag("script",%r{allownetworking: "all"})
|
58
|
+
html.should have_tag("script",%r{allowfullscreen: "true"})
|
59
|
+
html.should have_tag("script",%r{wmode: "opaque"})
|
60
|
+
|
61
|
+
# check the vars
|
62
|
+
html.should have_tag("script",%r{entryId: "12345"})
|
63
|
+
|
64
|
+
# check the embed
|
65
|
+
html.should have_tag("script",%r{swfobject.embedSWF})
|
66
|
+
html.should have_tag("script",
|
67
|
+
%r{http://www.kaltura.com/kwidget/wid/_#{KalturaFu.config[:partner_id]}})
|
68
|
+
if KalturaFu.config[:player_conf_id]
|
69
|
+
html.should have_tag("script",
|
70
|
+
%r{/ui_conf_id/#{KalturaFu.config[:player_conf_id]}})
|
71
|
+
else
|
72
|
+
html.should have_tag("script",
|
73
|
+
%r{/ui_conf_id/#{KalturaFu::ViewHelpers::DEFAULT_KPLAYER}})
|
74
|
+
end
|
75
|
+
html.should have_tag("script",%r{"kplayer","400","330"})
|
76
|
+
end
|
77
|
+
it "should embed a player with a different div" do
|
78
|
+
html = helper.kaltura_player_embed(12345,:div_id=>"waffles")
|
79
|
+
|
80
|
+
#check the outer div
|
81
|
+
html.should have_tag("div#waffles")
|
82
|
+
|
83
|
+
# check the parameters
|
84
|
+
html.should have_tag("script",%r{allowscriptaccess: "always"})
|
85
|
+
html.should have_tag("script",%r{allownetworking: "all"})
|
86
|
+
html.should have_tag("script",%r{allowfullscreen: "true"})
|
87
|
+
html.should have_tag("script",%r{wmode: "opaque"})
|
88
|
+
|
89
|
+
# check the vars
|
90
|
+
html.should have_tag("script",%r{entryId: "12345"})
|
91
|
+
|
92
|
+
# check the embed
|
93
|
+
html.should have_tag("script",%r{swfobject.embedSWF})
|
94
|
+
html.should have_tag("script",
|
95
|
+
%r{http://www.kaltura.com/kwidget/wid/_#{KalturaFu.config[:partner_id]}})
|
96
|
+
if KalturaFu.config[:player_conf_id]
|
97
|
+
html.should have_tag("script",
|
98
|
+
%r{/ui_conf_id/#{KalturaFu.config[:player_conf_id]}})
|
99
|
+
else
|
100
|
+
html.should have_tag("script",
|
101
|
+
%r{/ui_conf_id/#{KalturaFu::ViewHelpers::DEFAULT_KPLAYER}})
|
102
|
+
end
|
103
|
+
html.should have_tag("script",%r{"waffles","400","330"})
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should embed a player with a different config id" do
|
107
|
+
html = helper.kaltura_player_embed(12345, :player_conf_id=>"1234")
|
108
|
+
|
109
|
+
#check the outer div
|
110
|
+
html.should have_tag("div#kplayer")
|
111
|
+
|
112
|
+
# check the parameters
|
113
|
+
html.should have_tag("script",%r{allowscriptaccess: "always"})
|
114
|
+
html.should have_tag("script",%r{allownetworking: "all"})
|
115
|
+
html.should have_tag("script",%r{allowfullscreen: "true"})
|
116
|
+
html.should have_tag("script",%r{wmode: "opaque"})
|
117
|
+
|
118
|
+
# check the vars
|
119
|
+
html.should have_tag("script",%r{entryId: "12345"})
|
120
|
+
|
121
|
+
# check the embed
|
122
|
+
html.should have_tag("script",%r{swfobject.embedSWF})
|
123
|
+
html.should have_tag("script",
|
124
|
+
%r{http://www.kaltura.com/kwidget/wid/_#{KalturaFu.config[:partner_id]}})
|
125
|
+
html.should have_tag("script",
|
126
|
+
%r{/ui_conf_id/1234})
|
127
|
+
html.should have_tag("script",%r{"kplayer","400","330"})
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should allow a resize on the player" do
|
131
|
+
html = helper.kaltura_player_embed(12345,:size=>[200,170])
|
132
|
+
|
133
|
+
#check the outer div
|
134
|
+
html.should have_tag("div#kplayer")
|
135
|
+
|
136
|
+
# check the parameters
|
137
|
+
html.should have_tag("script",%r{allowscriptaccess: "always"})
|
138
|
+
html.should have_tag("script",%r{allownetworking: "all"})
|
139
|
+
html.should have_tag("script",%r{allowfullscreen: "true"})
|
140
|
+
html.should have_tag("script",%r{wmode: "opaque"})
|
141
|
+
|
142
|
+
# check the vars
|
143
|
+
html.should have_tag("script",%r{entryId: "12345"})
|
144
|
+
|
145
|
+
# check the embed
|
146
|
+
html.should have_tag("script",%r{swfobject.embedSWF})
|
147
|
+
html.should have_tag("script",
|
148
|
+
%r{http://www.kaltura.com/kwidget/wid/_#{KalturaFu.config[:partner_id]}})
|
149
|
+
if KalturaFu.config[:player_conf_id]
|
150
|
+
html.should have_tag("script",
|
151
|
+
%r{/ui_conf_id/#{KalturaFu.config[:player_conf_id]}})
|
152
|
+
else
|
153
|
+
html.should have_tag("script",
|
154
|
+
%r{/ui_conf_id/#{KalturaFu::ViewHelpers::DEFAULT_KPLAYER}})
|
155
|
+
end
|
156
|
+
html.should have_tag("script",%r{"kplayer","200","170"})
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should seek to a time in seconds when asked" do
|
160
|
+
html = helper.kaltura_seek_link("Seek to 5 seconds","5")
|
161
|
+
html.should have_tag("a[href=\"#\"]", "Seek to 5 seconds")
|
162
|
+
html.should have_tag("a[onclick=\"$(kplayer).get(0).sendNotification(\'doSeek\',5);window.scrollTo(0,0);return false;\"]")
|
163
|
+
html.should_not have_tag("a[div_id=\"kplayer\"]")
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
begin
|
2
|
+
require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need to install rspec in your base app"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
plugin_spec_dir = File.dirname(__FILE__)
|
9
|
+
ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
|
10
|
+
|