Refactored some of the code to match Rubocop style guidelines; will need to create rubocop config to make the style better
This commit is contained in:
parent
4c3ea4ea87
commit
bc799ff2cb
@ -1,29 +1,30 @@
|
|||||||
require 'toml'
|
require 'toml'
|
||||||
|
|
||||||
|
# Loads and handles the application configuration.
|
||||||
class Config
|
class Config
|
||||||
|
|
||||||
# class constructor
|
# class constructor
|
||||||
def initialize(config_path)
|
def initialize(config_path)
|
||||||
expanded_path = File.expand_path(config_path)
|
expanded_path = File.expand_path(config_path)
|
||||||
@config = TOML::load_file(expanded_path)
|
@config = TOML::load_file(expanded_path)
|
||||||
|
|
||||||
# just in case the user wants to use a tilde (~) in the repository path...
|
# just in case the user wants to use a tilde (~) in the repository path...
|
||||||
@config['transcoder']['repository'] = File.expand_path(self.get('transcoder.repository'))
|
@config['transcoder']['repository'] = File.expand_path(self.get('transcoder.repository'))
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns a configuration value from a dot-seperated string, like 'transcoder.interval'
|
# returns a configuration value from a dot-seperated string, like 'transcoder.interval'
|
||||||
def get(path)
|
def get(path)
|
||||||
value = @config
|
value = @config
|
||||||
bits = path.split('.')
|
bits = path.split('.')
|
||||||
bits.each { |bit|
|
bits.each { |bit|
|
||||||
if (value.has_key?(bit))
|
if (value.key?(bit))
|
||||||
value = value[bit]
|
value = value[bit]
|
||||||
else
|
else
|
||||||
abort("Configuration value #{path} does exist.")
|
abort("Configuration value #{path} does exist.")
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,44 +2,45 @@ require_relative 'util.rb'
|
|||||||
|
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
|
# Handles anything pertaining to the video file repository.
|
||||||
class Repository
|
class Repository
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@basePath = path
|
@base_path = path
|
||||||
|
|
||||||
# create repository base directory
|
# create repository base directory
|
||||||
createDirectory(@basePath)
|
create_directory(@base_path)
|
||||||
|
|
||||||
# create sub-directories
|
# create sub-directories
|
||||||
subPaths = ['ingest', 'archive', 'output']
|
sub_paths = ['ingest', 'archive', 'output']
|
||||||
subPaths.each { |p|
|
sub_paths.each { |p|
|
||||||
createDirectory(File.join(@basePath, p))
|
create_directory(File.join(@base_path, p))
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def searchIngest
|
def search_ingest
|
||||||
# create our ingest directory path
|
# create our ingest directory path
|
||||||
ingestPath = File.join(@basePath, 'ingest')
|
ingest_path = File.join(@base_path, 'ingest')
|
||||||
# search for files in ingest; ignore non-files (e.g. directories)
|
# search for files in ingest; ignore non-files (e.g. directories)
|
||||||
ingestFiles = Dir.entries(ingestPath).select { |f| File.file? File.join(ingestPath, f) }
|
ingest_files = Dir.entries(ingest_path).select { |f| File.file? File.join(ingest_path, f) }
|
||||||
|
|
||||||
return ingestFiles
|
return ingest_files
|
||||||
end
|
end
|
||||||
|
|
||||||
def archiveFile(filename)
|
def archive_file(filename)
|
||||||
# create source and destination paths for the copy
|
# create source and destination paths for the copy
|
||||||
ingestPath = File.join(@basePath, 'ingest', filename)
|
ingest_path = File.join(@base_path, 'ingest', filename)
|
||||||
archivePath = File.join(@basePath, 'archive', filename)
|
archive_path = File.join(@base_path, 'archive', filename)
|
||||||
|
|
||||||
# perform the copy, preserving file attributes
|
# perform the copy, preserving file attributes
|
||||||
FileUtils.cp(ingestPath, archivePath, preserve: true)
|
FileUtils.cp(ingest_path, archive_path, preserve: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanupFile(filename)
|
def cleanup_file(filename)
|
||||||
# create ingest path
|
# create ingest path
|
||||||
ingestPath = File.join(@basePath, 'ingest', filename)
|
ingest_path = File.join(@base_path, 'ingest', filename)
|
||||||
# remove the file
|
# remove the file
|
||||||
FileUtils.remove_file(ingestPath)
|
FileUtils.remove_file(ingest_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,23 +1,24 @@
|
|||||||
|
# Handles the actual transcoding.
|
||||||
class Transcoder
|
class Transcoder
|
||||||
|
|
||||||
def initialize(config, repository)
|
def initialize(config, repository)
|
||||||
@config = config
|
@config = config
|
||||||
@repository = repository
|
@repository = repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
puts "Starting transcoder..."
|
puts 'Starting transcoder...'
|
||||||
|
|
||||||
# search for files in ingest
|
# search for files in ingest
|
||||||
ingestFiles = @repository.searchIngest()
|
ingest_files = @repository.search_ingest()
|
||||||
ingestFiles.each { |ifile|
|
ingest_files.each { |ifile|
|
||||||
# archive the file
|
# archive the file
|
||||||
@repository.archiveFile(ifile)
|
@repository.archive_file(ifile)
|
||||||
# perform the transcode
|
# perform the transcode
|
||||||
# // TODO self.transcode(ifile)
|
# // TODO self.transcode(ifile)
|
||||||
# clean up the file from ingest
|
# clean up the file from ingest
|
||||||
@repository.cleanupFile(ifile)
|
@repository.cleanup_file(ifile)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
12
src/util.rb
12
src/util.rb
@ -1,7 +1,7 @@
|
|||||||
def createDirectory(path)
|
def create_directory(path)
|
||||||
if Dir.exists?(path)
|
if Dir.exist?(path)
|
||||||
puts "Directory #{path} already exists."
|
puts "Directory #{path} already exists."
|
||||||
else
|
else
|
||||||
puts "Creating directory #{path}."
|
puts "Creating directory #{path}."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user