class SubtitleIt::Bin
Public Class Methods
get_extension(file)
click to toggle source
# File lib/subtitle_it/bin.rb, line 108 def self.get_extension(file) fail unless file =~ /\./ file.split('.').last end
print_languages()
click to toggle source
# File lib/subtitle_it/bin.rb, line 119 def self.print_languages puts 'CODE | LANGUAGE' LANGS.each do |l| puts " #{l[0]} | #{l[1]}" end end
run!(argv, lang = nil, format = nil, force = false, _delay = nil, first = false)
click to toggle source
# File lib/subtitle_it/bin.rb, line 77 def self.run!(argv, lang = nil, format = nil, force = false, _delay = nil, first = false) fail unless argv @lang = lang @force = force @format = format @first = first # TODO: generate_rsb unless File.exist?(argv[0]) puts "Can't find '#{argv.join}'".yellow exit 1 end @file_in = argv[0] @file_in_ext = Bin.get_extension(@file_in) if argv[1] @file_out = argv[1] @file_out_ext = Bin.get_extension(@file_out) @format = @file_out_ext end if MOVIE_EXTS.include? @file_in_ext Subdownloader.new.run!(@file_in, @lang, @format, @first) elsif SUB_EXTS.include? @file_in_ext Subwork.new.run!(@file_in, @format) else fail "Unknown file type '#{@file_in_ext}'." end end
swap_extension(file, extension)
click to toggle source
# File lib/subtitle_it/bin.rb, line 113 def self.swap_extension(file, extension) f = file.dup f[-3..-1] = extension f end
write_out(filename, dump)
click to toggle source
# File lib/subtitle_it/bin.rb, line 126 def self.write_out(filename, dump) if File.exist?(filename) && !@force puts "File exist: #{filename}".red else File.open(filename, 'w') { |f| f.write(dump) } puts "Done: #{filename}".yellow end end