Class: MKV::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/mkv/track.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Track

Returns a new instance of Track.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mkv/track.rb', line 12

def initialize(data)
  (@number, @mkv_info_id) = data.match(/track number:\s(\d+)\s\(track ID for mkvmerge & mkvextract: (\d+)\)/i)[1..2]
  @uid = data.match(/track uid: (\d+)/i)[1]
  @lacing = (data.match(/lacing flag: (\d+)/i) || [0, 0])[1] != '0'
  @type = data.match(/track type: (\w+)/i)[1]
  @codec_id = data.match(/codec id: (.*)/i)[1]

  if @type == 'video'
    @width = data.match(/pixel width: (\d+)/i)[1].to_i
    @height = data.match(/pixel height: (\d+)/i)[1].to_i
  end

  if @type == 'audio'
    @sampling_frequency = data.match(/sampling frequency: (\d+)/i)[1].to_i
    @channels = (data.match(/channels: (\d+)/i) || [nil, '2'])[1].to_i
  end

  if @type == 'audio' || @type == 'subtitles'
    @language = (data.match(/language: (\w+)/i) || [nil, 'eng'])[1]
    @enabled = (data.match(/enabled: (\d+)/i) || [0, 1])[1] != '0'
    @default = (data.match(/default flag: (\d+)/i) || [0, 0])[1] != '0'
    @forced = (data.match(/forced flag: (\d+)/i) || [0, 0])[1] != '0'
  end
end

Instance Attribute Details

#channelsObject (readonly)

Audio



8
9
10
# File 'lib/mkv/track.rb', line 8

def channels
  @channels
end

#codec_idObject (readonly)

Video, Audio & Subtitle



4
5
6
# File 'lib/mkv/track.rb', line 4

def codec_id
  @codec_id
end

#defaultObject (readonly)

Subtitle & Audio



10
11
12
# File 'lib/mkv/track.rb', line 10

def default
  @default
end

#enabledObject (readonly)

Subtitle & Audio



10
11
12
# File 'lib/mkv/track.rb', line 10

def enabled
  @enabled
end

#forcedObject (readonly)

Subtitle & Audio



10
11
12
# File 'lib/mkv/track.rb', line 10

def forced
  @forced
end

#heightObject (readonly)

Video



6
7
8
# File 'lib/mkv/track.rb', line 6

def height
  @height
end

#lacingObject (readonly)

Video, Audio & Subtitle



4
5
6
# File 'lib/mkv/track.rb', line 4

def lacing
  @lacing
end

#languageObject (readonly)

Subtitle & Audio



10
11
12
# File 'lib/mkv/track.rb', line 10

def language
  @language
end

#mkv_info_idObject (readonly)

Video, Audio & Subtitle



4
5
6
# File 'lib/mkv/track.rb', line 4

def mkv_info_id
  @mkv_info_id
end

#numberObject (readonly)

Video, Audio & Subtitle



4
5
6
# File 'lib/mkv/track.rb', line 4

def number
  @number
end

#sampling_frequencyObject (readonly)

Audio



8
9
10
# File 'lib/mkv/track.rb', line 8

def sampling_frequency
  @sampling_frequency
end

#typeObject (readonly)

Video, Audio & Subtitle



4
5
6
# File 'lib/mkv/track.rb', line 4

def type
  @type
end

#uidObject (readonly)

Video, Audio & Subtitle



4
5
6
# File 'lib/mkv/track.rb', line 4

def uid
  @uid
end

#widthObject (readonly)

Video



6
7
8
# File 'lib/mkv/track.rb', line 6

def width
  @width
end

Instance Method Details

#is_audio?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/mkv/track.rb', line 41

def is_audio?
  @type == 'audio'
end

#is_subtitle?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/mkv/track.rb', line 45

def is_subtitle?
  !(@type =~ /subtitles?/).nil?
end

#is_video?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mkv/track.rb', line 37

def is_video?
  @type == 'video'
end