Class: Addic7ed::VideoFile

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

Overview

Represents the video file you're looking a subtitle for.

This class will extract from the video file name the show name, season, episode, group, etc.

It expects the file to be named according to The Scene rules, but actually supports a wide variety of common naming schemes.

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ String

Returns a new instance of Addic7ed::VideoFile. It expects a video file name, either with or without path and either absolute or relative.

Examples:

Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
Addic7ed::VideoFile.new("/home/mike/Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
Addic7ed::VideoFile.new("../Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")

Parameters:

  • filename (String)

    File name of the video file on disk (either relative or absolute).

Raises:

  • (InvalidFilename)

29
30
31
32
33
# File 'lib/addic7ed/models/video_file.rb', line 29

def initialize(filename)
  @filename = filename
  @regexp_matches = TVSHOW_REGEX.match(basename)
  raise InvalidFilename if regexp_matches.nil?
end

Instance Method Details

#basenameString

Returns the base file name (without path).

Examples:

video_file = Addic7ed::VideoFile.new("../Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.basename #=> "Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv"

Returns:

  • (String)

    Base file name


116
117
118
# File 'lib/addic7ed/models/video_file.rb', line 116

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

#distributionString

Returns the upcased distribution group extracted from the file name.

Examples:

video_file = Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS[eztv].mkv")
video_file.distribution #=> "EZTV"

Returns:

  • (String)

    Distribution group name


104
105
106
# File 'lib/addic7ed/models/video_file.rb', line 104

def distribution
  @distribution ||= regexp_matches[:distribution].upcase
end

#episodeInteger

Returns the TV show episode number extracted from the file name.

Examples:

video_file = Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.episode #=> 9

Returns:

  • (Integer)

    TV show episode number


67
68
69
# File 'lib/addic7ed/models/video_file.rb', line 67

def episode
  @episode ||= regexp_matches[:episode].to_i
end

#groupString

Returns the upcased release group extracted from the file name.

Examples:

video_file = Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.group #=> "AVS"

Returns:

  • (String)

    Release group name


92
93
94
# File 'lib/addic7ed/models/video_file.rb', line 92

def group
  @group ||= regexp_matches[:group].upcase
end

#inspectString

Returns a multiline, human-readable breakdown of the file name including all detected attributes (show name, season, episode, tags, …).

Returns:

  • (String)

    a human-readable breakdown of the file name


137
138
139
140
141
142
143
144
145
# File 'lib/addic7ed/models/video_file.rb', line 137

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

#seasonInteger

Returns the TV show season number extracted from the file name.

Examples:

video_file = Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.season #=> 6

Returns:

  • (Integer)

    TV show season number


55
56
57
# File 'lib/addic7ed/models/video_file.rb', line 55

def season
  @season ||= regexp_matches[:season].to_i
end

#shownameString

Returns the TV show name extracted from the file name.

Examples:

video_file = Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.showname #=> "Game.of.Thrones"

Returns:

  • (String)

    TV show name


43
44
45
# File 'lib/addic7ed/models/video_file.rb', line 43

def showname
  @showname ||= regexp_matches[:showname]
end

#tagsArray<String>

Returns the upcased release tags extracted from the file name (like HDTV, 720P, XviD, PROPER, …).

Examples:

video_file = Addic7ed::VideoFile.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.tags #=> ["720P", "HDTV", "X264"]

Returns:

  • (Array<String>)

    Release video, audio or packaging tags


80
81
82
# File 'lib/addic7ed/models/video_file.rb', line 80

def tags
  @tags ||= regexp_matches[:tags].upcase.split(/[\. ]/)
end

#to_sString

Returns the video file name as passed to #initialize.

Examples:

video_file = Addic7ed::VideoFile.new("../Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv")
video_file.to_s #=> "../Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv"

Returns:

  • (String)

    File name


128
129
130
# File 'lib/addic7ed/models/video_file.rb', line 128

def to_s
  filename
end