Class: ID3Tag::AudioFile
- Inherits:
-
Object
- Object
- ID3Tag::AudioFile
- Defined in:
- lib/id3tag/audio_file.rb
Constant Summary collapse
- ID3V1_TAG_SIZE =
128
- ID3V2_TAG_HEADER_SIZE =
10
- IDV1_TAG_IDENTIFIER =
"TAG"
- IDV2_TAG_IDENTIFIER =
"ID3"
- BLANK_STRING =
""
Instance Method Summary collapse
-
#initialize(file) ⇒ AudioFile
constructor
A new instance of AudioFile.
- #v1_tag_body ⇒ Object
- #v1_tag_present? ⇒ Boolean
- #v1_tag_size ⇒ Object
- #v2_tag_body ⇒ Object
- #v2_tag_major_version_number ⇒ Object
- #v2_tag_minor_version_number ⇒ Object
- #v2_tag_present? ⇒ Boolean
- #v2_tag_size ⇒ Object
- #v2_tag_version ⇒ Object
Constructor Details
#initialize(file) ⇒ AudioFile
Returns a new instance of AudioFile.
9 10 11 |
# File 'lib/id3tag/audio_file.rb', line 9 def initialize(file) @file = file end |
Instance Method Details
#v1_tag_body ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/id3tag/audio_file.rb', line 27 def v1_tag_body if v1_tag_present? @file.seek(-v1_tag_size, IO::SEEK_END) @file.read(v1_tag_size) else nil end end |
#v1_tag_present? ⇒ Boolean
13 14 15 16 17 18 19 20 |
# File 'lib/id3tag/audio_file.rb', line 13 def v1_tag_present? if @file.size >= ID3V1_TAG_SIZE @file.seek(-ID3V1_TAG_SIZE, IO::SEEK_END) @file.read(3) == IDV1_TAG_IDENTIFIER else false end end |
#v1_tag_size ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/id3tag/audio_file.rb', line 36 def v1_tag_size if v1_tag_present? ID3V1_TAG_SIZE - IDV1_TAG_IDENTIFIER.size else 0 end end |
#v2_tag_body ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/id3tag/audio_file.rb', line 44 def v2_tag_body if v2_tag_size > 0 @file.seek(v2_tag_frame_and_padding_position) bytes_to_read = v2_tag_frame_and_padding_size return BLANK_STRING if bytes_to_read < 0 limit = ID3Tag.configuration.v2_tag_read_limit if (limit > 0) && (bytes_to_read > limit) bytes_to_read = limit end @file.read(bytes_to_read) || BLANK_STRING end end |
#v2_tag_major_version_number ⇒ Object
69 70 71 |
# File 'lib/id3tag/audio_file.rb', line 69 def v2_tag_major_version_number v2_tag_header.major_version_number end |
#v2_tag_minor_version_number ⇒ Object
73 74 75 |
# File 'lib/id3tag/audio_file.rb', line 73 def v2_tag_minor_version_number v2_tag_header.minor_version_number end |
#v2_tag_present? ⇒ Boolean
22 23 24 25 |
# File 'lib/id3tag/audio_file.rb', line 22 def v2_tag_present? @file.seek(0) @file.read(3) == IDV2_TAG_IDENTIFIER end |
#v2_tag_size ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/id3tag/audio_file.rb', line 57 def v2_tag_size if v2_tag_present? v2_tag_header.tag_size else 0 end end |
#v2_tag_version ⇒ Object
65 66 67 |
# File 'lib/id3tag/audio_file.rb', line 65 def v2_tag_version v2_tag_header.version_number end |