format_parser 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/format_parser.gemspec +1 -1
- data/lib/audio.rb +9 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/parsers/mp3_parser.rb +19 -1
- data/spec/parsers/mp3_parser_spec.rb +24 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b54b8e7c496c5d1e732503678bc762993bf53e9a
|
4
|
+
data.tar.gz: ca7ce92f31f08a049b7475746e2017e6662b331a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3dcc4792c6097dc701beb1b124ae17ad345305b4e7e4ac46a132646ff2aefea13cdc350087f8582b9b2653b75181c6c00ffb12d6a5180716538a732cfe60c46
|
7
|
+
data.tar.gz: 898ea93a39709415452b5256fdcee7acb69d9a1decc14c50b52695990ae399848c3f984787ab7374efb9b04b3bb758f0487a4b9da67c7fa83396ab5a5c114218
|
data/format_parser.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
|
-
spec.add_dependency 'ks', '~> 0.0
|
33
|
+
spec.add_dependency 'ks', '~> 0.0'
|
34
34
|
spec.add_dependency 'exifr', '~> 1.0'
|
35
35
|
spec.add_dependency 'id3tag', '~> 0.10', '>= 0.10.1'
|
36
36
|
spec.add_dependency 'faraday', '~> 0.13'
|
data/lib/audio.rb
CHANGED
@@ -4,6 +4,15 @@ module FormatParser
|
|
4
4
|
|
5
5
|
NATURE = :audio
|
6
6
|
|
7
|
+
# Title of the audio
|
8
|
+
attr_accessor :title
|
9
|
+
|
10
|
+
# Album of the audio
|
11
|
+
attr_accessor :album
|
12
|
+
|
13
|
+
# Artist of the audio
|
14
|
+
attr_accessor :artist
|
15
|
+
|
7
16
|
# Type of the file (e.g :mp3)
|
8
17
|
attr_accessor :format
|
9
18
|
|
data/lib/parsers/mp3_parser.rb
CHANGED
@@ -81,6 +81,8 @@ class FormatParser::MP3Parser
|
|
81
81
|
|
82
82
|
first_frame = initial_frames.first
|
83
83
|
|
84
|
+
id3tags_hash = blend_id3_tags_into_hash(*tags)
|
85
|
+
|
84
86
|
file_info = FormatParser::Audio.new(
|
85
87
|
format: :mp3,
|
86
88
|
# media_duration_frames is omitted because the frames
|
@@ -88,9 +90,15 @@ class FormatParser::MP3Parser
|
|
88
90
|
# do not tell anything of substance
|
89
91
|
num_audio_channels: first_frame.channels,
|
90
92
|
audio_sample_rate_hz: first_frame.sample_rate,
|
91
|
-
intrinsics:
|
93
|
+
intrinsics: id3tags_hash.merge(id3tags: tags)
|
92
94
|
)
|
93
95
|
|
96
|
+
extra_file_attirbutes = fetch_extra_attributes_from_id3_tags(id3tags_hash)
|
97
|
+
|
98
|
+
extra_file_attirbutes.each do |name, value|
|
99
|
+
file_info.send(:"#{name}=", value)
|
100
|
+
end
|
101
|
+
|
94
102
|
if maybe_xing_header
|
95
103
|
duration = maybe_xing_header.frames * SAMPLES_PER_FRAME / first_frame.sample_rate.to_f
|
96
104
|
_bit_rate = maybe_xing_header.byte_count * 8 / duration / 1000
|
@@ -275,5 +283,15 @@ class FormatParser::MP3Parser
|
|
275
283
|
end
|
276
284
|
end
|
277
285
|
|
286
|
+
def fetch_extra_attributes_from_id3_tags(id3tags_hash)
|
287
|
+
attrs = {}
|
288
|
+
|
289
|
+
attrs[:title] = FormatParser.string_to_lossy_utf8(id3tags_hash[:title]) unless id3tags_hash[:title].to_s.empty?
|
290
|
+
attrs[:album] = FormatParser.string_to_lossy_utf8(id3tags_hash[:album]) unless id3tags_hash[:album].to_s.empty?
|
291
|
+
attrs[:artist] = FormatParser.string_to_lossy_utf8(id3tags_hash[:artist]) unless id3tags_hash[:artist].to_s.empty?
|
292
|
+
|
293
|
+
attrs
|
294
|
+
end
|
295
|
+
|
278
296
|
FormatParser.register_parser self, natures: :audio, formats: :mp3, priority: 99
|
279
297
|
end
|
@@ -15,6 +15,30 @@ describe FormatParser::MP3Parser do
|
|
15
15
|
expect(parsed.media_duration_seconds).to be_within(0.1).of(0.836)
|
16
16
|
end
|
17
17
|
|
18
|
+
describe 'title/artist/album attributes' do
|
19
|
+
let(:parsed) { subject.call(File.open(fpath, 'rb')) }
|
20
|
+
|
21
|
+
context 'when exist in id3 tags' do
|
22
|
+
let(:fpath) { fixtures_dir + '/MP3/Cassy.mp3' }
|
23
|
+
|
24
|
+
it 'set the attributes' do
|
25
|
+
expect(parsed.artist).to eq('WeTransfer Studios/GIlles Peterson')
|
26
|
+
expect(parsed.title).to eq('Cassy')
|
27
|
+
expect(parsed.album).to eq('The Psychology of DJing')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when do not exist in id3 tags' do
|
32
|
+
let(:fpath) { fixtures_dir + '/MP3/atc_fixture_vbr.mp3' }
|
33
|
+
|
34
|
+
it 'set attributes with nil' do
|
35
|
+
expect(parsed.title).to be_nil
|
36
|
+
expect(parsed.artist).to be_nil
|
37
|
+
expect(parsed.album).to be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
18
42
|
it 'decodes and estimates duration for a CBR MP3' do
|
19
43
|
fpath = fixtures_dir + '/MP3/atc_fixture_cbr.mp3'
|
20
44
|
parsed = subject.call(File.open(fpath, 'rb'))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Berman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.0
|
20
|
+
version: '0.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.0
|
27
|
+
version: '0.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: exifr
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
284
|
version: '0'
|
285
285
|
requirements: []
|
286
286
|
rubyforge_project:
|
287
|
-
rubygems_version: 2.
|
287
|
+
rubygems_version: 2.6.11
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: A library for efficient parsing of file metadata
|