Last active
January 25, 2016 12:26
-
-
Save CarlosEspejo/5267b93a9584e6c0d7f0 to your computer and use it in GitHub Desktop.
Ruby Transcoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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