class SubtitleIt::Movie

Le Movie

Constants

CHUNK_SIZE

Attributes

filename[R]
info[RW]

Public Class Methods

new(filename) click to toggle source
# File lib/subtitle_it/movie.rb, line 11
def initialize(filename)
  @filename = filename
  @info = {}
end

Public Instance Methods

compute_haxx() click to toggle source
# File lib/subtitle_it/movie.rb, line 16
def compute_haxx
  filesize = File.size(@filename)
  out = filesize

  # Read 64 kbytes, divide up into 64 bits and add each
  # to hash. Do for beginning and end of file.
  File.open(filename, 'rb') do |f|
    # Q = unsigned long long = 64 bit
    f.read(CHUNK_SIZE).unpack('Q*').each do |n|
      out = out + n & 0xffffffffffffffff # to remain as 64 bit number
    end

    f.seek([0, filesize - CHUNK_SIZE].max, IO::SEEK_SET)

    # And again for the end of the file
    f.read(CHUNK_SIZE).unpack('Q*').each do |n|
      out = out + n & 0xffffffffffffffff
    end
  end

  sprintf('%016x', out)
end
haxx() click to toggle source
# File lib/subtitle_it/movie.rb, line 39
def haxx
  @haxx ||= compute_haxx
end
size() click to toggle source
# File lib/subtitle_it/movie.rb, line 43
def size
  @size ||= File.size(@filename)
end