mp3file 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b9ad0218bd03684169d8f12f4bbe90a47388ea4a
4
- data.tar.gz: 345deef9fcc2f91c5cdd0e233cc07973fdab9b49
2
+ SHA256:
3
+ metadata.gz: 02d2af45ba050fcd79a6ad1cf2a9293e881be810be1a2c89471d152aea8a1e4d
4
+ data.tar.gz: c4f1d11342e60b7c1ff8cc1a55a2f95f3e635c1f8898c0959e4a6d827e85140b
5
5
  SHA512:
6
- metadata.gz: 6c45bef09f17af0e2fa3f2d42329a1a3fc1267c123478182a680fc0ad696835892786f6e62464880c6f08387028fbdb7ad3ba87a14d68f58ca69c560a50a64c4
7
- data.tar.gz: 79c80620a99932962e312a0343b4e8c090ae3ded864201b32924b91fca302758bad64c292109829e5868853e7ac954d9d9c1b810930a7347702efffb16348728
6
+ metadata.gz: 46ac99a44bc6e04762683c2ee0f4f7b18f96d170a5e6cb7f1230d85041298e5de57997e101fe7a73bd020500e8c61292b3c391fba60ddeb59b82600d1a976c8b
7
+ data.tar.gz: e1de3df56fd73be4c2598827cf1669d00c9317c1f748a945cc87d26a6598c244506b694b1256207919853d343c50833ed4a941d7b7d955430015bef23b581620
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.6
4
- - 2.1.9
5
- - 2.1.10
6
- - 2.2.5
7
- - 2.3.1
3
+ - 2.3.5
4
+ - 2.3.6
5
+ - 2.4.3
6
+ - 2.5.0
@@ -118,6 +118,10 @@ module Mp3file
118
118
  @side_bytes = SIDE_BYTES[head.version][head.mode]
119
119
  end
120
120
 
121
+ def duration
122
+ @samples.to_f / @samplerate
123
+ end
124
+
121
125
  def to_i
122
126
  @raw.to_binary_s
123
127
  .reverse
@@ -1,3 +1,3 @@
1
1
  module Mp3file
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/mp3file.gemspec CHANGED
@@ -15,11 +15,11 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.rubyforge_project = "mp3file"
17
17
 
18
- s.add_development_dependency('rspec', '~> 2.0', '< 2.99')
18
+ s.add_development_dependency('rspec', '~> 3.0')
19
19
  s.add_development_dependency('rake')
20
20
  s.add_development_dependency('pry')
21
21
 
22
- s.add_dependency('bindata', '~> 2.3.0')
22
+ s.add_dependency('bindata', '~> 2.4.0')
23
23
 
24
24
  s.files = `git ls-files`.split("\n")
25
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -5,8 +5,8 @@ include CommonHelpers
5
5
 
6
6
  describe Mp3file::ID3v1Tag do
7
7
  it "rejects an ID3v1 tag if it doesn't begin with TAG" do
8
- lambda { Mp3file::ID3v1Tag.parse(StringIO.new("\x00" * 128)) }.
9
- should(raise_error(Mp3file::InvalidID3v1TagError))
8
+ expect { Mp3file::ID3v1Tag.parse(StringIO.new("\x00" * 128)) }.
9
+ to(raise_error(Mp3file::InvalidID3v1TagError))
10
10
  end
11
11
 
12
12
  describe "When created with a properly-formatted ID3v1 tag" do
@@ -20,13 +20,40 @@ describe Mp3file::ID3v1Tag do
20
20
  Mp3file::ID3v1Tag.parse(StringIO.new('TAG' + title + artist + album + year + comment + genre))
21
21
  end
22
22
 
23
- its(:title) { should == 'Big Dipper' }
24
- its(:artist) { should == 'Cracker' }
25
- its(:album) { should == 'The Golden Age' }
26
- its(:year) { should == '1996' }
27
- its(:comment) { should == 'This is a comment' }
28
- its(:track) { should == nil }
29
- its(:genre) { should == 'Rock' }
23
+ describe '#title' do
24
+ subject { super().title }
25
+ it { is_expected.to eq('Big Dipper') }
26
+ end
27
+
28
+ describe '#artist' do
29
+ subject { super().artist }
30
+ it { is_expected.to eq('Cracker') }
31
+ end
32
+
33
+ describe '#album' do
34
+ subject { super().album }
35
+ it { is_expected.to eq('The Golden Age') }
36
+ end
37
+
38
+ describe '#year' do
39
+ subject { super().year }
40
+ it { is_expected.to eq('1996') }
41
+ end
42
+
43
+ describe '#comment' do
44
+ subject { super().comment }
45
+ it { is_expected.to eq('This is a comment') }
46
+ end
47
+
48
+ describe '#track' do
49
+ subject { super().track }
50
+ it { is_expected.to eq(nil) }
51
+ end
52
+
53
+ describe '#genre' do
54
+ subject { super().genre }
55
+ it { is_expected.to eq('Rock') }
56
+ end
30
57
  end
31
58
 
32
59
  describe "When created with a properly-formatted ID3v1.1 tag" do
@@ -41,22 +68,73 @@ describe Mp3file::ID3v1Tag do
41
68
  Mp3file::ID3v1Tag.parse(StringIO.new('TAG' + title + artist + album + year + comment + tracknum + genre))
42
69
  end
43
70
 
44
- its(:title) { should == 'Big Dipper' }
45
- its(:artist) { should == 'Cracker' }
46
- its(:album) { should == 'The Golden Age' }
47
- its(:year) { should == '1996' }
48
- its(:comment) { should == 'This is a comment' }
49
- its(:track) { should == 3 }
50
- its(:genre) { should == 'Rock' }
71
+ describe '#title' do
72
+ subject { super().title }
73
+ it { is_expected.to eq('Big Dipper') }
74
+ end
75
+
76
+ describe '#artist' do
77
+ subject { super().artist }
78
+ it { is_expected.to eq('Cracker') }
79
+ end
80
+
81
+ describe '#album' do
82
+ subject { super().album }
83
+ it { is_expected.to eq('The Golden Age') }
84
+ end
85
+
86
+ describe '#year' do
87
+ subject { super().year }
88
+ it { is_expected.to eq('1996') }
89
+ end
90
+
91
+ describe '#comment' do
92
+ subject { super().comment }
93
+ it { is_expected.to eq('This is a comment') }
94
+ end
95
+
96
+ describe '#track' do
97
+ subject { super().track }
98
+ it { is_expected.to eq(3) }
99
+ end
100
+
101
+ describe '#genre' do
102
+ subject { super().genre }
103
+ it { is_expected.to eq('Rock') }
104
+ end
51
105
  end
52
106
 
53
107
  describe "When created with a blank ID3v1 tag" do
54
108
  subject { Mp3file::ID3v1Tag.parse(StringIO.new("TAG" + ("\x00" * 125))) }
55
- its(:title) { should == "" }
56
- its(:artist) { should == "" }
57
- its(:album) { should == "" }
58
- its(:comment) { should == "" }
59
- its(:track) { should == nil }
60
- its(:genre) { should == 'Blues' }
109
+
110
+ describe '#title' do
111
+ subject { super().title }
112
+ it { is_expected.to eq("") }
113
+ end
114
+
115
+ describe '#artist' do
116
+ subject { super().artist }
117
+ it { is_expected.to eq("") }
118
+ end
119
+
120
+ describe '#album' do
121
+ subject { super().album }
122
+ it { is_expected.to eq("") }
123
+ end
124
+
125
+ describe '#comment' do
126
+ subject { super().comment }
127
+ it { is_expected.to eq("") }
128
+ end
129
+
130
+ describe '#track' do
131
+ subject { super().track }
132
+ it { is_expected.to eq(nil) }
133
+ end
134
+
135
+ describe '#genre' do
136
+ subject { super().genre }
137
+ it { is_expected.to eq('Blues') }
138
+ end
61
139
  end
62
140
  end
@@ -3,55 +3,55 @@ require File.dirname(__FILE__) + '/../../../lib/mp3file'
3
3
  describe Mp3file::ID3v2::BitPaddedInt do
4
4
  describe ".unpad_number" do
5
5
  it "returns 0 when unpadding 0" do
6
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0).should == 0
6
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0)).to eq(0)
7
7
  end
8
8
 
9
9
  context "without specifying bits" do
10
10
  it "returns the least significant 7 bits of each byte in a 4-byte number" do
11
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0xFF_FF_FF_FF).
12
- should == 0x0F_FF_FF_FF
13
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0b0101_0101_0101_0101_0101_0101_0101_0101).
14
- should == 0b0000_1010_1011_0101_0110_1010_1101_0101
15
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0b1010_1010_1010_1010_1010_1010_1010_1010).
16
- should == 0b0000_0101_0100_1010_1001_0101_0010_1010
11
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0xFF_FF_FF_FF)).
12
+ to eq(0x0F_FF_FF_FF)
13
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0b0101_0101_0101_0101_0101_0101_0101_0101)).
14
+ to eq(0b0000_1010_1011_0101_0110_1010_1101_0101)
15
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0b1010_1010_1010_1010_1010_1010_1010_1010)).
16
+ to eq(0b0000_0101_0100_1010_1001_0101_0010_1010)
17
17
  end
18
18
  end
19
19
 
20
20
  context "specifying bits as n" do
21
21
  it "returns the least significant n bits from each byte of a 4-byte number" do
22
22
  1.upto(7) do |n|
23
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0xFF_FF_FF_FF, n).
24
- should == 16**n - 1
23
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0xFF_FF_FF_FF, n)).
24
+ to eq(16**n - 1)
25
25
  end
26
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0b0101_0101_0101_0101_0101_0101_0101_0101, 5).
27
- should == 0b1010_1101_0110_1011_0101
28
- Mp3file::ID3v2::BitPaddedInt.unpad_number(0b1010_1010_1010_1010_1010_1010_1010_1010, 3).
29
- should == 0b1001_001_0010
26
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0b0101_0101_0101_0101_0101_0101_0101_0101, 5)).
27
+ to eq(0b1010_1101_0110_1011_0101)
28
+ expect(Mp3file::ID3v2::BitPaddedInt.unpad_number(0b1010_1010_1010_1010_1010_1010_1010_1010, 3)).
29
+ to eq(0b1001_001_0010)
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
34
  describe ".pad_number" do
35
35
  it "returns 0 when padding 0" do
36
- Mp3file::ID3v2::BitPaddedInt.pad_number(0).should == 0
36
+ expect(Mp3file::ID3v2::BitPaddedInt.pad_number(0)).to eq(0)
37
37
  end
38
38
 
39
39
  context "without specifying bits" do
40
40
  it "keeps the least significant 28 bits of a 4-byte number and pads each byte with a 0" do
41
- Mp3file::ID3v2::BitPaddedInt.pad_number(0xFF_FF_FF_FF).
42
- should == 0x7F_7F_7F_7F
43
- Mp3file::ID3v2::BitPaddedInt.pad_number(0b0101_0101_0101_0101_0101_0101_0101_0101).
44
- should == 0b0010_1010_0101_0101_0010_1010_0101_0101
45
- Mp3file::ID3v2::BitPaddedInt.pad_number(0b1010_1010_1010_1010_1010_1010_1010_1010).
46
- should == 0b0101_0101_0010_1010_0101_0101_0010_1010
41
+ expect(Mp3file::ID3v2::BitPaddedInt.pad_number(0xFF_FF_FF_FF)).
42
+ to eq(0x7F_7F_7F_7F)
43
+ expect(Mp3file::ID3v2::BitPaddedInt.pad_number(0b0101_0101_0101_0101_0101_0101_0101_0101)).
44
+ to eq(0b0010_1010_0101_0101_0010_1010_0101_0101)
45
+ expect(Mp3file::ID3v2::BitPaddedInt.pad_number(0b1010_1010_1010_1010_1010_1010_1010_1010)).
46
+ to eq(0b0101_0101_0010_1010_0101_0101_0010_1010)
47
47
  end
48
48
  end
49
49
 
50
50
  context "specifying bits as n" do
51
51
  it "keeps the bottom n*4 bits and pads each byte with 0s" do
52
52
  1.upto(7) do |n|
53
- Mp3file::ID3v2::BitPaddedInt.pad_number(0xFF_FF_FF_FF, n).
54
- should == (2**n - 1)*(256**3 + 256**2 + 256**1 + 1)
53
+ expect(Mp3file::ID3v2::BitPaddedInt.pad_number(0xFF_FF_FF_FF, n)).
54
+ to eq((2**n - 1)*(256**3 + 256**2 + 256**1 + 1))
55
55
  end
56
56
  end
57
57
  end
@@ -9,18 +9,66 @@ describe Mp3file::ID3v2::FrameHeader do
9
9
 
10
10
  describe("A 15-byte long TT2 frame header.") do
11
11
  subject { Mp3file::ID3v2::FrameHeader.new(StringIO.new("TT2\x00\x00\x0f"), tag) }
12
- its(:frame_id) { should == 'TT2' }
13
- its(:size) { should == 21 }
14
- its(:frame_size) { should == 15 }
15
- its(:preserve_on_altered_tag) { should == false }
16
- its(:preserve_on_altered_file) { should == false }
17
- its(:read_only) { should == false }
18
- its(:compressed) { should == false }
19
- its(:encrypted) { should == false }
20
- its(:encryption_type) { should be_nil }
21
- its(:group) { should be_nil }
22
- its(:unsynchronized) { should == false }
23
- its(:data_length) { should == 0 }
12
+
13
+ describe '#frame_id' do
14
+ subject { super().frame_id }
15
+ it { is_expected.to eq('TT2') }
16
+ end
17
+
18
+ describe '#size' do
19
+ subject { super().size }
20
+ it { is_expected.to eq(21) }
21
+ end
22
+
23
+ describe '#frame_size' do
24
+ subject { super().frame_size }
25
+ it { is_expected.to eq(15) }
26
+ end
27
+
28
+ describe '#preserve_on_altered_tag' do
29
+ subject { super().preserve_on_altered_tag }
30
+ it { is_expected.to eq(false) }
31
+ end
32
+
33
+ describe '#preserve_on_altered_file' do
34
+ subject { super().preserve_on_altered_file }
35
+ it { is_expected.to eq(false) }
36
+ end
37
+
38
+ describe '#read_only' do
39
+ subject { super().read_only }
40
+ it { is_expected.to eq(false) }
41
+ end
42
+
43
+ describe '#compressed' do
44
+ subject { super().compressed }
45
+ it { is_expected.to eq(false) }
46
+ end
47
+
48
+ describe '#encrypted' do
49
+ subject { super().encrypted }
50
+ it { is_expected.to eq(false) }
51
+ end
52
+
53
+ describe '#encryption_type' do
54
+ subject { super().encryption_type }
55
+ it { is_expected.to be_nil }
56
+ end
57
+
58
+ describe '#group' do
59
+ subject { super().group }
60
+ it { is_expected.to be_nil }
61
+ end
62
+
63
+ describe '#unsynchronized' do
64
+ subject { super().unsynchronized }
65
+ it { is_expected.to eq(false) }
66
+ end
67
+
68
+ describe '#data_length' do
69
+ subject { super().data_length }
70
+ it { is_expected.to eq(0) }
71
+ end
24
72
  end
25
73
  end
26
74
 
@@ -37,34 +85,130 @@ describe Mp3file::ID3v2::FrameHeader do
37
85
 
38
86
  describe("A 9-byte TIT2 frame header.") do
39
87
  subject { Mp3file::ID3v2::FrameHeader.new(StringIO.new("TIT2\x00\x00\x00\x09\x00\x00"), tag) }
40
- its(:frame_id) { should == 'TIT2' }
41
- its(:size) { should == 19 }
42
- its(:frame_size) { should == 9 }
43
- its(:preserve_on_altered_tag) { should == false }
44
- its(:preserve_on_altered_file) { should == false }
45
- its(:read_only) { should == false }
46
- its(:compressed) { should == false }
47
- its(:encrypted) { should == false }
48
- its(:encryption_type) { should be_nil }
49
- its(:group) { should be_nil }
50
- its(:unsynchronized) { should == false }
51
- its(:data_length) { should == 0 }
88
+
89
+ describe '#frame_id' do
90
+ subject { super().frame_id }
91
+ it { is_expected.to eq('TIT2') }
92
+ end
93
+
94
+ describe '#size' do
95
+ subject { super().size }
96
+ it { is_expected.to eq(19) }
97
+ end
98
+
99
+ describe '#frame_size' do
100
+ subject { super().frame_size }
101
+ it { is_expected.to eq(9) }
102
+ end
103
+
104
+ describe '#preserve_on_altered_tag' do
105
+ subject { super().preserve_on_altered_tag }
106
+ it { is_expected.to eq(false) }
107
+ end
108
+
109
+ describe '#preserve_on_altered_file' do
110
+ subject { super().preserve_on_altered_file }
111
+ it { is_expected.to eq(false) }
112
+ end
113
+
114
+ describe '#read_only' do
115
+ subject { super().read_only }
116
+ it { is_expected.to eq(false) }
117
+ end
118
+
119
+ describe '#compressed' do
120
+ subject { super().compressed }
121
+ it { is_expected.to eq(false) }
122
+ end
123
+
124
+ describe '#encrypted' do
125
+ subject { super().encrypted }
126
+ it { is_expected.to eq(false) }
127
+ end
128
+
129
+ describe '#encryption_type' do
130
+ subject { super().encryption_type }
131
+ it { is_expected.to be_nil }
132
+ end
133
+
134
+ describe '#group' do
135
+ subject { super().group }
136
+ it { is_expected.to be_nil }
137
+ end
138
+
139
+ describe '#unsynchronized' do
140
+ subject { super().unsynchronized }
141
+ it { is_expected.to eq(false) }
142
+ end
143
+
144
+ describe '#data_length' do
145
+ subject { super().data_length }
146
+ it { is_expected.to eq(0) }
147
+ end
52
148
  end
53
149
 
54
150
  describe("A TIT2 header with all of its flags set") do
55
151
  subject { Mp3file::ID3v2::FrameHeader.new(StringIO.new("TIT2\x00\x00\x00\x09\x00\x00"), tag) }
56
- its(:frame_id) { should == 'TIT2' }
57
- its(:size) { should == 19 }
58
- its(:frame_size) { should == 9 }
59
- its(:preserve_on_altered_tag) { should == false }
60
- its(:preserve_on_altered_file) { should == false }
61
- its(:read_only) { should == false }
62
- its(:compressed) { should == false }
63
- its(:encrypted) { should == false }
64
- its(:encryption_type) { should be_nil }
65
- its(:group) { should be_nil }
66
- its(:unsynchronized) { should == false }
67
- its(:data_length) { should == 0 }
152
+
153
+ describe '#frame_id' do
154
+ subject { super().frame_id }
155
+ it { is_expected.to eq('TIT2') }
156
+ end
157
+
158
+ describe '#size' do
159
+ subject { super().size }
160
+ it { is_expected.to eq(19) }
161
+ end
162
+
163
+ describe '#frame_size' do
164
+ subject { super().frame_size }
165
+ it { is_expected.to eq(9) }
166
+ end
167
+
168
+ describe '#preserve_on_altered_tag' do
169
+ subject { super().preserve_on_altered_tag }
170
+ it { is_expected.to eq(false) }
171
+ end
172
+
173
+ describe '#preserve_on_altered_file' do
174
+ subject { super().preserve_on_altered_file }
175
+ it { is_expected.to eq(false) }
176
+ end
177
+
178
+ describe '#read_only' do
179
+ subject { super().read_only }
180
+ it { is_expected.to eq(false) }
181
+ end
182
+
183
+ describe '#compressed' do
184
+ subject { super().compressed }
185
+ it { is_expected.to eq(false) }
186
+ end
187
+
188
+ describe '#encrypted' do
189
+ subject { super().encrypted }
190
+ it { is_expected.to eq(false) }
191
+ end
192
+
193
+ describe '#encryption_type' do
194
+ subject { super().encryption_type }
195
+ it { is_expected.to be_nil }
196
+ end
197
+
198
+ describe '#group' do
199
+ subject { super().group }
200
+ it { is_expected.to be_nil }
201
+ end
202
+
203
+ describe '#unsynchronized' do
204
+ subject { super().unsynchronized }
205
+ it { is_expected.to eq(false) }
206
+ end
207
+
208
+ describe '#data_length' do
209
+ subject { super().data_length }
210
+ it { is_expected.to eq(0) }
211
+ end
68
212
  end
69
213
  end
70
214