Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP3: add suport to id3 v2.4.x #169

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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