Class: MovieOrganizer::TvShow

Inherits:
Media
  • Object
show all
Defined in:
lib/movie_organizer/tv_show.rb

Constant Summary collapse

S_E_EXPRESSIONS =
[
  /(s(\d+)e(\d+))/i,
  /((\d+)x(\d+))/i,
  /[\.\s]((\d)(\d+))[\.\s]/i
]

Instance Attribute Summary

Attributes inherited from Media

#filename, #logger, #options, #settings

Instance Method Summary collapse

Methods inherited from Media

#movie?, subtype, #tv_show?, #year

Constructor Details

#initialize(filename, options) ⇒ TvShow

Returns a new instance of TvShow.



9
10
11
12
13
14
15
# File 'lib/movie_organizer/tv_show.rb', line 9

def initialize(filename, options)
  super
  @season = nil
  @episode = nil
  @episode_title = nil
  @season_and_episode = nil
end

Instance Method Details

#process!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/movie_organizer/tv_show.rb', line 17

def process!
  return nil if should_skip?
  # rename the file
  fail "Show not configured #{basename}" if title.nil?
  target_dir = File.join(
    settings[:tv_shows][:directory],
    title,
    "Season #{season.sub(/^0+/, '')}"
  )
  FileUtils.mkdir_p(target_dir, noop: dry_run?)
  target_file = File.join(target_dir, processed_filename)
  logger.info("    target dir: [#{target_dir}]")
  logger.info("    target file: [#{target_file.green.bold}]")
  FileUtils.move(
    filename,
    target_file,
    force: true, noop: dry_run?
  )
rescue ArgumentError => err
  raise err unless err.message.match(/^same file:/)
end

#processed_filenameString

Standardize the filename

Returns:

  • (String)

    cleaned filename



41
42
43
44
45
46
47
48
# File 'lib/movie_organizer/tv_show.rb', line 41

def processed_filename
  return nil if should_skip?
  if options[:preserve_episode_name] && episode_title
    "#{title} - #{season_and_episode} - #{episode_title}#{ext}"
  else
    "#{title} - #{season_and_episode}#{ext}"
  end
end

#seasonObject



62
63
64
65
66
# File 'lib/movie_organizer/tv_show.rb', line 62

def season
  return @season unless @season.nil?
  season_and_episode
  @season
end

#titleObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/movie_organizer/tv_show.rb', line 50

def title
  return @title unless @title.nil?
  settings[:tv_shows][:my_shows].each do |show|
    md = sanitize(basename).match(Regexp.new(sanitize(show), Regexp::IGNORECASE))
    if md
      @title = md[0].titleize
      return @title
    end
  end
  @title
end