diff --git a/src/repository.rb b/src/repository.rb index 28ce619..a50f9c4 100644 --- a/src/repository.rb +++ b/src/repository.rb @@ -1,5 +1,7 @@ require_relative 'util.rb' +require 'fileutils' + class Repository def initialize(path) @@ -15,4 +17,29 @@ class Repository } end + def searchIngest + # create our ingest directory path + ingestPath = File.join(@basePath, 'ingest') + # search for files in ingest; ignore non-files (e.g. directories) + ingestFiles = Dir.entries(ingestPath).select { |f| File.file? File.join(ingestPath, f) } + + return ingestFiles + end + + def archiveFile(filename) + # create source and destination paths for the copy + ingestPath = File.join(@basePath, 'ingest', filename) + archivePath = File.join(@basePath, 'archive', filename) + + # perform the copy, preserving file attributes + FileUtils.cp(ingestPath, archivePath, preserve: true) + end + + def cleanupFile(filename) + # create ingest path + ingestPath = File.join(@basePath, 'ingest', filename) + # remove the file + FileUtils.remove_file(ingestPath) + end + end diff --git a/src/transcoder.rb b/src/transcoder.rb new file mode 100644 index 0000000..0b6c5c9 --- /dev/null +++ b/src/transcoder.rb @@ -0,0 +1,23 @@ +class Transcoder + + def initialize(config, repository) + @config = config + @repository = repository + end + + def start + puts "Starting transcoder..." + + # search for files in ingest + ingestFiles = @repository.searchIngest() + ingestFiles.each { |ifile| + # archive the file + @repository.archiveFile(ifile) + # perform the transcode + # // TODO self.transcode(ifile) + # clean up the file from ingest + @repository.cleanupFile(ifile) + } + end + +end diff --git a/src/zealot.rb b/src/zealot.rb index 2007d41..f5d1b63 100755 --- a/src/zealot.rb +++ b/src/zealot.rb @@ -2,6 +2,7 @@ require_relative 'config.rb' require_relative 'repository.rb' +require_relative 'transcoder.rb' # create new configuration instance c = Config.new('~/.config/zealot.toml') @@ -9,5 +10,8 @@ c = Config.new('~/.config/zealot.toml') # create new repository instance r = Repository.new(c.get('transcoder.repository')) -# print repository directory as a test -puts c.get('transcoder.repository') +# create new transcoder instance +t = Transcoder.new(c, r) + +# start the transcoder +t.start()