Class: SubsReader

Inherits:
Object
  • Object
show all
Includes:
Patterns
Defined in:
lib/subtitle-library/reader.rb

Constant Summary

Constants included from Patterns

Patterns::MICRO_DVD_LINE, Patterns::SUBVIEWER_LINE, Patterns::SUBVIEWER_METADATA, Patterns::SUB_RIP_LINE, Patterns::SUB_RIP_TIMING

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subs_path) ⇒ SubsReader

Returns a new instance of SubsReader.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/subtitle-library/reader.rb', line 9

def initialize(subs_path)
  @subs_path = subs_path
  @type = recognize
  case @type
    when 'sr'
      @inner_reader = SubRipReader.new subs_path
    when 'md'
      @inner_reader = MicroDVDReader.new subs_path
    when 'sv'
      @inner_reader = SubviewerReader.new subs_path
  end
  @fps = 23.976
end

Instance Attribute Details

#cuesObject

Returns the value of attribute cues.



7
8
9
# File 'lib/subtitle-library/reader.rb', line 7

def cues
  @cues
end

#fpsObject (readonly)

Returns the value of attribute fps.



6
7
8
# File 'lib/subtitle-library/reader.rb', line 6

def fps
  @fps
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/subtitle-library/reader.rb', line 6

def type
  @type
end

Instance Method Details

#check_syntaxObject



42
43
44
45
46
47
48
# File 'lib/subtitle-library/reader.rb', line 42

def check_syntax
  if @inner_reader
    @inner_reader.read_subs true
  else
    'Unknown file format'
  end
end

#load_cuesObject



34
35
36
37
38
39
40
# File 'lib/subtitle-library/reader.rb', line 34

def load_cues
  if @inner_reader
    @cues, @fps = @inner_reader.read_subs false
  else
    'Unknown file format'
  end
end

#recognizeObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/subtitle-library/reader.rb', line 23

def recognize
  File.open(@subs_path, 'r') do |subs|
    while line = subs.gets
      return 'sr' if SUB_RIP_LINE =~ line
      return 'md' if MICRO_DVD_LINE =~ line
      return 'sv' if SUBVIEWER_LINE =~ line
    end
  end
  'uk'
end