class MovieCleaner::Cleaner

Cleaner prints commands to remove all unwanted movie files in a directory

Public Class Methods

new(base_path, verbose = false, possible_resolutions = nil) click to toggle source
# File lib/movie_cleaner/cleaner.rb, line 6
def initialize(base_path, verbose = false, possible_resolutions = nil)
  @base_path = base_path
  @verbose = verbose
  @possible_resolutions = possible_resolutions || %w[1080p 720p]
end

Public Instance Methods

print_rm_commands() click to toggle source
sub_par_files() click to toggle source
# File lib/movie_cleaner/cleaner.rb, line 12
def sub_par_files
  sub_par_files_per_movie.flat_map do |movie, files|
    next if files.empty?

    files.map { |file| full_path(movie, file) }
  end.compact
end

Private Instance Methods

full_path(movie, file) click to toggle source
# File lib/movie_cleaner/cleaner.rb, line 60
def full_path(movie, file)
  "#{@base_path}/#{movie}/#{file}"
end
movie_files() click to toggle source
# File lib/movie_cleaner/cleaner.rb, line 51
def movie_files
  @movie_files ||= Dir["#{@base_path}/*"].map do |dir|
    [
      File.basename(dir),
      Dir["#{dir}/*.{mkv,mov,mp4}"].map { |f| File.basename(f) }
    ]
  end.to_h
end
print_rm_commands_for_files(movie, files) click to toggle source
sub_par_files_per_movie() click to toggle source
# File lib/movie_cleaner/cleaner.rb, line 36
def sub_par_files_per_movie
  movie_files.map do |movie, files|
    current_sub_par_files = []
    @possible_resolutions.each do |resolution|
      next if files.none? { |f| f.include?(resolution) }

      current_sub_par_files = files.reject { |f| f.include?(resolution) }
      break
    end
    next if current_sub_par_files.empty?

    [movie, current_sub_par_files]
  end.compact.to_h
end
vputs(*args) click to toggle source
# File lib/movie_cleaner/cleaner.rb, line 64
def vputs(*args)
  puts args if @verbose
end