Sha256: fba04fe8c40ff74582833fb54512f4254a906b2bbf5d0836c54f574c1c0bf29b

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require 'pry'
require 'trollop'
require 'colored'

module MovieOrganizer
  class Organizer
    attr_accessor :logger, :options

    # Make a singleton but allow the class to be instantiated for easier testing
    def self.instance
      @instance || new
    end

    def initialize
      @logger = Logger.instance
    end

    def start
      start_time = Time.now
      @options = collect_args
      logger.info('Starting MovieOrganizer...'.green)
      count = 0

      # Enumerate all of the new source media
      @media_list = MediaList.new(MovieOrganizer.source_directories)

      # Process each source file
      @media_list.file_collection.each do |file|
        # Get movie or TV show information so we can rename the file if necessary
        media = Media.subtype(file, options)
        # Move and/or rename the file
        logger.info("Processing [#{file}] - #{media.class.to_s.yellow}")
        media.process!
        count += 1
      end
      elapsed = Time.now - start_time
      logger.info("Processed #{count} vidoes in [#{elapsed}] seconds.".yellow)
    end

    private

    def collect_args
      Trollop.options do
        opt(
          :source_dir,
          'Source directories containing media files. Colon (:) separated.',
          type: :string, required: false, short: '-s')
        opt(
          :dry_run,
          'Do not actually move or copy files',
          type: :boolean, required: false, short: '-d',
          default: false)
        opt(
          :preserve_episode_name,
          'Preserve episode names if they exist (experimental)',
          type: :boolean, required: false, short: '-p',
          default: false)
        opt(
          :verbose,
          'Be verbose with output',
          type: :boolean, required: false, short: '-v',
          default: false)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
movie_organizer-0.1.2 lib/movie_organizer/organizer.rb
movie_organizer-0.1.1 lib/movie_organizer/organizer.rb
movie_organizer-0.1.0 lib/movie_organizer/organizer.rb