Class: Addic7ed::Search

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

Overview

Represents a subtitle search for a video_filename in a language with multiple search criterias.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(video_filename, language, criterias = {}) ⇒ Search

Creates a new instance of Addic7ed::Search.

Currently supported search criterias are:

  • no_hi: do not include hearing impaired subtitles (defaults to false)

Examples:

Addic7ed::Search.new("Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv", :fr)
#=> #<Addic7ed::Search
#       @criterias={:no_hi=>false},
#       @language=:fr,
#       @video_filename="Game.of.Thrones.S06E09.720p.HDTV.x264-AVS.mkv"
#   >

Parameters:

  • video_filename (String)

    Path to the video file for which we search subtitles (either relative or absolute path)

  • language (String)

    ISO code of target subtitles language

  • criterias (Hash) (defaults to: {})

    List of search criterias the subtitles must match (will be merged with default criterias as described above)


31
32
33
34
35
# File 'lib/addic7ed/models/search.rb', line 31

def initialize(video_filename, language, criterias = {})
  @video_filename = video_filename
  @language       = language
  @criterias      = default_criterias.merge(criterias)
end

Instance Attribute Details

#criteriasHash

List of search criterias as a Hash.

Returns:

  • (Hash)

    the current value of criterias


9
10
11
# File 'lib/addic7ed/models/search.rb', line 9

def criterias
  @criterias
end

#languageString

ISO code of language (e.g. “en”, “fr”, “es”).

Returns:

  • (String)

    the current value of language


9
10
11
# File 'lib/addic7ed/models/search.rb', line 9

def language
  @language
end

#video_filenameString

Video file name we're searching subtitles for.

Returns:

  • (String)

    the current value of video_filename


9
10
11
# File 'lib/addic7ed/models/search.rb', line 9

def video_filename
  @video_filename
end

Instance Method Details

#all_subtitlesSubtitlesCollection

Returns the list of all available subtitles for this search, regardless of completeness, compatibility or search criterias.

Returns:


58
59
60
# File 'lib/addic7ed/models/search.rb', line 58

def all_subtitles
  @all_subtitles ||= SubtitlesCollection.new(episode.subtitles(language))
end

#best_subtitleSubtitlesCollection

Returns the best subtitle for the episode we're searching subtitles for.

The best subtitle means the more popular (i.e. most downloaded) subtitle among completed, compatible subtitles for the episode we're searching subtitles for.

Returns:


78
79
80
# File 'lib/addic7ed/models/search.rb', line 78

def best_subtitle
  @best_subtitle ||= matching_subtitles.most_popular
end

#episodeEpisode

Returns the Episode object we're searching subtitles for.

Returns:


49
50
51
# File 'lib/addic7ed/models/search.rb', line 49

def episode
  @episode ||= Episode.new(video_file.showname, video_file.season, video_file.episode)
end

#matching_subtitlesSubtitlesCollection

Returns the list of subtitles completed and compatible with the episode we're searching subtitles for, regardless of search criterias.

Returns:


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

def matching_subtitles
  @matching_subtitles ||= all_subtitles.completed.compatible_with(video_file.group)
end

#video_fileVideoFile

Returns the VideoFile object representing the video file we're searching subtitles for.

Returns:


41
42
43
# File 'lib/addic7ed/models/search.rb', line 41

def video_file
  @video_file ||= VideoFile.new(video_filename)
end