Sha256: 6d18b7802000f08fd63a8e85649867d624445e4c572563353eae581d40a4f7ab

Contents?: true

Size: 1.82 KB

Versions: 23

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'eac_cli/core_ext'
require 'ehbrs/videos/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|
              ::Ehbrs::Videos::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

23 entries across 23 versions & 1 rubygems

Version Path
ehbrs-tools-0.39.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.38.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.37.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.36.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.35.1 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.35.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.34.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.33.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.32.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.31.1 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.31.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.30.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.29.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.28.3 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.28.2 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.28.1 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.28.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.27.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.26.0 lib/ehbrs/tools/runner/videos/extract.rb
ehbrs-tools-0.25.1 lib/ehbrs/tools/runner/videos/extract.rb