Module: MotionVj
- Defined in:
- lib/motion_vj.rb,
lib/motion_vj/client.rb,
lib/motion_vj/logger.rb,
lib/motion_vj/helpers.rb,
lib/motion_vj/version.rb,
lib/motion_vj/helpers/input.rb
Defined Under Namespace
Modules: Helpers, Logger
Classes: Client
Constant Summary
collapse
- VERSION =
'0.2.0'
Class Method Summary
collapse
Class Method Details
.get_dropbox_token(app_key, app_secret) ⇒ Object
10
11
12
13
|
# File 'lib/motion_vj.rb', line 10
def self.get_dropbox_token(app_key, app_secret)
token = MotionVj::Client.get_token(app_key, app_secret)
puts "Your Dropbox access token for this app is: #{ token }"
end
|
.start(options) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/motion_vj.rb', line 15
def self.start(options)
listener = Listen.to(options[:videos_dir], only: /\.#{ Regexp.escape options[:videos_extension] }$/) do |modified_filepaths, _, removed_filepaths|
unless modified_filepaths.empty?
client = MotionVj::Client.new(options[:db_app_token], options[:db_videos_dir])
motion_lsof = `lsof -c #{ options[:motion_cmd] }`
modified_filepaths.each do |filepath|
file_basename = File.basename filepath
if motion_lsof =~ /#{ Regexp.escape(file_basename) }/
Logger.error "Added file still in use."
next
end
if !client.file_exist?(file_basename)
begin
if client.upload(filepath)
FileUtils.rm_f(filepath)
Logger.info "'#{ file_basename }' was uploaded."
else
Logger.error "Could not upload '#{ file_basename }'."
end
rescue => e
Logger.error "Could not upload '#{ file_basename }'."
end
end
end
end
removed_filepaths.each do |filepath|
Logger.info "'#{ File.basename(filepath) }' deleted."
end
end
listener.start
end
|