Permalink
Browse files

Modified transfers to only require gems if the type of transfer is ac…

…tivated.
  • Loading branch information...
1 parent 8595f70 commit a780301753debf2ff31e62662d6f55fbcf7cd845 @carsonmcdonald committed Mar 31, 2010
Showing with 64 additions and 28 deletions.
  1. +1 −1 README.md
  2. +32 −0 hs_config.rb
  3. +30 −3 hs_transfer.rb
  4. +1 −24 http_streamer.rb
View
@@ -17,7 +17,7 @@ The project includes a ruby script and a C program that use FFMpeg to encode and
## REQUIREMENTS
-FFMpeg is the primary external requirement for the ruby script. The segmenter needs libavformat to compile and that can be obtained by installing FFMpeg. The script also needs the following gems installed:
+FFMpeg is the primary external requirement for the ruby script. The segmenter needs libavformat to compile and that can be obtained by installing FFMpeg. The script also needs the following gems installed if you want to be able to use SCP or S3 as transfer options:
- *Net::SCP*
See http://net-ssh.rubyforge.org/ for more information. To intall run gem install net-scp
View
@@ -16,6 +16,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
+require 'hs_transfer'
+
+require 'logger'
require 'yaml'
class HSConfig
@@ -33,10 +36,39 @@ def [](index)
@config[index]
end
+ def self.log_setup(config)
+ if config['log_type'] == 'FILE'
+ log = Logger.new(config['log_file'])
+ else
+ log = Logger.new(STDOUT)
+ end
+
+ case config['log_level']
+ when 'DEBUG'
+ log.level = Logger::DEBUG
+ when 'INFO'
+ log.level = Logger::INFO
+ when 'WARN'
+ log.level = Logger::WARN
+ when 'ERROR'
+ log.level = Logger::ERROR
+ else
+ log.level = Logger::DEBUG
+ end
+
+ return log
+ end
+
private
def sanity_check(config)
# TODO
+
+ log = HSConfig::log_setup(config)
+
+ log.info("No FTP transfers available. Missing FTP gem.") if !HSTransfer::can_ftp
+ log.info("No SCP transfers available. Missing SCP gem.") if !HSTransfer::can_scp
+ log.info("No S3 transfers available. Missing AWS gem.") if !HSTransfer::can_s3
end
end
View
@@ -17,9 +17,6 @@
#
require 'rubygems'
-require 'net/scp'
-require 'net/ftp'
-require 'right_aws'
class HSTransfer
@@ -72,6 +69,33 @@ def start_transfer_thread
end
end
+ def self.can_scp
+ begin
+ require 'net/scp'
+ return true
+ rescue LoadError
+ return false
+ end
+ end
+
+ def self.can_ftp
+ begin
+ require 'net/ftp'
+ return true
+ rescue LoadError
+ return false
+ end
+ end
+
+ def self.can_s3
+ begin
+ require 'right_aws'
+ return true
+ rescue LoadError
+ return false
+ end
+ end
+
private
def create_and_transfer_multirate_index
@@ -131,18 +155,21 @@ def transfer_file(source_file, destination_file)
when 'copy'
File.copy(source_file, transfer_config['directory'] + '/' + destination_file)
when 'ftp'
+ require 'net/ftp'
Net::FTP.open(transfer_config['remote_host']) do |ftp|
ftp.login(transfer_config['user_name'], transfer_config['password'])
files = ftp.chdir(transfer_config['directory'])
ftp.putbinaryfile(source_file, destination_file)
end
when 'scp'
+ require 'net/scp'
if transfer_config.has_key?('password')
Net::SCP.upload!(transfer_config['remote_host'], transfer_config['user_name'], source_file, transfer_config['directory'] + '/' + destination_file, :password => transfer_config['password'])
else
Net::SCP.upload!(transfer_config['remote_host'], transfer_config['user_name'], source_file, transfer_config['directory'] + '/' + destination_file)
end
when 's3'
+ require 'right_aws'
s3 = RightAws::S3Interface.new(transfer_config['aws_api_key'], transfer_config['aws_api_secret'])
content_type = source_file =~ /.*\.m3u8$/ ? 'application/x-mpegURL' : 'video/MP2T'
View
@@ -20,29 +20,6 @@
require 'hs_config'
require 'hs_encoder'
-def log_setup(config)
- if config['log_type'] == 'FILE'
- log = Logger.new(config['log_file'])
- else
- log = Logger.new(STDOUT)
- end
-
- case config['log_level']
- when 'DEBUG'
- log.level = Logger::DEBUG
- when 'INFO'
- log.level = Logger::INFO
- when 'WARN'
- log.level = Logger::WARN
- when 'ERROR'
- log.level = Logger::ERROR
- else
- log.level = Logger::DEBUG
- end
-
- return log
-end
-
# **************************************************************
#
# Main
@@ -60,7 +37,7 @@ def log_setup(config)
config = HSConfig::load( ARGV[0] )
-log = log_setup( config )
+log = HSConfig::log_setup( config )
log.info('HTTP Streamer started')

0 comments on commit a780301

Please sign in to comment.