Class: Dexter::Matchers::Video

Inherits:
AbstractMatcher show all
Defined in:
lib/dexter.rb

Direct Known Subclasses

Subtitle

Constant Summary collapse

EXTENSIONS =
['avi', 'mkv']

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractMatcher

#extension, #filename, #initialize

Constructor Details

This class inherits a constructor from Dexter::Matchers::AbstractMatcher

Class Method Details

.allowed?(filename) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
88
# File 'lib/dexter.rb', line 82

def self.allowed?(filename) 
  if !super(filename)
    return false
  end
  filename.downcase =~ /([0-9A-z\s\.]+)\s?\.?-?\s?\.?(s[0-9]+e[0-9]+|[0-9]+x[0-9]+).*/
  return !!$1
end

.output_formatObject



78
79
80
# File 'lib/dexter.rb', line 78

def self.output_format
  @output ||= ':name/S:season/:name S:seasonE:episode.:extension'
end

.output_format=(options) ⇒ Object



90
91
92
# File 'lib/dexter.rb', line 90

def self.output_format=(options)
  @output = options
end

Instance Method Details

#episodeObject



111
112
113
114
115
116
# File 'lib/dexter.rb', line 111

def episode
  filename.downcase =~ /[\s\.]?s[0-9]{2}e([0-9]{2})/
  filename.downcase =~ /[\s\.]?[0-9]+x([0-9]+)/ if $1.nil?
  return nil if $1.nil?
  $1.to_i
end

#nameObject



94
95
96
97
98
99
100
101
102
# File 'lib/dexter.rb', line 94

def name
  filename.downcase =~ /([0-9A-z\s\.]+)\s?\.?-?\s?\.?(s[0-9]+e[0-9]+|[0-9]+x[0-9]+).*/
  return nil if $1.nil?
  return $1.gsub('.', ' ')   \
    .split(' ')              \
    .collect(&:capitalize)   \
    .join(' ')               \
    .strip
end

#organize!(path) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/dexter.rb', line 131

def organize!(path)
  output_path = File.dirname(output(path))
  output_file = output(path)
  FileUtils.mkdir_p(output_path)
  FileUtils.mv(@filename, output_file) unless File.expand_path(@filename) == File.expand_path(output(path))
  return output(path)
end

#output(path) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/dexter.rb', line 118

def output(path)
  options = {
    :season => season.to_s.rjust(2,'0'),
    :episode => episode.to_s.rjust(2,'0'),
    :name => name,
    :path => path,
    :extension => extension
  }
  options.inject(':path/' + self.class.output_format){ |output, object|
    output = (output.gsub(":#{object[0]}", object[1]) || output)
  }
end

#seasonObject



104
105
106
107
108
109
# File 'lib/dexter.rb', line 104

def season
  filename.downcase =~ /[\s\.]?s([0-9]{2})e[0-9]{2}/
  filename.downcase =~ /[\s\.]?([0-9]+)x[0-9]+/ if $1.nil?
  return nil if $1.nil?
  $1.to_i
end