chocolate_rain 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chocolate_rain/ftp.rb +17 -0
- data/lib/chocolate_rain/ftp_worker.rb +51 -0
- data/lib/chocolate_rain/inbox.rb +26 -0
- data/lib/chocolate_rain/mail_handler.rb +44 -0
- data/lib/chocolate_rain/version.rb +1 -1
- data/lib/chocolate_rain/y_video.rb +61 -39
- data/lib/chocolate_rain.rb +10 -38
- metadata +7 -6
- data/lib/chocolate_rain/ftp_files_and_upload.rb +0 -54
- data/lib/chocolate_rain/mail_rain/inbox.rb +0 -39
- data/lib/chocolate_rain/mail_rain/mail_handler.rb +0 -53
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
require 'fileutils'
|
3
|
+
include Daemon
|
4
|
+
include ChocolateRain
|
5
|
+
|
6
|
+
class FtpMachine < Daemon::Base
|
7
|
+
def self.start
|
8
|
+
loop do
|
9
|
+
ChocolateRain::FtpWorker.do_work
|
10
|
+
sleep(30)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.stop
|
15
|
+
put "Stopping FtpMachine"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module ChocolateRain
|
5
|
+
class FtpWorker < ActionMailer::Base
|
6
|
+
def do_work
|
7
|
+
@@ftp_creds = YAML.load(File.open("config/fms_config.yml"))["#{Rails.env}"]
|
8
|
+
|
9
|
+
@local_files = []
|
10
|
+
|
11
|
+
ftp = Net::FTP.new
|
12
|
+
ftp.passive = true
|
13
|
+
|
14
|
+
puts "Connection"
|
15
|
+
ftp.connect(@@ftp_creds["url"], 21)
|
16
|
+
ftp.login(@@ftp_creds["username"], @@ftp_creds["password"])
|
17
|
+
puts "logged in"
|
18
|
+
|
19
|
+
ftp.chdir(@@ftp_creds["directory"])
|
20
|
+
puts "chdir"
|
21
|
+
filenames = ftp.nlst("*.#{@@ftp_creds["format"]}")
|
22
|
+
puts "got files"
|
23
|
+
# loop by index
|
24
|
+
filenames.each_index do |i|
|
25
|
+
begin
|
26
|
+
f = File.open("#{Rails.root}/tmp/#{i}.#{@@ftp_creds["format"]}")
|
27
|
+
ftp.getbinaryfile(filenames[i], f)
|
28
|
+
v = ChocolateRain::YVideo.new()
|
29
|
+
v.filename = i
|
30
|
+
v.file_object = f
|
31
|
+
v.title = i
|
32
|
+
@local_files << "#{i}.#{@@ftp_creds["format"]}"
|
33
|
+
rescue Exception => e
|
34
|
+
puts "Error in FTP: #{e.message}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
filenames.each do |filename|
|
39
|
+
# ftp.delete("#{filename}")
|
40
|
+
end
|
41
|
+
|
42
|
+
@local_files.each do |f|
|
43
|
+
begin
|
44
|
+
v.save
|
45
|
+
rescue Exception => e
|
46
|
+
puts "Exception: #{e.message}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/pop'
|
2
|
+
require 'mail'
|
3
|
+
include Daemon
|
4
|
+
include ChocolateRain
|
5
|
+
|
6
|
+
class MailFetcher < Daemon::Base
|
7
|
+
def self.start
|
8
|
+
loop do
|
9
|
+
pop = Net::POP3.new('mail.hasflavor.com')
|
10
|
+
pop.start("app@hasflavor.com", "oi890po")
|
11
|
+
|
12
|
+
if !pop.mails.empty?
|
13
|
+
pop.each_mail do |m|
|
14
|
+
ChocolateRain::MailHandler.receive(m.pop)
|
15
|
+
# m.delete
|
16
|
+
end
|
17
|
+
end
|
18
|
+
pop.finish
|
19
|
+
sleep(30)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.stop
|
24
|
+
puts "Stopping Mail Fetcher Daemon"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module ChocolateRain
|
5
|
+
class MailHandler < ActionMailer::Base
|
6
|
+
def resend(sender, recipient, subject, body)
|
7
|
+
mail(:from => sender,
|
8
|
+
:to => recipient,
|
9
|
+
:subject => subject,
|
10
|
+
:body => body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def receive(email)
|
14
|
+
resend_multipart(email)
|
15
|
+
end
|
16
|
+
|
17
|
+
def resend_multipart(email)
|
18
|
+
email.attachments.each do |att|
|
19
|
+
fn = att.filename
|
20
|
+
v = ChocolateRain::YVideo.new()
|
21
|
+
begin
|
22
|
+
f = StringIO.new(att.body.decoded)
|
23
|
+
v.filename = fn
|
24
|
+
v.file_object = f
|
25
|
+
v.title = fn
|
26
|
+
begin
|
27
|
+
v.save
|
28
|
+
rescue Exception => e
|
29
|
+
puts "Exception: #{e.message}"
|
30
|
+
end
|
31
|
+
rescue Exception => e
|
32
|
+
puts "Exception: #{e.message}"
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
resent = resend("whyhermancain@gmail.com", "support@wearefound.com", "[CAIN] Successful Upload", "A new testimonial video has been uploaded via email to s3. Its url is http://s3.amazonaws.com/whyHermanCain/#{v.filename}")
|
37
|
+
resent.deliver
|
38
|
+
rescue
|
39
|
+
return
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,49 +1,71 @@
|
|
1
1
|
require 'youtube_it'
|
2
2
|
require 'aws/s3'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@category = nil
|
18
|
-
@keywords = []
|
19
|
-
@list = "denied"
|
20
|
-
@comments = "denied"
|
21
|
-
@rate = "denied"
|
22
|
-
@commentVote = "denied"
|
23
|
-
@videoRespond = "denied"
|
24
|
-
@embed = "denied"
|
25
|
-
@syndicate = "denied"
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_hash
|
29
|
-
self.instance_variables.inject({}) { |hash,var| hash[var.to_s.delete("@")] = self.instance_variable_get(var); hash }
|
30
|
-
end
|
31
|
-
|
32
|
-
def upload
|
33
|
-
@@YCONN.video_upload(File.open("#{Rails.root.to_s}/public/videos/#{f}"), :title => "#{f}", :description => "Testimonial Video", :category => "Entertainment", :keywords => %w[herman cain whyhermancain republican politics testimonal donate donation], :list => "denied", :comments => "denied", :rate => "denied", :commentVote => "denied", :videoRespond => "denied", :embed => "denied", :syndicate => "denied")
|
34
|
-
end
|
35
|
-
|
36
|
-
def save
|
37
|
-
puts "in save"
|
4
|
+
module ChocolateRain
|
5
|
+
class YVideo
|
6
|
+
attr_accessor :filename, :file_object, :title, :description, :category, :keywords, :list, :comments, :rate, :commentVote, :videoRespond, :embed, :syndicate
|
7
|
+
|
8
|
+
@@y_creds = {}
|
9
|
+
YAML.load(File.open("config/youtube_config.yml"))[(Rails.env)].each{|key, val| @@y_creds[key.to_sym] = val}
|
10
|
+
@@y_conn = YouTubeIt::Client.new(:username => @@y_creds[:username] , :password => @@y_creds[:password] , :dev_key => @@y_creds[:dev_key])
|
11
|
+
@@s3_creds = YAML.load(File.open("config/s3.yml"))
|
12
|
+
AWS::S3::Base.establish_connection!(
|
13
|
+
:access_key_id => @@s3_creds[(Rails.env)]["access_key_id"],
|
14
|
+
:secret_access_key => @@s3_creds[(Rails.env)]["secret_access_key"]
|
15
|
+
)
|
16
|
+
|
38
17
|
begin
|
39
|
-
bucket = AWS::S3::Bucket.find(@@
|
18
|
+
@@bucket = AWS::S3::Bucket.find(@@s3_creds[(Rails.env)]["bucket"])
|
40
19
|
rescue
|
41
|
-
bucket = AWS::S3::Bucket.create(@@
|
20
|
+
@@bucket = AWS::S3::Bucket.create(@@s3_creds[(Rails.env)]["bucket"])
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@filename = nil
|
25
|
+
@title = ""
|
26
|
+
@description = "Testimonial Video"
|
27
|
+
@category = "Entertainment"
|
28
|
+
@keywords = %w[herman cain whyhermancain republican politics testimonal donate donation]
|
29
|
+
@list = "denied"
|
30
|
+
@comments = "denied"
|
31
|
+
@rate = "denied"
|
32
|
+
@commentVote = "denied"
|
33
|
+
@videoRespond = "denied"
|
34
|
+
@embed = "denied"
|
35
|
+
@syndicate = "denied"
|
36
|
+
@private = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_hash
|
40
|
+
self.instance_variables.inject({}) { |hash,var| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var); hash }
|
42
41
|
end
|
43
|
-
|
42
|
+
|
43
|
+
def to_upload_options_hash
|
44
|
+
self.instance_variables.inject({}) { |hash,var| (hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var) unless (["filename", "file_object"].include?(var.to_s.delete("@")))); hash }
|
45
|
+
end
|
46
|
+
|
47
|
+
def upload
|
48
|
+
resp = @@y_conn.video_upload(self.file_object, self.to_upload_options_hash
|
49
|
+
)
|
50
|
+
puts "Response: #{resp.inspect}"
|
51
|
+
puts "***"
|
52
|
+
puts "ID: #{resp.video_id.split(":").last}"
|
44
53
|
return true
|
45
|
-
|
46
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
def save
|
57
|
+
begin
|
58
|
+
AWS::S3::S3Object.store(self.filename, self.file_object, @@s3_creds[(Rails.env)]["bucket"], :access => :public_read)
|
59
|
+
begin
|
60
|
+
self.upload
|
61
|
+
return true
|
62
|
+
rescue Exception => e
|
63
|
+
puts "Upload Failed. #{e.message}"
|
64
|
+
end
|
65
|
+
rescue Exception => e
|
66
|
+
puts "Could not complete save. #{e.message}"
|
67
|
+
return false
|
68
|
+
end
|
47
69
|
end
|
48
70
|
end
|
49
71
|
end
|
data/lib/chocolate_rain.rb
CHANGED
@@ -3,44 +3,16 @@ require 'logger'
|
|
3
3
|
version
|
4
4
|
daemon
|
5
5
|
y_video
|
6
|
-
|
7
|
-
|
6
|
+
mail_handler
|
7
|
+
inbox
|
8
|
+
ftp
|
9
|
+
ftp_worker
|
8
10
|
).each{|m| require File.dirname(__FILE__) + '/chocolate_rain/' + m }
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# URL-escape a string. Stolen from Camping (wonder how many Ruby libs in the wild can say the same)
|
17
|
-
def self.esc(s) #:nodoc:
|
18
|
-
s.to_s.gsub(/[^ \w.-]+/n){'%'+($&.unpack('H2'*$&.size)*'%').upcase}.tr(' ', '+')
|
19
|
-
end
|
20
|
-
|
21
|
-
# Set the logger for the library
|
22
|
-
def self.logger=(any_logger)
|
23
|
-
@logger = any_logger
|
24
|
-
end
|
25
|
-
|
26
|
-
# Get the logger for the library (by default will log to STDOUT). TODO: this is where we grab the Rails logger too
|
27
|
-
def self.logger
|
28
|
-
@logger ||= create_default_logger
|
29
|
-
end
|
30
|
-
|
31
|
-
# Gets mixed into the classes to provide the logger method
|
32
|
-
module Logging #:nodoc:
|
33
|
-
|
34
|
-
# Return the base logger set for the library
|
35
|
-
def logger
|
36
|
-
YouTubeIt.logger
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def self.create_default_logger
|
42
|
-
logger = Logger.new(STDOUT)
|
43
|
-
logger.level = Logger::DEBUG
|
44
|
-
logger
|
45
|
-
end
|
12
|
+
module ChocolateRain
|
13
|
+
puts "Starting MailFetcher"
|
14
|
+
MailFetcher.start
|
15
|
+
puts "Starting FtpMachine"
|
16
|
+
FtpMachine.start
|
17
|
+
puts "All started"
|
46
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chocolate_rain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-23 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: youtube_it
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156678920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156678920
|
25
25
|
description: Monitor E-Mail and FTP for videos to upload to YouTube
|
26
26
|
email:
|
27
27
|
- kevin@wearefound.com
|
@@ -35,9 +35,10 @@ files:
|
|
35
35
|
- chocolate_rain.gemspec
|
36
36
|
- lib/chocolate_rain.rb
|
37
37
|
- lib/chocolate_rain/daemon.rb
|
38
|
-
- lib/chocolate_rain/
|
39
|
-
- lib/chocolate_rain/
|
40
|
-
- lib/chocolate_rain/
|
38
|
+
- lib/chocolate_rain/ftp.rb
|
39
|
+
- lib/chocolate_rain/ftp_worker.rb
|
40
|
+
- lib/chocolate_rain/inbox.rb
|
41
|
+
- lib/chocolate_rain/mail_handler.rb
|
41
42
|
- lib/chocolate_rain/version.rb
|
42
43
|
- lib/chocolate_rain/y_video.rb
|
43
44
|
homepage: ''
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'net/ftp'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'youtube_it'
|
4
|
-
|
5
|
-
module YouTuber
|
6
|
-
# Youtube Creds
|
7
|
-
def upload(f)
|
8
|
-
YT_CLIENT ||= YouTubeIt::Client.new(:username => "whyhermancain" , :password => "999m3@nsj0bs" , :dev_key => "AI39si79BSRx1X9AtG5zNxo-wk5YGiIHa-FAt5BNvb2poO7AVdNJEYoCgxg-JilsgHbNr0IUFk8j490v_LOZ8iPKueOUea6DdQ")
|
9
|
-
|
10
|
-
YT_CLIENT.video_upload(File.open("#{Rails.root.to_s}/public/videos/#{f}"), :title => "#{f}", :description => "Testimonial Video", :category => "Entertainment", :keywords => %w[herman cain whyhermancain republican politics testimonal donate donation], :list => "denied", :comments => "denied", :rate => "denied", :commentVote => "denied", :videoRespond => "denied", :embed => "denied", :syndicate => "denied")
|
11
|
-
puts "completed #{f}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# FTP creds
|
16
|
-
URL = "fx0j7sls.rtmphost.com"
|
17
|
-
USERNAME = "fx0j7sls"
|
18
|
-
PASSWORD = "oi890_{PO"
|
19
|
-
DIRECTORY = "/fx0j7sls_apps/VideoGallery/streams/_definst_"
|
20
|
-
FORMAT = "flv"
|
21
|
-
|
22
|
-
@local_files = []
|
23
|
-
|
24
|
-
ftp = Net::FTP.new
|
25
|
-
ftp.connect(URL, 21)
|
26
|
-
ftp.login(USERNAME, PASSWORD)
|
27
|
-
|
28
|
-
|
29
|
-
ftp.chdir(DIRECTORY)
|
30
|
-
filenames = ftp.nlst("*.#{FORMAT}") # comes back as array
|
31
|
-
|
32
|
-
# loop by index
|
33
|
-
filenames.each_index do |i|
|
34
|
-
puts "working with index: #{i}"
|
35
|
-
localfile = "#{Rails.root.to_s}/public/videos/#{i}.#{FORMAT}"
|
36
|
-
ftp.getbinaryfile(filenames[i], localfile)
|
37
|
-
puts "got #{i}.#{FORMAT}"
|
38
|
-
@local_files << "#{i}.#{FORMAT}"
|
39
|
-
puts "*** \n"
|
40
|
-
end
|
41
|
-
|
42
|
-
filenames.each do |filename|
|
43
|
-
puts "Deleting #{filename}"
|
44
|
-
ftp.delete("#{filename}") # deleting from server so we don't re-download
|
45
|
-
puts "complete.\n***\n"
|
46
|
-
end
|
47
|
-
|
48
|
-
puts "Starting upload stack\n...\n......"
|
49
|
-
@local_files.each do |f|
|
50
|
-
YT_CLIENT.video_upload(File.open("#{Rails.root.to_s}/public/videos/#{f}"), :title => "#{f}", :description => "Testimonial Video", :category => "Entertainment", :keywords => %w[herman cain whyhermancain republican politics testimonal donate donation], :list => "denied", :comments => "denied", :rate => "denied", :commentVote => "denied", :videoRespond => "denied", :embed => "denied", :syndicate => "denied")
|
51
|
-
puts "completed #{f}"
|
52
|
-
end
|
53
|
-
|
54
|
-
puts "...el fine..."
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'net/pop'
|
2
|
-
require 'mail'
|
3
|
-
require 'daemon'
|
4
|
-
require 'y_video'
|
5
|
-
require 'mail_handler'
|
6
|
-
|
7
|
-
class MailFetcher < Daemon::Base
|
8
|
-
def self.start
|
9
|
-
loop do
|
10
|
-
puts "Running Mail Importer..."
|
11
|
-
pop = Net::POP3.new('mail.hasflavor.com')
|
12
|
-
|
13
|
-
pop.start("app@hasflavor.com", "oi890po")
|
14
|
-
|
15
|
-
if pop.mails.empty?
|
16
|
-
puts "NO MAIL"
|
17
|
-
else
|
18
|
-
i = 0
|
19
|
-
puts "receiving mail..."
|
20
|
-
pop.each_mail do |m|
|
21
|
-
MailHandler.receive(m.pop)
|
22
|
-
m.delete
|
23
|
-
i += 1
|
24
|
-
end
|
25
|
-
puts "#{pop.mails.size} mails popped"
|
26
|
-
end
|
27
|
-
pop.finish
|
28
|
-
puts "Finished Mail Importer."
|
29
|
-
|
30
|
-
sleep(10)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.stop
|
35
|
-
puts "Stopping Mail Fetcher Daemon"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
MailFetcher.start
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'mail'
|
2
|
-
require 'stringio'
|
3
|
-
require 'y_video'
|
4
|
-
|
5
|
-
class MailHandler < ActionMailer::Base
|
6
|
-
def resend(sender, recipient, subject, body)
|
7
|
-
mail(:from => sender,
|
8
|
-
:to => recipient,
|
9
|
-
:subject => subject,
|
10
|
-
:body => body)
|
11
|
-
puts "Mail sent to #{recipient}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def receive(email)
|
15
|
-
to_email = "apx05eq15zgx@m.youtube.com"
|
16
|
-
resend_multipart(email)
|
17
|
-
end
|
18
|
-
|
19
|
-
def resend_multipart(email)
|
20
|
-
email.attachments.each do |att|
|
21
|
-
fn = att.filename
|
22
|
-
v = YVideo.new()
|
23
|
-
begin
|
24
|
-
f = StringIO.new(att.body.decoded)
|
25
|
-
v.filename = fn
|
26
|
-
v.file_object = f
|
27
|
-
v.title = fn
|
28
|
-
begin
|
29
|
-
v.save
|
30
|
-
puts "Saving to S3 succeeded"
|
31
|
-
rescue Exception => e
|
32
|
-
puts "S3 Failed miserably: #{e.message}"
|
33
|
-
end
|
34
|
-
rescue Exception => e
|
35
|
-
puts "Unable to save data for #{fn} because of #{e.message}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
text_body = email.parts.select{|p| p.content_type.include? "text/plain" }.first.body.to_s
|
40
|
-
puts "Email subject: #{email.subject}"
|
41
|
-
begin
|
42
|
-
resent = MailHandler.resend(["whyhermancain@gmail.com"], ["support@wearefound.com"], "[CAIN] Successful Upload", "A new testimonial video has been uploaded via email to s3. Its url is http://s3.amazonaws.com/whyHermanCain/#{v.filename}")
|
43
|
-
resent.deliver
|
44
|
-
puts "sent"
|
45
|
-
rescue
|
46
|
-
return
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def upload(f)
|
51
|
-
puts "completed #{f}"
|
52
|
-
end
|
53
|
-
end
|