Skip to content

Commit

Permalink
MP3: add suport to id3 v2.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioperrella committed Sep 30, 2020
1 parent efdc1a9 commit f993e0e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/parsers/mp3_parser/id3_extraction.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module FormatParser::MP3Parser::ID3Extraction
ID3V1_TAG_SIZE_BYTES = 128
ID3V2_TAG_VERSIONS = ["\x03\x00".b, "\x02\x00".b]
# it supports 2.4.x, 2.3.x, 2.2.x which are supported by the gem id3tag
# see https://id3.org/Developer%20Information for more details of each version
ID3V2_MINOR_TAG_VERSIONS = [2, 3, 4]
MAX_SIZE_FOR_ID3V2 = 1 * 1024 * 1024

extend FormatParser::IOUtils
Expand All @@ -22,7 +24,7 @@ def attempt_id3_v2_extraction(io)
io.seek(0) # Only support header ID3v2
header = parse_id3_v2_header(io)
return unless header[:tag] == 'ID3' && header[:size] > 0
return unless ID3V2_TAG_VERSIONS.include?(header[:version])
return unless ID3V2_MINOR_TAG_VERSIONS.include?(header[:version].unpack('C').first)

id3_tag_size = io.pos + header[:size]

Expand Down
Binary file added spec/fixtures/MP3/id3v24.mp3
Binary file not shown.
8 changes: 8 additions & 0 deletions spec/parsers/mp3_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@
}.to raise_error(FormatParser::IOUtils::InvalidRead)
end

it 'supports id3 v2.4.x' do
fpath = fixtures_dir + '/MP3/id3v24.mp3'

parsed = subject.call(File.open(fpath, 'rb'))

expect(parsed.artist). to eq('wetransfer')
end

describe '#as_json' do
it 'converts all hash keys to string when stringify_keys: true' do
fpath = fixtures_dir + '/MP3/Cassy.mp3'
Expand Down

0 comments on commit f993e0e

Please sign in to comment.