Class: MovieOrganizer::Media

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

Overview

This meta-class factory accepts the media filename, and from that determines if it is likely to be:

  1. a TV show

  2. a Movie

  3. a home video or other type

Direct Known Subclasses

Movie, TvShow, Video

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options) ⇒ Media

Returns a new instance of Media.



24
25
26
27
28
29
30
# File 'lib/movie_organizer/media.rb', line 24

def initialize(filename, options)
  @filename = filename
  @options = options
  @tv_show = nil
  @logger = Logger.instance
  @settings = Settings.new
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



15
16
17
# File 'lib/movie_organizer/media.rb', line 15

def filename
  @filename
end

#loggerObject

Returns the value of attribute logger.



15
16
17
# File 'lib/movie_organizer/media.rb', line 15

def logger
  @logger
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/movie_organizer/media.rb', line 15

def options
  @options
end

#settingsObject

Returns the value of attribute settings.



15
16
17
# File 'lib/movie_organizer/media.rb', line 15

def settings
  @settings
end

Class Method Details

.subtype(filename, options) ⇒ Object



17
18
19
20
21
22
# File 'lib/movie_organizer/media.rb', line 17

def self.subtype(filename, options)
  instance = new(filename, options)
  return TvShow.new(filename, options) if instance.tv_show?
  return Movie.new(filename, options) if instance.movie?
  Video.new(filename, options)
end

Instance Method Details

#movie?Boolean

Returns:

  • (Boolean)


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

def movie?
  return @movie unless @movie.nil?
  @movie = false
  Tmdb::Api.key(settings[:movies][:tmdb_key])
  title = sanitize(File.basename(filename, ext)).gsub(/\d\d\d\d/, '').strip
  matches = Tmdb::Movie.find(title)
  @movie = matches.any?
  @movie
end

#tv_show?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/movie_organizer/media.rb', line 32

def tv_show?
  return @tv_show unless @tv_show.nil?
  @tv_show = false
  @tv_show = true unless filename.match(/S\d+E\d+/i).nil?
  @tv_show = true unless filename.match(/\d+x\d+/i).nil?
  @tv_show
end

#yearObject



50
51
52
53
# File 'lib/movie_organizer/media.rb', line 50

def year
  md = basename.match(/\((\d\d\d\d)\)|(19\d\d)|(20\d\d)/)
  md ? md.captures.compact.first : nil
end