Class: FramyMP3::File
- Inherits:
-
Object
- Object
- FramyMP3::File
- Defined in:
- lib/framy_mp3/file.rb
Instance Attribute Summary collapse
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #id3v1_tag ⇒ Object
- #id3v2_tag ⇒ Object
-
#initialize(stream) ⇒ File
constructor
A new instance of File.
- #to_blob(options = {}) ⇒ Object (also: #to_s)
- #total_frame_bytes ⇒ Object
- #total_frames ⇒ Object
- #variable_bitrate? ⇒ Boolean (also: #vbr?)
Constructor Details
#initialize(stream) ⇒ File
Returns a new instance of File.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/framy_mp3/file.rb', line 8 def initialize(stream) @stream = stream @frames = [] @tags = [] while (object = next_object) frames << object if object.frame? << object if object.tag? end end |
Instance Attribute Details
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
6 7 8 |
# File 'lib/framy_mp3/file.rb', line 6 def frames @frames end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
6 7 8 |
# File 'lib/framy_mp3/file.rb', line 6 def @tags end |
Instance Method Details
#id3v1_tag ⇒ Object
51 52 53 |
# File 'lib/framy_mp3/file.rb', line 51 def id3v1_tag .find(&:v1?) end |
#id3v2_tag ⇒ Object
47 48 49 |
# File 'lib/framy_mp3/file.rb', line 47 def id3v2_tag .find(&:v2?) end |
#to_blob(options = {}) ⇒ Object Also known as: to_s
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/framy_mp3/file.rb', line 19 def to_blob(={}) blob = "" keep_xing_headers = vbr? ? false : .fetch(:keep_xing_headers, false) StringIO.open(blob, "wb") do |outfile| initial_tag = id3v2_tag outfile << initial_tag.data unless initial_tag.nil? outfile << xing_header.data unless keep_xing_headers (keep_xing_headers ? frames : frames.reject(&:xing_header?)).each do |frame| outfile << frame.data end closing_tag = id3v1_tag outfile << closing_tag.data unless closing_tag.nil? end blob end |
#total_frame_bytes ⇒ Object
59 60 61 |
# File 'lib/framy_mp3/file.rb', line 59 def total_frame_bytes frames.map { |frame| frame.data.bytesize }.sum end |
#total_frames ⇒ Object
55 56 57 |
# File 'lib/framy_mp3/file.rb', line 55 def total_frames frames.count end |
#variable_bitrate? ⇒ Boolean Also known as: vbr?
39 40 41 42 43 44 |
# File 'lib/framy_mp3/file.rb', line 39 def variable_bitrate? initial_bitrate = frames.first.bitrate frames[1..-1].any? do |frame| frame.bitrate != initial_bitrate end end |