Class: Addic7ed::Subtitle

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

Overview

Represents a subtitle on Addic7ed.

This model contains as much information as possible for a subtitle as parsed on Addic7ed website.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Subtitle

Creates a new instance of Addic7ed::Subtitle created using options, usually from data parsed from an Addic7ed page.

The options hash can have the following keys as symbols:

  • version: main compatible release group(s) as parsed on the Addic7ed website

  • language: language full name

  • status: full-text advancement status

  • source: URL of website the subtitle was originally published on

  • downloads: number of times the subtitle has been downloaded

  • comment: manually added comment from the author or publisher

  • hi: hearing-impaired support

  • url: download URL for the subtitle file

Examples:

Addic7ed::Subtitle.new(
  version:   "Version KILLERS, 720p AVS, 0.00 MBs",
  language:  "French",
  status:    "Completed",
  source:    "http://sous-titres.eu",
  downloads: 10335,
  comment:   "works with 1080p.BATV",
  hi:        false,
  url:       "http://www.addic7ed.com/original/113643/4"
)
#=> #<Addic7ed::Subtitle
#       @version="KILLERS,AVS",
#       @language="French"
#       @status="Completed"
#       @url="http://www.addic7ed.com/original/113643/4"
#       @source="http://sous-titres.eu"
#       @hi=false
#       @downloads=10335
#       @comment="works with 1080p.batv"
#   >

63
64
65
66
67
68
69
70
71
72
# File 'lib/addic7ed/models/subtitle.rb', line 63

def initialize(options = {})
  @version   = NormalizeVersion.call(options[:version])
  @language  = options[:language]
  @status    = options[:status]
  @url       = options[:url]
  @source    = options[:source]
  @hi        = options[:hi]
  @downloads = options[:downloads].to_i || 0
  @comment   = NormalizeComment.call(options[:comment])
end

Instance Attribute Details

#commentString

Comment manually added by the subtitle author/publisher (usually related to extra-compatibilities or resync source).


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

def comment
  @comment
end

#downloadsNumeric

Number of times this subtitle has been downloaded.


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

def downloads
  @downloads
end

#hiBoolean

Hearing-impaired support.


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

def hi
  @hi
end

#languageString

Language the subtitle is written in (e.g.: “French”, “English”).


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

def language
  @language
end

#sourceString

URL of website the subtitle was first published on.


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

def source
  @source
end

#statusString

Translation/synchronization advancement status (e.g.: “60%”“ or ”Completed“).


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

def status
  @status
end

#urlString

Download URL of actual subtitle file (warning: Addic7ed servers won't serve a subtite file without a proper Referer HTTP header which can be retrieved from episode.page_url).


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

def url
  @url
end

#versionString

Main compatible release group(s) (evenually as a comma-separated list).


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

def version
  @version
end

Instance Method Details

#completed?Boolean

Completeness status of the Addic7ed::Subtitle.

Examples:

Addic7ed::Subtitle.new(status: "50%").completed?       #=> false
Addic7ed::Subtitle.new(status: "Completed").completed? #=> true

105
106
107
# File 'lib/addic7ed/models/subtitle.rb', line 105

def completed?
  status == "Completed"
end

#to_sString

Returns a human-friendly readable string representing the Addic7ed::Subtitle

TODO: move to the CLI codebase

Examples:

Addic7ed::Subtitle.new(
  version:   "Version 720p AVS, 0.00 MBs",
  language:  "French",
  status:    "Completed",
  downloads: 42,
  url:       "http://www.addic7ed.com/original/113643/4"
).to_s
#=> "http://www.addic7ed.com/original/113643/4\t->\tAVS (French, Completed) [42 downloads]"

90
91
92
93
94
# File 'lib/addic7ed/models/subtitle.rb', line 90

def to_s
  str = "#{url}\t->\t#{version} (#{language}, #{status}) [#{downloads} downloads]"
  str += " (source #{source})" if source
  str
end