stupeflix 0.0.1 → 0.0.2
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/README.md +12 -5
- data/examples/example.rb +23 -0
- data/lib/stupeflix/version.rb +2 -5
- data/lib/stupeflix.rb +108 -35
- data/stupeflix.gemspec +2 -1
- metadata +18 -1
data/README.md
CHANGED
@@ -20,17 +20,24 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
Retrieve your API keys from http://developer.stupeflix.com/keychain/ and then replace the placeholder variables below.
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
```ruby
|
24
|
+
# Set a unique identifier e.g. 'user/resource_id'
|
25
|
+
id = "user/resource_id#{Time.now.to_i}"
|
26
|
+
|
27
|
+
# Configure credentials
|
28
|
+
s = Stupeflix::Video.new id, YOUR_ACCESS_KEY, YOUR_SECRET_KEY
|
25
29
|
|
26
30
|
# To PUT a video definition
|
27
|
-
s.
|
31
|
+
s.definition = definition_xml
|
28
32
|
|
29
33
|
# POST profiles to request videos be generated accordingly
|
30
|
-
s.
|
34
|
+
s.profiles = profiles_xml
|
31
35
|
|
32
36
|
# GET status of requested videos
|
33
|
-
s.status
|
37
|
+
s.status
|
38
|
+
```
|
39
|
+
|
40
|
+
See the [examples directory](http://github.com/pgeraghty/stupeflix-api/tree/master/examples) for guidance.
|
34
41
|
|
35
42
|
Follow [this link](http://stupeflix-api.readthedocs.org/en/latest/resources/04_video_description_langage.html) for more
|
36
43
|
information about how to produce a definition. I recommend Nokogiri's XML builder.
|
data/examples/example.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Set a unique identifier e.g. 'user/resource_id'
|
2
|
+
id = "user/resource_id#{Time.now.to_i}"
|
3
|
+
|
4
|
+
# Configure credentials
|
5
|
+
s = Stupeflix::Video.new id, YOUR_ACCESS_KEY, YOUR_SECRET_KEY
|
6
|
+
|
7
|
+
# To PUT a video definition
|
8
|
+
s.definition = Stupeflix::Definition.new do |xml|
|
9
|
+
images = %w(qiwD B0-X hXBA rEpt 9w95 ILMo mO6A oUay st5s wExP 01Wb IouW zlCm).map { |i| 'http://gdurl.com/' + i }.shuffle[0...8]
|
10
|
+
xml.stack(duration: 4) {
|
11
|
+
xml.add_image images.pop
|
12
|
+
xml.add_text 'Example', align: 'center,center'
|
13
|
+
}
|
14
|
+
images.each_with_index do |i,x|
|
15
|
+
xml.add_slide i, "Slide #{x}", duration: 4
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# POST profiles to request videos be generated accordingly
|
20
|
+
s.profiles = '<profiles><profile name="720p"><stupeflixStore></stupeflixStore></profile></profiles>'
|
21
|
+
|
22
|
+
# GET status of requested videos
|
23
|
+
s.status
|
data/lib/stupeflix/version.rb
CHANGED
data/lib/stupeflix.rb
CHANGED
@@ -1,50 +1,123 @@
|
|
1
1
|
require 'stupeflix/version'
|
2
2
|
require 'httparty'
|
3
|
+
require 'nokogiri'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
module Stupeflix
|
6
|
+
class Video
|
7
|
+
include HTTParty
|
8
|
+
base_uri 'services.stupeflix.com'
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def initialize id, key, secret
|
11
|
+
@id, @key, @secret = id, key, secret
|
12
|
+
self.class.default_params AccessKey: key
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def req method, body, mime, t, url
|
16
|
+
md5hex, md5base64 = md5(body) rescue [nil, nil] # md5hex can be compared to etag in response for verification
|
17
|
+
[{ Date: t, Signature: sign([method, md5base64, mime, t, url, nil]*"\n") },
|
18
|
+
body ? { 'Content-MD5' => md5base64.to_s, 'Content-Length' => body.length.to_s, 'Content-Type' => mime } : nil]
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def definition= d
|
22
|
+
params, headers = req('PUT', d, 'text/xml', Time.now.to_i, url = "#{self.url}/definition/")
|
23
|
+
self.class.put url, query: params, headers: headers, body: d
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
# TODO make this an array or..?
|
27
|
+
def profiles= profiles_xml
|
28
|
+
params, headers = req('POST', body = "ProfilesXML=#{CGI::escape profiles_xml}",
|
29
|
+
'application/x-www-form-urlencoded', Time.now.to_i, url = "#{self.url}/")
|
30
|
+
self.class.post url, query: params, headers: headers, body: body
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def status
|
34
|
+
params, headers = req('GET', nil, nil, Time.now.to_i, url = "#{self.url}/status/")
|
35
|
+
r = self.class.get url, query: params #, format: :json
|
36
|
+
r.parsed_response rescue r
|
37
|
+
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
def url
|
40
|
+
"/stupeflix-1.0/#{@id}" # user/resource
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
39
44
|
|
40
|
-
|
45
|
+
def sign str
|
46
|
+
OpenSSL::HMAC.hexdigest OpenSSL::Digest::Digest.new('sha1'), @secret, str
|
47
|
+
end
|
41
48
|
|
42
|
-
|
43
|
-
|
49
|
+
def md5 body
|
50
|
+
md5 = Digest::MD5.new().update body
|
51
|
+
[md5.hexdigest, Base64.encode64(md5.digest).strip]
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
|
-
|
47
|
-
|
48
|
-
|
55
|
+
class Definition < Nokogiri::XML::Builder
|
56
|
+
EFFECTS = %w(kenburns flower rectangles none) # http://wiki.stupeflix.com/doku.php?id=effects
|
57
|
+
FONTS = %w(arial arialbold arialroundedmtbold comicsansms couriernew landspeedrecord saddlebag timesnewroman verdana)
|
58
|
+
DIRECTIONS = %w(left right up down)
|
59
|
+
TRANSITIONS = %w(circle crossfade cube move over radial scan scans spiral strip swirl under waterdrop)
|
60
|
+
TRANSITIONS_WITH_DIR = %w(cube move over scan spiral under)
|
61
|
+
|
62
|
+
def initialize &block
|
63
|
+
super({}, Nokogiri::XML::Document.new) do |x|
|
64
|
+
x.movie(service: 'craftsman-1.0') {
|
65
|
+
x.body {
|
66
|
+
yield x if block_given?
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end.root
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_slide url, caption, options={}
|
73
|
+
options = { duration: 1 }.merge options
|
74
|
+
add_transition
|
75
|
+
stack(duration: options[:duration]) {
|
76
|
+
add_image url
|
77
|
+
add_text_overlay caption unless caption.length > 0 rescue nil
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_map map
|
82
|
+
overlay(right: '0.0', bottom: '0.0', width:'0.25') {
|
83
|
+
image filename: map
|
84
|
+
animator type: 'slide-in', direction: 'up', duration:'1.0'
|
85
|
+
animator type: 'slide-out', direction: 'down', 'margin-start' => '6.0'
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_image url, options={}
|
90
|
+
effect({ type: EFFECTS.sample }.merge options) {
|
91
|
+
image filename: url
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_text caption, options={}
|
96
|
+
return unless caption.length > 0 rescue nil
|
97
|
+
defaults = { type: 'zone', vector: 'true', align: 'left,bottom' }
|
98
|
+
long_caption = caption.length > 30
|
99
|
+
#defaults[:align] = 'center,top'
|
100
|
+
defaults[:fontsize] = 30 unless long_caption # prevent auto-scale from filling screen with huge text
|
101
|
+
text_(defaults.merge options) {
|
102
|
+
text caption
|
103
|
+
filter(type: 'distancemap', distanceWidth: 40.0)
|
104
|
+
filter type: 'distancecolor', distanceWidth: 40.0, color: '#de7316',
|
105
|
+
strokeColor: '#000000', strokeOpacity: 1.0, strokeWidth: 0.02,
|
106
|
+
dropShadowColor: '#00000044', dropShadowOpacity: 1.0, dropShadowBlurWidth: '0.9',
|
107
|
+
dropShadowPosition: '0.01,-0.01', outerGlowColor: '#ffffff44', outerGlowOpacity: 1.0, outerGlowBlurWidth: 0.7
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_text_overlay caption, options={}
|
112
|
+
overlay {
|
113
|
+
add_text caption, options
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_transition options={}
|
118
|
+
defaults = { type: TRANSITIONS.sample }
|
119
|
+
defaults[:direction] = DIRECTIONS.sample if TRANSITIONS_WITH_DIR.include? defaults[:type]
|
120
|
+
transition defaults.merge(options)
|
121
|
+
end
|
49
122
|
end
|
50
123
|
end
|
data/stupeflix.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'stupeflix/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = 'stupeflix'
|
8
|
-
gem.version = Stupeflix
|
8
|
+
gem.version = Stupeflix::VERSION
|
9
9
|
gem.platform = Gem::Platform::RUBY
|
10
10
|
gem.authors = ['Paul Geraghty']
|
11
11
|
gem.email = ['muse@appsthatcould.be']
|
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ['lib']
|
20
20
|
|
21
21
|
gem.add_dependency 'httparty', '>= 0'
|
22
|
+
gem.add_dependency 'nokogiri', '>= 0'
|
22
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stupeflix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Stupeflix API wrapper using HTTParty
|
31
47
|
email:
|
32
48
|
- muse@appsthatcould.be
|
@@ -39,6 +55,7 @@ files:
|
|
39
55
|
- LICENSE.txt
|
40
56
|
- README.md
|
41
57
|
- Rakefile
|
58
|
+
- examples/example.rb
|
42
59
|
- lib/stupeflix.rb
|
43
60
|
- lib/stupeflix/version.rb
|
44
61
|
- stupeflix.gemspec
|