Sha256: 760d9d97b328b63cd39769ac6f2c39890ee72e2d2b0b352151db162073b8b272

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require 'eac_cli/core_ext'
require 'ehbrs_ruby_utils/videos2/extract/package'

module Ehbrs
  module Tools
    class Runner
      class Videos
        class Extract
          require_sub __FILE__

          DEFAULT_QUALITIES = %w[1080 720 web webrip hdtv].freeze

          runner_with :help do
            desc 'Extrai arquivos de seriados.'
            arg_opt '-d', '--dir', 'Extraí para diretório.'
            bool_opt '-D', '--delete', 'Remove o pacote após o processamento.'
            arg_opt '-q', '--qualities', 'Lista de qualidades.'
            pos_arg 'packages', repeat: true
          end

          def run
            start_banner
            packages.each do |package|
              infov 'Package', package
              package.run(parsed.delete?)
            end
          end

          private

          def packages_uncached
            parsed.packages?.map do |p|
              ::EhbrsRubyUtils::Videos2::Extract::Package.new(p, target_dir, qualities)
            end
          end

          def qualities_uncached
            (parsed.qualities.to_s.split(',') + DEFAULT_QUALITIES).uniq
          end

          def start_banner
            infov 'Packages', packages.count
            infov 'Qualities', qualities
            infov 'Target directory', target_dir
          end

          def target_dir_uncached
            parsed.dir.if_present(&:to_pathname) || default_target_dir
          end

          def default_target_dir
            r = parsed.packages.first.to_pathname.basename('.*')
            return r unless r.exist?

            r = r.basename_sub { |b| "#{b}_extract" }
            index = 0
            loop do
              return r unless r.exist?

              index += 1
              r = r.basename_sub { |b| "#{b}_#{index}" }
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ehbrs-tools-0.43.1 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.43.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.42.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.39.1 lib/ehbrs/tools/runner/videos/extract.rb