Skip to content

Instantly share code, notes, and snippets.

@CarlosEspejo
Last active January 25, 2016 12:26
Show Gist options
  • Save CarlosEspejo/5267b93a9584e6c0d7f0 to your computer and use it in GitHub Desktop.
Save CarlosEspejo/5267b93a9584e6c0d7f0 to your computer and use it in GitHub Desktop.
Ruby Transcoder
require 'fileutils'
class Encoder
attr_reader :processed, :search_path, :queue
def initialize
@search_path = '/mnt/data/media'
@processed = File.readlines('encode.log') if File.exists?('encode.log')
@processed = Array(processed).map(&:chomp)
@queue = Dir.glob("#{search_path}/**/*.avi").sort
puts "Found #{queue.size} avi files"
end
def process
(queue - processed).each do |f|
directory_path = File.dirname(f)
new_filename = "#{File.basename(f, '.*')}.mp4"
encode(f, new_filename)
FileUtils.mv(new_filename, File.join(directory_path, new_filename))
File.open('encode.log', 'a') { |file| file.puts f }
end
end
private
def encode(source, target)
system %{HandBrakeCLI -i "#{source}" -o ./"#{target}" --preset="High Profile"}
end
end
Encoder.new.process
require 'fileutils'
open('encode.log').each do |l|
path = "#{l}".chomp
FileUtils.rm path if File.exists?(path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment