Skip to content

Commit

Permalink
Merge pull request #49 from scouttyg/scott/more-wahwah-parse-fixes
Browse files Browse the repository at this point in the history
Adding a few more parsing fixes for various M4A and MP3 file types
  • Loading branch information
aidewoode authored Aug 14, 2024
2 parents 8c8b5b2 + 1249064 commit 990de38
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/wahwah/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def self.file_format_from_signature(io)
# M4A is checked for first, since MP4 files start with a chunk size -
# and that chunk size may incidentally match another signature.
# No other formats would reasonably have "ftyp" as the next for bytes.
return "m4a" if ["ftypM4A ".b, "ftyp3gp4".b].include?(signature[4...12])
return "m4a" if ["ftypM4A ".b, "ftyp3gp4".b, "ftypmp42".b].include?(signature[4...12])
# Handled separately simply because it requires two checks.
return "wav" if signature.start_with?("RIFF".b) && signature[8...12] == "WAVE".b
magic_numbers = {
Expand Down
3 changes: 2 additions & 1 deletion lib/wahwah/mp3_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def parse
def parse_id3_tag
@file_io.rewind
signature = @file_io.read(6)
@file_io.rewind

if signature.start_with?("ID3".b)
id3_v2_tag = ID3::V2.new(@file_io)
Expand All @@ -72,7 +73,7 @@ def parse_duration
@bitrate = (bytes_count * 8 / @duration / 1000).round unless @duration.zero?
else
@bitrate = mpeg_frame_header.frame_bitrate
@duration = (file_size - (@id3_tag&.size || 0)) * 8 / (@bitrate * 1000).to_f unless @bitrate.zero?
@duration = (file_size - (@id3_tag&.size || 0)) * 8 / (@bitrate * 1000).to_f unless @bitrate.to_i.zero?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/wahwah/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module WahWah
VERSION = "1.6.5"
VERSION = "1.6.6"
end

0 comments on commit 990de38

Please sign in to comment.