Sha256: 67d51a5231a87f32cb99f00a3ac20c96b76466d1e832a56fe6f754e3b3091c25

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EhbrsRubyUtils
  module Videos2
    module Extract
      class PackageFile
        DEFAULT_QUALITY = '__default__'

        enable_simple_cache
        common_constructor :package, :path do
          self.path = path.to_pathname
        end

        def copy_to_selected_dir
          ::FileUtils.cp(path.to_path, selected_dir.to_path)
        end

        def match_quality?(quality)
          path.basename_sub { |b| b.to_s.downcase }.basename
            .fnmatch?("*#{quality.downcase}*".gsub(/\A\*+/, '*').gsub(/\*+\z/, '*'))
        end

        def move_to_quality_dir
          ::FileUtils.mv(path.to_path, quality_dir.to_path)
        end

        private

        def quality_uncached
          package.qualities.find { |q| match_quality?(q) } || DEFAULT_QUALITY
        end

        def quality_dir
          r = package.target_dir / quality
          r.mkpath
          r
        end

        def selected_dir
          r = nil
          r = package.target_dir / 'source' if /\.torrent/ =~ path.to_path
          r = package.target_dir / 'subtitle' if /\.srt/ =~ path.to_path
          raise "Destination unknown: #{path}" unless r

          r.mkpath
          r
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.3 lib/ehbrs_ruby_utils/videos2/extract/package_file.rb
ehbrs_ruby_utils-0.44.2 lib/ehbrs_ruby_utils/videos2/extract/package_file.rb
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/videos2/extract/package_file.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/videos2/extract/package_file.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/videos2/extract/package_file.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/videos2/extract/package_file.rb