class SubtitleIt::Subtitle

Le Subtitle pour le Movie

Attributes

download_count[R]
download_url[R]
filename[R]
format[R]
fps[W]
id[R]
info[R]
language[R]
lines[RW]
original_filename[R]
osdb_id[R]
rating[R]
raw[R]
release_name[R]
style[RW]
user[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/subtitle_it/subtitle.rb, line 34
def initialize(args = {})
  # Looks like opensubtitle is the only provider around..
  # If a second one comes need big refactor...
  if (@info = args[:info])
    # @osdb_info         = info
    @osdb_id           = @info['IDSubtitleFile'].to_s
    @original_filename = @info['SubFileName'].to_s
    @format            = @info['SubFormat'].to_s
    @user              = @info['UserNickName'].to_s
    @language          = @info['LanguageName'].to_s
    @release_name      = @info['MovieReleaseName'].to_s
    @download_count    = @info['SubDownloadsCnt'].to_i
    @rating            = @info['SubRating'].to_f
    @uploaded_at       = @info['SubAddDate'].to_s # TODO: convert to Date?
    @download_url      = @info['SubDownloadLink'].to_s
  end
  @fps = args[:fps] || 23.976
  return unless args[:dump]
  parse_dump(args[:dump], args[:format])
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/subtitle_it/subtitle.rb, line 59
def <=>(other)
  rating <=> other.rating
end
data=(data) click to toggle source
# File lib/subtitle_it/subtitle.rb, line 55
def data=(data)
  @raw = data
end

Private Instance Methods

encode_dump(dump) click to toggle source

Force subtitles to be UTF-8

# File lib/subtitle_it/subtitle.rb, line 66
def encode_dump(dump)
  dump = dump.read unless dump.is_a?(String)

  enc = CharlockHolmes::EncodingDetector.detect(dump)
  if enc[:encoding] != 'UTF-8'
    puts "Converting `#{enc[:encoding]}` to `UTF-8`".yellow
    dump = CharlockHolmes::Converter.convert dump, enc[:encoding], 'UTF-8'
  end
  dump
end
parse_dump(dump, format) click to toggle source
# File lib/subtitle_it/subtitle.rb, line 77
def parse_dump(dump, format)
  raise unless SUB_EXTS.include?(format)
  @raw = encode_dump(dump)
  @format = format
  parse_lines!
end
parse_lines!() click to toggle source
# File lib/subtitle_it/subtitle.rb, line 84
def parse_lines!
  self.lines = send :"parse_#{@format}"
end