Class: Addic7ed::VideoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/addic7ed/video_file.rb

Constant Summary collapse

TVSHOW_REGEX =
/\A(?<showname>.*\w)[\[\. ]+S?(?<season>\d{1,2})[-\. ]?[EX]?(?<episode>\d{2})([-\. ]?[EX]?\d{2})*[\]\. ]+(?<tags>.*)-(?<group>\w*)\[?(?<distribution>\w*)\]?(\.\w{3})?\z/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ VideoFile

Returns a new instance of VideoFile.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/addic7ed/video_file.rb', line 8

def initialize(filename)
  @filename = filename
  if match = TVSHOW_REGEX.match(basename)
    @showname     = match[:showname]
    @season       = match[:season].to_i
    @episode      = match[:episode].to_i
    @tags         = match[:tags].upcase.split(/[\. ]/)
    @group        = match[:group].upcase
    @distribution = match[:distribution].upcase
  else
    raise InvalidFilename
  end
end

Instance Attribute Details

#distributionObject (readonly)

Returns the value of attribute distribution.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def distribution
  @distribution
end

#episodeObject (readonly)

Returns the value of attribute episode.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def episode
  @episode
end

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def filename
  @filename
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def group
  @group
end

#seasonObject (readonly)

Returns the value of attribute season.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def season
  @season
end

#shownameObject (readonly)

Returns the value of attribute showname.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def showname
  @showname
end

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/addic7ed/video_file.rb', line 6

def tags
  @tags
end

Instance Method Details

#basenameObject



22
23
24
# File 'lib/addic7ed/video_file.rb', line 22

def basename
  @basename ||= ::File.basename(@filename)
end

#inspectObject



30
31
32
33
34
35
36
37
38
# File 'lib/addic7ed/video_file.rb', line 30

def inspect
"Guesses for #{@filename}:
  show:         #{@showname}
  season:       #{@season}
  episode:      #{@episode}
  tags:         #{@tags}
  group:        #{@group}
  distribution: #{@distribution}"
end

#to_sObject



26
27
28
# File 'lib/addic7ed/video_file.rb', line 26

def to_s
  @filename
end