class MovieOrganizer::TvShow

Constants

S_E_EXPRESSIONS

Attributes

preserve_episode_name[R]
tvdb_instance[R]

Public Class Methods

match?(filepath) click to toggle source
# File lib/movie_organizer/tv_show.rb, line 13
def match?(filepath)
  index = nil
  clean_title = nil
  base = basename(filepath)
  sanitized = sanitize(base)
  S_E_EXPRESSIONS.each do |regex|
    next unless (md = sanitized.match(regex))
    index = sanitized.index(md[1], 0)
    clean_title = sanitized[0..index - 1].strip
    break
  end
  return false unless clean_title
  tvdb_instance = TvdbInstance.new(clean_title)
  return tvdb_instance if tvdb_instance.tv_show?
  false
end
new(filename, tvdb_instance) click to toggle source
Calls superclass method MovieOrganizer::Medium::new
# File lib/movie_organizer/tv_show.rb, line 31
def initialize(filename, tvdb_instance)
  super(filename)
  @tvdb_instance         = tvdb_instance
  @season                = nil
  @episode               = nil
  @episode_title         = nil
  @season_and_episode    = nil
  @preserve_episode_name = false
end

Public Instance Methods

process!() click to toggle source

Set the target filename

# File lib/movie_organizer/tv_show.rb, line 43
def process!
  return nil if should_skip?

  @target = File.join(target_dir, processed_filename)
  Logger.instance.info("    target file: [#{@target.green.bold}]")
end
processed_filename() click to toggle source

Standardize the filename @return [String] cleaned filename

# File lib/movie_organizer/tv_show.rb, line 52
def processed_filename
  return nil if should_skip?
  if @preserve_episode_name && episode_title
    "#{title} - #{season_and_episode} - #{episode_title}#{extname}"
  else
    "#{title} - #{season_and_episode}#{extname}"
  end
end
season() click to toggle source
# File lib/movie_organizer/tv_show.rb, line 65
def season
  return @season unless @season.nil?
  season_and_episode
  @season
end
title() click to toggle source
# File lib/movie_organizer/tv_show.rb, line 61
def title
  tvdb_instance.match.title
end

Private Instance Methods

episode_title() click to toggle source
# File lib/movie_organizer/tv_show.rb, line 85
def episode_title
  return @episode_title unless @episode_title.nil?
  md = basename.match(/([^-]+)-([^-]+)-([^-]+)/)
  @episode_title = md[3].sub(/#{ext}$/, '').strip if md
  @episode_title
end
season_and_episode() click to toggle source
# File lib/movie_organizer/tv_show.rb, line 92
def season_and_episode
  return @season_and_episode unless @season_and_episode.nil?
  base = basename.gsub(/#{title}[\.\s]*/i, '')
  s_and_e_info = sanitize(base)
  S_E_EXPRESSIONS.each do |regex|
    md = s_and_e_info.match(regex)
    next unless md
    @season = md[2].rjust(2, '0')
    @episode = md[3].rjust(2, '0')
    @season_and_episode = "S#{@season}E#{@episode}"
    return @season_and_episode
  end
  @season_and_episode
end
should_skip?() click to toggle source
# File lib/movie_organizer/tv_show.rb, line 73
def should_skip?
  filename.match(/[\.\s-]?sample[\.\s-]?/)
end
target_dir() click to toggle source
# File lib/movie_organizer/tv_show.rb, line 77
def target_dir
  @target_dir ||= File.join(
    MovieOrganizer.tv_shows_directory,
    title,
    "Season #{season.sub(/^0+/, '')}"
  )
end