Sha256: bf5aff681d6b9f3dc6fc33ea1421dae8447ae356b42519464d739c8f1eef8ae6

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require_relative 'string'

module MovieOrganizer
  class Video < Media
    attr_reader :settings

    def initialize(filename, options)
      @settings = Settings.new
      super
    end

    def process!(file_copier = nil)
      target_file = File.join(target_dir, processed_filename)
      logger.info("    target dir: [#{target_dir}]")
      logger.info("    target file: [#{target_file.green.bold}]")
      fc = file_copier || FileCopier.new(filename, target_file, options)
      fc.copy
    end

    def processed_filename
      "#{title} (#{year})#{ext}"
    end

    def title
      @title ||= begin
        prompt = <<-STRING.here_with_pipe(' ')
          |Enter a friendly title for this video: [#{basename}]
          |or hit enter to keep the current title
        STRING
        new_title = MovieOrganizer.prompt_for(prompt, '')
        return File.basename(filename, ext) if new_title.nil? || new_title.empty?
        new_title
      end
    end

    def date_time
      filestat = File.stat(filename)
      filestat.birthtime.strftime('%Y-%m-%d @ %l:%M %p')
    end

    # private

    def target_dir
      File.join(MovieOrganizer.video_directory, "#{title} (#{date_time})")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
movie_organizer-0.1.11 lib/movie_organizer/video.rb
movie_organizer-0.1.10 lib/movie_organizer/video.rb
movie_organizer-0.1.9 lib/movie_organizer/video.rb
movie_organizer-0.1.8 lib/movie_organizer/video.rb