heywatch 0.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/heywatch +135 -0
- data/lib/heywatch.rb +133 -81
- metadata +83 -68
- data/Manifest.txt +0 -18
- data/README.txt +0 -163
- data/Rakefile +0 -74
- data/lib/heywatch/account.rb +0 -32
- data/lib/heywatch/auth.rb +0 -83
- data/lib/heywatch/base.rb +0 -269
- data/lib/heywatch/browser.rb +0 -98
- data/lib/heywatch/discover.rb +0 -39
- data/lib/heywatch/download.rb +0 -30
- data/lib/heywatch/encoded_video.rb +0 -49
- data/lib/heywatch/ext.rb +0 -118
- data/lib/heywatch/job.rb +0 -32
- data/lib/heywatch/version.rb +0 -9
- data/lib/heywatch/video.rb +0 -25
- data/setup.rb +0 -1585
- data/test/test_helper.rb +0 -8
- data/test/test_heywatch.rb +0 -149
data/bin/heywatch
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
4
|
+
require "rubygems"
|
5
|
+
require "heywatch"
|
6
|
+
|
7
|
+
RestClient.log = "stderr" if ENV["DEBUG"]
|
8
|
+
config_file = "#{ENV["HOME"]}/.heywatch"
|
9
|
+
|
10
|
+
if File.exists?(config_file)
|
11
|
+
user, passwd = File.read(config_file).split("\n")
|
12
|
+
else
|
13
|
+
puts "HeyWatch username:"
|
14
|
+
user = $stdin.gets.chomp
|
15
|
+
puts "HeyWatch password:"
|
16
|
+
system "stty -echo"
|
17
|
+
passwd = $stdin.gets.chomp
|
18
|
+
system "stty echo"
|
19
|
+
|
20
|
+
# testing credentials
|
21
|
+
begin
|
22
|
+
HeyWatch.new(user, passwd)
|
23
|
+
File.open(config_file, "w") {|f| f.write("#{user}\n#{passwd}") }
|
24
|
+
File.chmod(0600, config_file)
|
25
|
+
puts "Your credentials have been saved in this file #{config_file} (0600)"
|
26
|
+
exit
|
27
|
+
rescue => e
|
28
|
+
puts "Wrong login or password."
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
hw = HeyWatch.new(user, passwd)
|
34
|
+
|
35
|
+
begin
|
36
|
+
if ARGV.empty?
|
37
|
+
puts %(Usage: heywatch RESOURCE:METHOD [ID] [parameter1=value1 parameter2=value2 ...]
|
38
|
+
|
39
|
+
Resources:
|
40
|
+
|
41
|
+
account # account information
|
42
|
+
video # manage video | all, info, delete, count, bin
|
43
|
+
encoded_video # manage encoded video | all, info, delete, count, bin, jpg
|
44
|
+
download # manage download | all, info, delete, count, create
|
45
|
+
job # manage job | all, info, delete, count, create
|
46
|
+
format # manage format | all, info, delete, count, create, update
|
47
|
+
|
48
|
+
Usage:
|
49
|
+
|
50
|
+
heywatch account
|
51
|
+
heywatch video:info 123456
|
52
|
+
heywatch job:all
|
53
|
+
heywatch download:create url=http://site.com/video.mp4 title=mytitle
|
54
|
+
heywatch encoded_video:jpg 9882322 start=4 > thumb.jpg
|
55
|
+
heywatch format:all owner=true video_codec=h264
|
56
|
+
heywatch video:all "[0]"
|
57
|
+
heywatch job:all "[0..10]"
|
58
|
+
heywatch format:count owner=true
|
59
|
+
)
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
|
63
|
+
if ARGV[0] == "account"
|
64
|
+
puts JSON.pretty_generate(hw.account)
|
65
|
+
exit
|
66
|
+
end
|
67
|
+
|
68
|
+
resource, method = ARGV[0].split(":")
|
69
|
+
params = ARGV[1..-1]
|
70
|
+
|
71
|
+
$stderr.puts [resource, method, params].inspect if ENV["DEBUG"]
|
72
|
+
|
73
|
+
if method == "create"
|
74
|
+
params = Hash[*ARGV[1..-1].map{|p| k,v = p.split("=") }.flatten]
|
75
|
+
puts JSON.pretty_generate(hw.send(method, *[resource, params]))
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
if method == "update"
|
80
|
+
params = Hash[*ARGV[2..-1].map{|p| k,v = p.split("=") }.flatten]
|
81
|
+
puts JSON.pretty_generate(hw.send(method, *[resource, ARGV[1], params]))
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
|
85
|
+
if method == "jpg"
|
86
|
+
params = Hash[*ARGV[2..-1].map{|p| k,v = p.split("=") }.flatten]
|
87
|
+
puts hw.send(method, *[ARGV[1], params])
|
88
|
+
exit
|
89
|
+
end
|
90
|
+
|
91
|
+
if method == "bin"
|
92
|
+
puts hw.send(method, *[resource, ARGV[1]])
|
93
|
+
exit
|
94
|
+
end
|
95
|
+
|
96
|
+
if params.empty?
|
97
|
+
res = hw.send(method, resource)
|
98
|
+
if method == "count"
|
99
|
+
puts res
|
100
|
+
exit
|
101
|
+
end
|
102
|
+
|
103
|
+
puts JSON.pretty_generate(res)
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
107
|
+
if params.last =~ /\[([0-9\.-]+)\]/
|
108
|
+
offset = eval($1)
|
109
|
+
params = params[0..-2]
|
110
|
+
end
|
111
|
+
|
112
|
+
res = hw.send(method, *[resource, params])
|
113
|
+
if res == true
|
114
|
+
puts "ok"
|
115
|
+
exit
|
116
|
+
end
|
117
|
+
|
118
|
+
if res.is_a?(Fixnum)
|
119
|
+
puts res
|
120
|
+
exit
|
121
|
+
end
|
122
|
+
|
123
|
+
if res.empty?
|
124
|
+
exit
|
125
|
+
end
|
126
|
+
|
127
|
+
res = res[offset] if offset
|
128
|
+
|
129
|
+
puts JSON.pretty_generate(res)
|
130
|
+
exit
|
131
|
+
|
132
|
+
rescue => e
|
133
|
+
puts e
|
134
|
+
puts e.backtrace.join("\n") if ENV["DEBUG"]
|
135
|
+
end
|
data/lib/heywatch.rb
CHANGED
@@ -1,88 +1,140 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
#++
|
1
|
+
require "rest-client"
|
2
|
+
require "json"
|
23
3
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# These are error codes you receive if you use ping options
|
34
|
-
ErrorCode = {
|
35
|
-
100 => "Unknown error",
|
36
|
-
101 => "Unsupported audio codec",
|
37
|
-
102 => "Unsupported video codec",
|
38
|
-
103 => "This video cannot be encoded in this format",
|
39
|
-
104 => "Wrong settings for audio",
|
40
|
-
105 => "Wrong settings for video",
|
41
|
-
106 => "Cannot retrieve info from this video",
|
42
|
-
107 => "Not a video file",
|
43
|
-
108 => "Video too long",
|
44
|
-
109 => "The container of this video is not supported yet",
|
45
|
-
110 => "The audio can't be resampled",
|
46
|
-
201 => "404 Not Found",
|
47
|
-
202 => "Bad address",
|
48
|
-
300 => "No more credit available"
|
49
|
-
} unless const_defined? :ErrorCode
|
50
|
-
|
51
|
-
class NotAuthorized < RuntimeError; end
|
52
|
-
class RequestError < RuntimeError; end
|
53
|
-
class ResourceNotFound < RuntimeError; end
|
54
|
-
class ServerError < RuntimeError; end
|
55
|
-
class SessionNotFound < RuntimeError; end
|
4
|
+
class HeyWatch
|
5
|
+
class InvalidResource < ArgumentError; end
|
6
|
+
class BadRequest < RuntimeError; end
|
7
|
+
|
8
|
+
URL = "https://heywatch.com"
|
9
|
+
VERSION = "1.0.2"
|
10
|
+
|
11
|
+
attr_reader :cli
|
56
12
|
|
57
|
-
#
|
58
|
-
|
59
|
-
|
13
|
+
# Authenticate with your HeyWatch credentials
|
14
|
+
#
|
15
|
+
# hw = HeyWatch.new(user, passwd)
|
16
|
+
def initialize(user, password)
|
17
|
+
@cli = RestClient::Resource.new(URL, {:user => user, :password => password, :headers =>
|
18
|
+
{:user_agent => "HeyWatch Ruby/#{VERSION}", :accept => "application/json"}})
|
19
|
+
|
20
|
+
self
|
60
21
|
end
|
61
22
|
|
62
|
-
#
|
63
|
-
|
64
|
-
|
23
|
+
def inspect # :nodoc:
|
24
|
+
"#<HeyWatch: " + account.inspect + ">"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get account information
|
28
|
+
#
|
29
|
+
# hw.account
|
30
|
+
def account
|
31
|
+
JSON.parse(@cli["/account"].get)
|
65
32
|
end
|
66
|
-
end
|
67
|
-
|
68
|
-
$: << File.dirname(File.expand_path(__FILE__))
|
69
|
-
|
70
|
-
require "heywatch/ext"
|
71
|
-
require "heywatch/version"
|
72
|
-
require "heywatch/browser"
|
73
|
-
require "heywatch/auth"
|
74
|
-
require "heywatch/base"
|
75
|
-
require "heywatch/encoded_video"
|
76
|
-
require "heywatch/video"
|
77
|
-
require "heywatch/account"
|
78
|
-
require "heywatch/download"
|
79
|
-
require "heywatch/discover"
|
80
|
-
require "heywatch/job"
|
81
33
|
|
82
|
-
|
83
|
-
|
84
|
-
|
34
|
+
# Get all from a given resource.
|
35
|
+
# Filters are optional
|
36
|
+
#
|
37
|
+
# hw.all :video
|
38
|
+
# hw.all :format, :owner => true
|
39
|
+
def all(*resource_and_filters)
|
40
|
+
resource, filters = resource_and_filters
|
41
|
+
|
42
|
+
result = JSON.parse(@cli["/#{resource}"].get)
|
43
|
+
return result if filters.nil? or filters.empty?
|
85
44
|
|
86
|
-
|
87
|
-
|
88
|
-
|
45
|
+
return filter_all(result, filters)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get info about a given resource and id
|
49
|
+
#
|
50
|
+
# hw.info :format, 31
|
51
|
+
def info(resource, id)
|
52
|
+
JSON.parse(@cli["/#{resource}/#{id}"].get)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Count objects from a given resources.
|
56
|
+
# Filters are optional
|
57
|
+
#
|
58
|
+
# hw.count :job
|
59
|
+
# hw.count :job, :status => "error"
|
60
|
+
def count(*resource_and_filters)
|
61
|
+
all(*resource_and_filters).size
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get the binary data of a video / encoded_video
|
65
|
+
#
|
66
|
+
# hw.bin :encoded_video, 12345
|
67
|
+
def bin(resource, id, &block)
|
68
|
+
unless [:encoded_video, :video].include?(resource.to_sym)
|
69
|
+
raise InvalidResource, "Can't retrieve '#{resource}'"
|
70
|
+
end
|
71
|
+
|
72
|
+
@cli["/#{resource}/#{id}.bin"].head do |res, req|
|
73
|
+
return RestClient.get(res.headers[:location], :raw_response => true, &block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Generate thumbnails in the foreground or background via :async => true
|
78
|
+
#
|
79
|
+
# hw.jpg 12345, :start => 2
|
80
|
+
# => thumbnail data
|
81
|
+
#
|
82
|
+
# hw.jpg 12345, :async => true, :number => 6, :s3_directive => "s3://accesskey:secretkey@bucket"
|
83
|
+
# => true
|
84
|
+
def jpg(id, params={})
|
85
|
+
if params.delete(:async) or params.delete("async")
|
86
|
+
@cli["/encoded_video/#{id}/thumbnails"].post(params)
|
87
|
+
return true
|
88
|
+
end
|
89
|
+
|
90
|
+
unless params.empty?
|
91
|
+
params = "?" + params.map{|k,v| "#{k}=#{v}"}.join("&")
|
92
|
+
end
|
93
|
+
@cli["/encoded_video/#{id}.jpg#{params}"].get
|
94
|
+
rescue RestClient::BadRequest=> e
|
95
|
+
raise BadRequest, e.http_body
|
96
|
+
end
|
97
|
+
|
98
|
+
# Create a resource with the give data
|
99
|
+
#
|
100
|
+
# hw.create :download, :url => "http://site.com/video.mp4", :title => "testing"
|
101
|
+
def create(resource, data={})
|
102
|
+
JSON.parse(@cli["/#{resource}"].post(data))
|
103
|
+
rescue RestClient::BadRequest=> e
|
104
|
+
raise BadRequest, e.http_body
|
105
|
+
end
|
106
|
+
|
107
|
+
# Update an object by giving its resource and ID
|
108
|
+
#
|
109
|
+
# hw.update :format, 9877, :video_bitrate => 890
|
110
|
+
def update(resource, id, data={})
|
111
|
+
@cli["/#{resource}/#{id}"].put(data)
|
112
|
+
info(resource, id)
|
113
|
+
rescue RestClient::BadRequest=> e
|
114
|
+
raise BadRequest, e.http_body
|
115
|
+
end
|
116
|
+
|
117
|
+
# Delete a resource
|
118
|
+
#
|
119
|
+
# hw.delete :format, 9807
|
120
|
+
def delete(resource, id)
|
121
|
+
@cli["/#{resource}/#{id}"].delete
|
122
|
+
true
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def filter_all(result, filters) # :nodoc:
|
128
|
+
if filters.is_a?(Array)
|
129
|
+
filters = Hash[*filters.map{|f| f.split("=") }.flatten]
|
130
|
+
end
|
131
|
+
|
132
|
+
filtered = []
|
133
|
+
result.each do |r|
|
134
|
+
if eval("true if " + filters.map{|k,v| "'#{r[k.to_s]}' =~ /#{v}/"}.join(" and "))
|
135
|
+
filtered << r
|
136
|
+
end
|
137
|
+
end
|
138
|
+
filtered
|
139
|
+
end
|
140
|
+
end
|
metadata
CHANGED
@@ -1,80 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: heywatch
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
rubyforge_project: heywatch
|
14
|
-
description: Ruby Library for HeyWatch service (http://heywatch.com).
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
25
11
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
12
|
authors:
|
30
13
|
- Bruno Celeste
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
- Rakefile
|
35
|
-
- lib/heywatch.rb
|
36
|
-
- lib/heywatch/video.rb
|
37
|
-
- lib/heywatch/version.rb
|
38
|
-
- lib/heywatch/job.rb
|
39
|
-
- lib/heywatch/ext.rb
|
40
|
-
- lib/heywatch/encoded_video.rb
|
41
|
-
- lib/heywatch/download.rb
|
42
|
-
- lib/heywatch/discover.rb
|
43
|
-
- lib/heywatch/browser.rb
|
44
|
-
- lib/heywatch/base.rb
|
45
|
-
- lib/heywatch/auth.rb
|
46
|
-
- lib/heywatch/account.rb
|
47
|
-
- setup.rb
|
48
|
-
- test/test_helper.rb
|
49
|
-
- test/test_heywatch.rb
|
50
|
-
test_files:
|
51
|
-
- test/test_helper.rb
|
52
|
-
- test/test_heywatch.rb
|
53
|
-
rdoc_options:
|
54
|
-
- --quiet
|
55
|
-
- --title
|
56
|
-
- heywatch documentation
|
57
|
-
- --opname
|
58
|
-
- index.html
|
59
|
-
- --line-numbers
|
60
|
-
- --main
|
61
|
-
- README.txt
|
62
|
-
- --inline-source
|
63
|
-
extra_rdoc_files:
|
64
|
-
- README.txt
|
65
|
-
executables: []
|
66
|
-
|
67
|
-
extensions: []
|
68
|
-
|
69
|
-
requirements: []
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
70
17
|
|
18
|
+
date: 2011-06-18 00:00:00 +02:00
|
19
|
+
default_executable:
|
71
20
|
dependencies:
|
72
21
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
74
|
-
|
75
|
-
|
22
|
+
name: rest-client
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
76
40
|
requirements:
|
77
41
|
- - ">="
|
78
42
|
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Client Library for encoding Videos with HeyWatch, a Video Encoding Web Service.
|
50
|
+
email: bruno@particle-s.com
|
51
|
+
executables:
|
52
|
+
- heywatch
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- lib/heywatch.rb
|
59
|
+
- bin/heywatch
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://heywatch.com
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.5.0
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Client library and CLI to encode videos with HeyWatch
|
94
|
+
test_files: []
|
95
|
+
|