class Ranger

Attributes

api_enabled[R]

Fetch show info from thetvdb.com and write nfo file

extensions[RW]

Extensions recognized as video files ['avi', 'mkv', 'mp4']

method[R]

Strategy used to copy files, default: :ln

source[R]

Path (directory) scanned to find tvshows

target[R]

Path (directory) where output is created

verbose[R]

Is verbose

Public Class Methods

Ranger#new(String source, String target, Symbol method) click to toggle source

Initialize

# File lib/ranger.rb, line 21
def initialize(source, target, method = :ln_s)
  @source      = source
  @target      = target
  @extensions  = ['avi', 'mkv', 'mp4']
  @api_enabled = true
  self.method  = method.to_sym
  self.verbose = false
end

Public Instance Methods

Ranger#api_enabled = Boolean b click to toggle source

Set @api_enabled

# File lib/ranger.rb, line 50
def api_enabled=(b)
  @api_enabled = !!(b)
end
Ranger#method = Symbol method click to toggle source

Set @method

# File lib/ranger.rb, line 34
def method=(method)
  @method = method.to_sym
end
Ranger#run() click to toggle source

Execute main method

# File lib/ranger.rb, line 58
def run
  entries = Lister.new(self.source).prepared_entries

  entries.each do |serie, seasons|
    outdir = Pathname.new(self.target.to_s).join(serie)
    FileUtils.mkdir_p(outdir)
    self.make_nfo(outdir)
    seasons.each do |season, paths|
      outdir = outdir.join(season)
      FileUtils.mkdir_p(outdir)
      paths.each { |path| self.copy(path, outdir) }
    end
  end
end
Ranger#verbose = Boolean b click to toggle source

Set @verbose

# File lib/ranger.rb, line 42
def verbose=(verbose)
  @verbose = !!(verbose)
end

Protected Instance Methods

Ranger#copy(String file, String outdir) → Boolean click to toggle source

Copy file

# File lib/ranger.rb, line 78
def copy(file, outdir)
  file    = Pathname.new(file)
  outfile = Pathname.new(outdir).join(file.basename)

  return false if not self.extensions.include?(file.extname[1..-1])
  case self.method
  when :ln
    FileUtils.ln(file, outfile, :force => true, :verbose => self.verbose)
  when :copy
    FileUtils.rm_f(outfile) if outfile.symlink?
    if not (outfile.exist? and FileUtils.compare_file(file, outfile))
      FileUtils.copy(file, outfile, :verbose => self.verbose)
    end
  else
    FileUtils.ln_s(file, outfile, :force => true, :verbose => self.verbose)
  end
  return true
end
Ranger#make_nfo(String path) → Ranger click to toggle source

Write nfo into path directory

# File lib/ranger.rb, line 101
def make_nfo(path)
  serie = Pathname.new(path).basename.to_s
  begin
    SerieGetter.new(serie).make_nfo(path) if self.api_enabled
    return self
  rescue Exception => e
    $stderr.puts e.message
  end
end