Class: Mp3file::MP3File

Inherits:
Object
  • Object
show all
Defined in:
lib/mp3file/mp3_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ MP3File

Returns a new instance of MP3File.



14
15
16
17
# File 'lib/mp3file/mp3_file.rb', line 14

def initialize(file_path, options = {})
  file_path = Pathname.new(file_path).expand_path if file_path.is_a?(String)
  load_file(file_path, options)
end

Instance Attribute Details

#audio_sizeObject (readonly)

Returns the value of attribute audio_size.



5
6
7
# File 'lib/mp3file/mp3_file.rb', line 5

def audio_size
  @audio_size
end

#bitrateObject (readonly)

Returns the value of attribute bitrate.



9
10
11
# File 'lib/mp3file/mp3_file.rb', line 9

def bitrate
  @bitrate
end

#extra_id3v2_tagsObject

Returns the value of attribute extra_id3v2_tags.



12
13
14
# File 'lib/mp3file/mp3_file.rb', line 12

def extra_id3v2_tags
  @extra_id3v2_tags
end

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/mp3file/mp3_file.rb', line 5

def file
  @file
end

#file_sizeObject (readonly)

Returns the value of attribute file_size.



5
6
7
# File 'lib/mp3file/mp3_file.rb', line 5

def file_size
  @file_size
end

#first_headerObject (readonly)

Returns the value of attribute first_header.



6
7
8
# File 'lib/mp3file/mp3_file.rb', line 6

def first_header
  @first_header
end

#first_header_offsetObject (readonly)

Returns the value of attribute first_header_offset.



6
7
8
# File 'lib/mp3file/mp3_file.rb', line 6

def first_header_offset
  @first_header_offset
end

#id3v1_tagObject

Returns the value of attribute id3v1_tag.



12
13
14
# File 'lib/mp3file/mp3_file.rb', line 12

def id3v1_tag
  @id3v1_tag
end

#id3v2_tagObject

Returns the value of attribute id3v2_tag.



12
13
14
# File 'lib/mp3file/mp3_file.rb', line 12

def id3v2_tag
  @id3v2_tag
end

#layerObject (readonly)

Returns the value of attribute layer.



9
10
11
# File 'lib/mp3file/mp3_file.rb', line 9

def layer
  @layer
end

#lengthObject (readonly)

Returns the value of attribute length.



10
11
12
# File 'lib/mp3file/mp3_file.rb', line 10

def length
  @length
end

#modeObject (readonly)

Returns the value of attribute mode.



9
10
11
# File 'lib/mp3file/mp3_file.rb', line 9

def mode
  @mode
end

#mpeg_versionObject (readonly)

Returns the value of attribute mpeg_version.



9
10
11
# File 'lib/mp3file/mp3_file.rb', line 9

def mpeg_version
  @mpeg_version
end

#num_framesObject (readonly)

Returns the value of attribute num_frames.



10
11
12
# File 'lib/mp3file/mp3_file.rb', line 10

def num_frames
  @num_frames
end

#samplerateObject (readonly)

Returns the value of attribute samplerate.



9
10
11
# File 'lib/mp3file/mp3_file.rb', line 9

def samplerate
  @samplerate
end

#total_samplesObject (readonly)

Returns the value of attribute total_samples.



10
11
12
# File 'lib/mp3file/mp3_file.rb', line 10

def total_samples
  @total_samples
end

#vbri_headerObject (readonly)

Returns the value of attribute vbri_header.



8
9
10
# File 'lib/mp3file/mp3_file.rb', line 8

def vbri_header
  @vbri_header
end

#vbri_header_offsetObject (readonly)

Returns the value of attribute vbri_header_offset.



8
9
10
# File 'lib/mp3file/mp3_file.rb', line 8

def vbri_header_offset
  @vbri_header_offset
end

#xing_headerObject (readonly)

Returns the value of attribute xing_header.



7
8
9
# File 'lib/mp3file/mp3_file.rb', line 7

def xing_header
  @xing_header
end

#xing_header_offsetObject (readonly)

Returns the value of attribute xing_header_offset.



7
8
9
# File 'lib/mp3file/mp3_file.rb', line 7

def xing_header_offset
  @xing_header_offset
end

Instance Method Details

#albumObject



39
40
41
# File 'lib/mp3file/mp3_file.rb', line 39

def album
  value_from_tags(:album)
end

#artistObject



35
36
37
# File 'lib/mp3file/mp3_file.rb', line 35

def artist
  value_from_tags(:artist)
end

#commentObject



51
52
53
# File 'lib/mp3file/mp3_file.rb', line 51

def comment
  value_from_tags(:comment)
end

#each_headerObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/mp3file/mp3_file.rb', line 59

def each_header
  file = File.open(@file.path, "rb")
  offset = @first_header_offset

  file.seek(offset, IO::SEEK_SET)
  while !file.eof?
    header = MP3Header.new(file)
    yield offset, header

    offset = offset + header.frame_size
    file.seek(offset, IO::SEEK_SET)
  end

  file.close
end

#genreObject



55
56
57
# File 'lib/mp3file/mp3_file.rb', line 55

def genre
  value_from_tags(:genre)
end

#id3v1tag?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mp3file/mp3_file.rb', line 23

def id3v1tag?
  !@id3v1_tag.nil?
end

#id3v2tag?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/mp3file/mp3_file.rb', line 27

def id3v2tag?
  !@id3v2_tag.nil?
end

#titleObject



31
32
33
# File 'lib/mp3file/mp3_file.rb', line 31

def title
  value_from_tags(:title)
end

#trackObject



43
44
45
# File 'lib/mp3file/mp3_file.rb', line 43

def track
  value_from_tags(:track)
end

#vbr?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/mp3file/mp3_file.rb', line 19

def vbr?
  @vbr
end

#yearObject



47
48
49
# File 'lib/mp3file/mp3_file.rb', line 47

def year
  value_from_tags(:year)
end