Skip to content

Commit

Permalink
Modified transfers to only require gems if the type of transfer is ac…
Browse files Browse the repository at this point in the history
…tivated.
  • Loading branch information
carsonmcdonald committed Mar 31, 2010
1 parent 8595f70 commit a780301
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions hs_config.rb
Expand Up @@ -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
Expand All @@ -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
33 changes: 30 additions & 3 deletions hs_transfer.rb
Expand Up @@ -17,9 +17,6 @@
#

require 'rubygems'
require 'net/scp'
require 'net/ftp'
require 'right_aws'

class HSTransfer

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
25 changes: 1 addition & 24 deletions http_streamer.rb
Expand Up @@ -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
Expand All @@ -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')

Expand Down

0 comments on commit a780301

Please sign in to comment.