Sha256: 34bd6574546496d288e85c3594209825c4f655daa30b6a0752cf9b9e84dc29c6

Contents?: true

Size: 1.29 KB

Versions: 27

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'ehbrs/fs/compressed_package'

module Ehbrs
  module Videos
    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

27 entries across 27 versions & 1 rubygems

Version Path
ehbrs-tools-0.26.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.25.1 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.25.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.24.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.23.1 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.23.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.22.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.21.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.20.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.19.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.18.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.17.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.16.5 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.16.4 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.16.3 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.16.2 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.16.1 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.16.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.15.0 lib/ehbrs/videos/extract/package_file.rb
ehbrs-tools-0.14.1 lib/ehbrs/videos/extract/package_file.rb