discid 1.0.0 → 1.1.0
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 +6 -14
- data/.travis.yml +4 -3
- data/CHANGES +3 -0
- data/README.md +6 -2
- data/Rakefile +2 -2
- data/discid.gemspec +6 -0
- data/examples/discidinfo.rb +2 -2
- data/examples/readdiscid.rb +3 -3
- data/lib/discid.rb +9 -9
- data/lib/discid/disc.rb +21 -24
- data/lib/discid/disc_error.rb +20 -0
- data/lib/discid/lib.rb +5 -5
- data/lib/discid/track.rb +17 -17
- data/lib/discid/version.rb +1 -1
- data/test/helper.rb +23 -0
- data/test/test_disc.rb +6 -5
- data/test/test_discid.rb +20 -18
- data/test/test_track.rb +3 -2
- metadata +49 -18
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZWI2ZTdjOTNlOTIyMzk5NDNhZDVjOGFmNjk4MTg4ZDVmYWVhNzBmNTQ0ZjI3
|
10
|
-
MmM2YWNlZDI3NmZiOTVmNzU1NTk0NGM0YTkwMjAyOWFiNWNiOTY0ZDgyMTYw
|
11
|
-
MDQ3ODEyMGVlZDBjYmZiYmFjZTc0N2ZmYzZjYTRhZGE0M2MzNTQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDUxZmJkOGQ4NTA3ZTdiYjk4Yjg4YjFhOTZkNTBhOThhMDA4NTE5NzE2YzYy
|
14
|
-
NDM3NjBlZmZmYzQ5MTUxZmE1NDVlMGYzNmZjMDFiMzgxZTY1YzVmYjEyZmM0
|
15
|
-
MjA4ZDljY2Y1NmYzNzg0OWQ1ZDkxNTQxNDJlMzJjNWExMWMzYTY=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 811b73ec96d4fecd54e6a73741b30c62cf9b8252
|
4
|
+
data.tar.gz: 82dc97ff4580f1679337a5ef48074c6c8320e23a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 822fcd13bd24be44fe7c84eec02c1a4030ef3537c353f376e156ced43eb4f4081283b72879cc13fadbdafc7d82ccffef85de536e6af6b65c3c37dd652f6b8a07
|
7
|
+
data.tar.gz: 10b05970fdc3983ea6d8dd2841eb49a5cbeb411f445e89b1b1170f958ef19267730ce082494466a4e7a2a245fa5ff7d1e222404279c7e495370d77163c21997c
|
data/.travis.yml
CHANGED
@@ -3,11 +3,12 @@ rvm:
|
|
3
3
|
- 1.8.7
|
4
4
|
- 1.9.3
|
5
5
|
- 2.0.0
|
6
|
+
- 2.1.0
|
7
|
+
- 2.2.3
|
6
8
|
- jruby-18mode # JRuby in 1.8 mode
|
7
9
|
- jruby-19mode # JRuby in 1.9 mode
|
8
|
-
- rbx-
|
9
|
-
- rbx-19mode
|
10
|
+
- rbx-2
|
10
11
|
before_install:
|
11
12
|
- sudo apt-get update -qq
|
12
13
|
- sudo apt-get install -qq libdiscid0
|
13
|
-
script: bundle exec rake test
|
14
|
+
script: CODECLIMATE_REPO_TOKEN=40f40f3d9e79b5e7051d7564172541932d6799ba585a5ada684695c0fb3e5e5e bundle exec rake test
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# Ruby bindings for MusicBrainz libdiscid
|
2
|
+
[](https://travis-ci.org/phw/ruby-discid)
|
3
|
+
[](https://codeclimate.com/github/phw/ruby-discid)
|
4
|
+
[](https://codeclimate.com/github/phw/ruby-discid)
|
5
|
+
[](http://badge.fury.io/rb/discid)
|
2
6
|
|
3
7
|
## About
|
4
8
|
ruby-discid provides Ruby bindings for the MusicBrainz DiscID library libdiscid.
|
@@ -63,7 +67,7 @@ and Kramdown). `rake install` will build the discid gem and install it.
|
|
63
67
|
puts " ISRC : %s" % track.isrc
|
64
68
|
end
|
65
69
|
|
66
|
-
See the [API documentation](http://rubydoc.info/github/phw/ruby-discid/master
|
70
|
+
See the [API documentation](http://www.rubydoc.info/github/phw/ruby-discid/master)
|
67
71
|
of {DiscId} or the files in the `examples` directory for more usage information.
|
68
72
|
|
69
73
|
## Contribute
|
@@ -75,4 +79,4 @@ Please report any issues on the
|
|
75
79
|
|
76
80
|
## License
|
77
81
|
ruby-discid is released under the GNU Lesser General Public License Version 3.
|
78
|
-
See LICENSE for details.
|
82
|
+
See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -5,9 +5,9 @@ require 'yard'
|
|
5
5
|
desc "Run just the unit tests"
|
6
6
|
Rake::TestTask.new(:test) do |test|
|
7
7
|
test.test_files = FileList['test/test*.rb']
|
8
|
-
test.libs = ['lib', '
|
8
|
+
test.libs = ['lib', 'test']
|
9
9
|
test.warning = true
|
10
10
|
end
|
11
11
|
|
12
12
|
YARD::Rake::YardocTask.new do |t|
|
13
|
-
end
|
13
|
+
end
|
data/discid.gemspec
CHANGED
@@ -29,4 +29,10 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "rake"
|
30
30
|
spec.add_development_dependency "yard"
|
31
31
|
spec.add_development_dependency "kramdown"
|
32
|
+
spec.add_development_dependency "test-unit"
|
33
|
+
|
34
|
+
# The code coverage is only supported for Ruby >= 1.9
|
35
|
+
if (RUBY_VERSION.split('.').map{|s|s.to_i} <=> [1, 9, 0]) >= 0
|
36
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
37
|
+
end
|
32
38
|
end
|
data/examples/discidinfo.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# Example script for DiscId.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This script will read the disc ID from the default device and print
|
6
6
|
# the results. You can specify an alternate device to use by giving the
|
7
7
|
# device's name as the first command line argument.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Example:
|
10
10
|
# ./discid.rb /dev/dvd
|
11
11
|
|
data/examples/readdiscid.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# Example script for DiscId.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# This script will read the disc ID from the default device and print
|
6
6
|
# the results. You can specify an alternate device to use by giving the
|
7
7
|
# device's name as the first command line argument.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Example:
|
10
10
|
# ./discid.rb /dev/dvd
|
11
11
|
|
@@ -23,7 +23,7 @@ device = $*[0] ? $*[0] : DiscId.default_device
|
|
23
23
|
puts "Reading TOC from device '#{device}'."
|
24
24
|
begin
|
25
25
|
disc = DiscId.read(device, :isrc, :mcn)
|
26
|
-
|
26
|
+
|
27
27
|
# Instead of reading from a device we could set the TOC directly:
|
28
28
|
#disc = DiscId.put(1, 82255, [150, 16157, 35932, 57527])
|
29
29
|
rescue DiscId::DiscError => e
|
data/lib/discid.rb
CHANGED
@@ -34,10 +34,10 @@ require 'discid/version'
|
|
34
34
|
#
|
35
35
|
# @example Read the TOC, MCN and ISRCs
|
36
36
|
# require 'discid'
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# device = "/dev/cdrom"
|
39
39
|
# disc = DiscId.read(device, :mcn, :isrc)
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# # Print information about the disc:
|
42
42
|
# puts "DiscID : #{disc.id}"
|
43
43
|
# puts "FreeDB ID : #{disc.freedb_id}"
|
@@ -76,7 +76,7 @@ module DiscId
|
|
76
76
|
# This function will always read the TOC, but additional features like `:mcn`
|
77
77
|
# and `:isrc` can be set using the features parameter. You can set multiple
|
78
78
|
# features.
|
79
|
-
#
|
79
|
+
#
|
80
80
|
# @example Read only the TOC:
|
81
81
|
# disc = DiscId.read(device)
|
82
82
|
#
|
@@ -101,11 +101,11 @@ module DiscId
|
|
101
101
|
disc.read device, *features
|
102
102
|
return disc
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
# Provides the TOC of a known CD.
|
106
106
|
#
|
107
107
|
# This function may be used if the TOC has been read earlier and you want to
|
108
|
-
# calculate the disc ID afterwards, without accessing the disc drive.
|
108
|
+
# calculate the disc ID afterwards, without accessing the disc drive.
|
109
109
|
#
|
110
110
|
# @raise [DiscError] The TOC could not be set. `Exception#message`contains
|
111
111
|
# error details.
|
@@ -119,7 +119,7 @@ module DiscId
|
|
119
119
|
disc.put first_track, sectors, offsets
|
120
120
|
return disc
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
# Return the name of the default disc drive for this operating system.
|
124
124
|
#
|
125
125
|
# @return [String] An operating system dependent device identifier
|
@@ -142,9 +142,9 @@ module DiscId
|
|
142
142
|
end
|
143
143
|
|
144
144
|
# A list of features supported by the current platform.
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# Currently the following features are available:
|
147
|
-
#
|
147
|
+
#
|
148
148
|
# * :read
|
149
149
|
# * :mcn
|
150
150
|
# * :isrc
|
@@ -157,7 +157,7 @@ module DiscId
|
|
157
157
|
end
|
158
158
|
|
159
159
|
# Converts sectors to seconds.
|
160
|
-
#
|
160
|
+
#
|
161
161
|
# According to the red book standard 75 sectors are one second.
|
162
162
|
#
|
163
163
|
# @private
|
data/lib/discid/disc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Philipp Wolfer
|
1
|
+
# Copyright (C) 2013-2014 Philipp Wolfer
|
2
2
|
#
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU Lesser General Public License as published by
|
@@ -14,6 +14,7 @@
|
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
16
|
require 'ffi'
|
17
|
+
require 'discid/disc_error'
|
17
18
|
require 'discid/lib'
|
18
19
|
require 'discid/track'
|
19
20
|
|
@@ -38,11 +39,11 @@ module DiscId
|
|
38
39
|
def read(device, *features)
|
39
40
|
@read = false
|
40
41
|
device = DiscId.default_device if device.nil?
|
41
|
-
|
42
|
+
|
42
43
|
if not device.respond_to? :to_s
|
43
44
|
raise TypeError, 'wrong argument type (expected String)'
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
@device = device.to_s
|
47
48
|
flags = Lib.features_to_int features
|
48
49
|
result = Lib.read @handle, @device, flags
|
@@ -58,13 +59,13 @@ module DiscId
|
|
58
59
|
def put(first_track, sectors, offsets)
|
59
60
|
@read = false
|
60
61
|
@device = nil
|
61
|
-
last_track = offsets.length
|
62
|
-
|
62
|
+
last_track = offsets.length
|
63
|
+
|
63
64
|
# discid_put expects always an offsets array with exactly 100 elements.
|
64
65
|
FFI::MemoryPointer.new(:int, 100) do |p|
|
65
66
|
p.write_array_of_int([sectors] + offsets)
|
66
67
|
result = Lib.put @handle, first_track, last_track, p
|
67
|
-
|
68
|
+
|
68
69
|
if result == 0
|
69
70
|
raise DiscError, Lib.get_error_msg(@handle)
|
70
71
|
else
|
@@ -86,31 +87,31 @@ module DiscId
|
|
86
87
|
def freedb_id
|
87
88
|
return Lib.get_freedb_id @handle if @read
|
88
89
|
end
|
89
|
-
|
90
|
+
|
90
91
|
# The number of the first track on this disc.
|
91
|
-
#
|
92
|
-
# @return [Integer] The number of the first track or `nil` if no ID was yet read.
|
92
|
+
#
|
93
|
+
# @return [Integer] The number of the first track or `nil` if no ID was yet read.
|
93
94
|
def first_track_number
|
94
95
|
return Lib.get_first_track_num @handle if @read
|
95
96
|
end
|
96
97
|
|
97
98
|
# The number of the last track on this disc.
|
98
|
-
#
|
99
|
-
# @return [Integer] The number of the last track or `nil` if no ID was yet read.
|
99
|
+
#
|
100
|
+
# @return [Integer] The number of the last track or `nil` if no ID was yet read.
|
100
101
|
def last_track_number
|
101
102
|
return Lib.get_last_track_num @handle if @read
|
102
103
|
end
|
103
104
|
|
104
105
|
# The length of the disc in sectors.
|
105
|
-
#
|
106
|
-
# @return [Integer] Sectors or `nil` if no ID was yet read.
|
106
|
+
#
|
107
|
+
# @return [Integer] Sectors or `nil` if no ID was yet read.
|
107
108
|
def sectors
|
108
109
|
return Lib.get_sectors @handle if @read
|
109
110
|
end
|
110
111
|
|
111
112
|
# The length of the disc in seconds.
|
112
|
-
#
|
113
|
-
# @return [Integer] Seconds or `nil` if no ID was yet read.
|
113
|
+
#
|
114
|
+
# @return [Integer] Seconds or `nil` if no ID was yet read.
|
114
115
|
def seconds
|
115
116
|
DiscId.sectors_to_seconds(sectors) if @read
|
116
117
|
end
|
@@ -124,7 +125,7 @@ module DiscId
|
|
124
125
|
# Not available on all platforms, see
|
125
126
|
# {http://musicbrainz.org/doc/libdiscid#Feature_Matrix}.
|
126
127
|
#
|
127
|
-
# @return [String] MCN or `nil` if no ID was yet read.
|
128
|
+
# @return [String] MCN or `nil` if no ID was yet read.
|
128
129
|
def mcn
|
129
130
|
return Lib.get_mcn @handle if @read
|
130
131
|
end
|
@@ -151,7 +152,7 @@ module DiscId
|
|
151
152
|
|
152
153
|
# Returns an array of {Track} objects. Each Track object contains
|
153
154
|
# detailed information about the track.
|
154
|
-
#
|
155
|
+
#
|
155
156
|
# Returns always `nil` if no ID was yet read. The block won't be
|
156
157
|
# called in this case.
|
157
158
|
#
|
@@ -162,7 +163,7 @@ module DiscId
|
|
162
163
|
def tracks
|
163
164
|
if @read
|
164
165
|
read_tracks if @tracks.nil?
|
165
|
-
|
166
|
+
|
166
167
|
if block_given?
|
167
168
|
@tracks.each(&Proc.new)
|
168
169
|
return nil
|
@@ -177,21 +178,17 @@ module DiscId
|
|
177
178
|
def read_tracks
|
178
179
|
track_number = self.first_track_number - 1
|
179
180
|
@tracks = []
|
180
|
-
|
181
|
+
|
181
182
|
while track_number < self.last_track_number do
|
182
183
|
track_number += 1
|
183
184
|
isrc = Lib.get_track_isrc(@handle, track_number)
|
184
185
|
offset = Lib.get_track_offset(@handle, track_number)
|
185
186
|
length = Lib.get_track_length(@handle, track_number)
|
186
187
|
track_info = Track.new(track_number, offset, length, isrc)
|
187
|
-
|
188
|
+
|
188
189
|
@tracks << track_info
|
189
190
|
end
|
190
191
|
end
|
191
192
|
|
192
193
|
end
|
193
|
-
|
194
|
-
# This exception is thrown on errors reading the disc or setting the TOC.
|
195
|
-
class DiscError < StandardError
|
196
|
-
end
|
197
194
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright (C) 2013-2014 Philipp Wolfer
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module DiscId
|
17
|
+
# This exception is thrown on errors reading the disc or setting the TOC.
|
18
|
+
class DiscError < StandardError
|
19
|
+
end
|
20
|
+
end
|
data/lib/discid/lib.rb
CHANGED
@@ -29,12 +29,12 @@ module DiscId
|
|
29
29
|
attach_function :new, :discid_new, [], :pointer
|
30
30
|
|
31
31
|
attach_function :free, :discid_free, [:pointer], :void
|
32
|
-
|
32
|
+
|
33
33
|
begin
|
34
34
|
attach_function :read, :discid_read_sparse, [:pointer, :string, :uint], :int
|
35
35
|
rescue FFI::NotFoundError
|
36
36
|
attach_function :legacy_read, :discid_read, [:pointer, :string], :int
|
37
|
-
|
37
|
+
|
38
38
|
def self.read(handle, device, features)
|
39
39
|
legacy_read(handle, device)
|
40
40
|
end
|
@@ -43,13 +43,13 @@ module DiscId
|
|
43
43
|
attach_function :put, :discid_put, [:pointer, :int, :int, :pointer], :int
|
44
44
|
|
45
45
|
attach_function :get_error_msg, :discid_get_error_msg, [:pointer], :string
|
46
|
-
|
46
|
+
|
47
47
|
attach_function :get_id, :discid_get_id, [:pointer], :string
|
48
48
|
|
49
49
|
attach_function :get_freedb_id, :discid_get_freedb_id, [:pointer], :string
|
50
50
|
|
51
51
|
attach_function :get_submission_url, :discid_get_submission_url, [:pointer], :string
|
52
|
-
|
52
|
+
|
53
53
|
attach_function :default_device, :discid_get_default_device, [], :string
|
54
54
|
|
55
55
|
attach_function :get_first_track_num, :discid_get_first_track_num, [:pointer], :int
|
@@ -91,7 +91,7 @@ module DiscId
|
|
91
91
|
end
|
92
92
|
|
93
93
|
#attach_function :get_feature_list, :discid_get_feature_list, [:pointer], :void
|
94
|
-
|
94
|
+
|
95
95
|
begin
|
96
96
|
attach_function :get_version_string, :discid_get_version_string, [], :string
|
97
97
|
rescue FFI::NotFoundError
|
data/lib/discid/track.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
module DiscId
|
18
18
|
|
19
19
|
# This class holds information about a single track.
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# Currently this includes the following fields:
|
22
22
|
#
|
23
23
|
# * number: The number of the track on the disc.
|
@@ -29,32 +29,32 @@ module DiscId
|
|
29
29
|
# * end_time: End position of the track on the disc in seconds.
|
30
30
|
# * isrc: The track's ISRC (International Standard Recordings Code)
|
31
31
|
# if available.
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# You can access all fields either directly or with the square bracket
|
34
34
|
# notation:
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# track = Track.new(1, 150, 16007)
|
37
37
|
# puts track.sectors # 16007
|
38
38
|
# puts track[:sectors] # 16007
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# @see DiscId::Disc#tracks
|
41
41
|
class Track
|
42
|
-
|
42
|
+
|
43
43
|
# The number of the track on the disc.
|
44
44
|
#
|
45
45
|
# @return [Integer]
|
46
46
|
attr_reader :number
|
47
|
-
|
47
|
+
|
48
48
|
# Length of the track in sectors.
|
49
49
|
#
|
50
50
|
# @return [Integer]
|
51
51
|
attr_reader :sectors
|
52
|
-
|
52
|
+
|
53
53
|
# Start position of the track on the disc in sectors.
|
54
54
|
#
|
55
55
|
# @return [Integer]
|
56
56
|
attr_reader :offset
|
57
|
-
|
57
|
+
|
58
58
|
# ISRC number of the track.
|
59
59
|
#
|
60
60
|
# @note libdiscid >= 0.3.0 required. Older versions will always return nil.
|
@@ -63,7 +63,7 @@ module DiscId
|
|
63
63
|
#
|
64
64
|
# @return [String]
|
65
65
|
attr_reader :isrc
|
66
|
-
|
66
|
+
|
67
67
|
# Initializes a new Track object.
|
68
68
|
def initialize(number, offset, sectors, isrc)
|
69
69
|
@number = number
|
@@ -71,37 +71,37 @@ module DiscId
|
|
71
71
|
@sectors = sectors
|
72
72
|
@isrc = isrc
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# End position of the track on the disc in sectors.
|
76
76
|
#
|
77
77
|
# @return [Integer]
|
78
78
|
def end_sector
|
79
79
|
offset + sectors
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# Length of the track in seconds.
|
83
83
|
#
|
84
84
|
# @return [Integer]
|
85
85
|
def seconds
|
86
86
|
DiscId.sectors_to_seconds(sectors)
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
# Start position of the track on the disc in seconds.
|
90
90
|
#
|
91
91
|
# @return [Integer]
|
92
92
|
def start_time
|
93
93
|
DiscId.sectors_to_seconds(offset)
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
# End position of the track on the disc in seconds.
|
97
97
|
#
|
98
98
|
# @return [Integer]
|
99
99
|
def end_time
|
100
100
|
DiscId.sectors_to_seconds(end_sector)
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
# Allows access to all fields similar to accessing values in a hash.
|
104
|
-
#
|
104
|
+
#
|
105
105
|
# Example:
|
106
106
|
#
|
107
107
|
# track = Track.new(1, 150, 16007)
|
@@ -113,7 +113,7 @@ module DiscId
|
|
113
113
|
method(key).call
|
114
114
|
end
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
# Converts the Track into a Hash.
|
118
118
|
#
|
119
119
|
# @return [Hash]
|
@@ -129,6 +129,6 @@ module DiscId
|
|
129
129
|
:isrc => isrc,
|
130
130
|
}
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
end
|
134
134
|
end
|
data/lib/discid/version.rb
CHANGED
data/test/helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright (C) 2013-2014 Philipp Wolfer
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
# The code coverage is only supported for Ruby >= 1.9
|
17
|
+
if (RUBY_VERSION.split('.').map{|s|s.to_i} <=> [1, 9, 0]) >= 0
|
18
|
+
require 'codeclimate-test-reporter'
|
19
|
+
|
20
|
+
CodeClimate::TestReporter.start do
|
21
|
+
add_filter "/test/"
|
22
|
+
end
|
23
|
+
end
|
data/test/test_disc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Philipp Wolfer
|
1
|
+
# Copyright (C) 2013-2014 Philipp Wolfer
|
2
2
|
#
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU Lesser General Public License as published by
|
@@ -13,12 +13,13 @@
|
|
13
13
|
# You should have received a copy of the GNU Lesser General Public License
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
|
+
require 'helper'
|
16
17
|
require 'test/unit'
|
17
18
|
require 'discid'
|
18
19
|
|
19
20
|
# Unit test for the DiscId::Disc class.
|
20
21
|
class TestDisc < Test::Unit::TestCase
|
21
|
-
|
22
|
+
|
22
23
|
def setup
|
23
24
|
@fiction_disc_id = 'Wn8eRBtfLDfM0qjYPdxrz.Zjs_U-'
|
24
25
|
@fiction_first_track = 1
|
@@ -33,7 +34,7 @@ class TestDisc < Test::Unit::TestCase
|
|
33
34
|
|
34
35
|
def teardown
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
def test_empty_disc
|
38
39
|
disc = DiscId::Disc.new
|
39
40
|
assert_equal nil, disc.id
|
@@ -56,7 +57,7 @@ class TestDisc < Test::Unit::TestCase
|
|
56
57
|
# successfull put before.
|
57
58
|
def test_put
|
58
59
|
disc = DiscId::Disc.new
|
59
|
-
|
60
|
+
|
60
61
|
# Erroneous put
|
61
62
|
assert_raise(DiscId::DiscError) do
|
62
63
|
disc = DiscId.put(-1, @fiction_sectors, @fiction_offsets)
|
@@ -68,7 +69,7 @@ class TestDisc < Test::Unit::TestCase
|
|
68
69
|
assert_equal nil, disc.sectors
|
69
70
|
assert_equal nil, disc.seconds
|
70
71
|
assert_equal nil, disc.tracks
|
71
|
-
|
72
|
+
|
72
73
|
# Second successfull put
|
73
74
|
assert_nothing_raised do
|
74
75
|
disc = DiscId.put(@fiction_first_track, @fiction_sectors,
|
data/test/test_discid.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Philipp Wolfer
|
1
|
+
# Copyright (C) 2013-2014 Philipp Wolfer
|
2
2
|
#
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU Lesser General Public License as published by
|
@@ -13,14 +13,15 @@
|
|
13
13
|
# You should have received a copy of the GNU Lesser General Public License
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
|
+
require 'helper'
|
16
17
|
require 'test/unit'
|
17
18
|
require 'discid'
|
18
19
|
|
19
20
|
# Helper class which can't be converted into a string.
|
20
21
|
class NotAString
|
21
|
-
|
22
|
+
|
22
23
|
private
|
23
|
-
|
24
|
+
|
24
25
|
def to_s
|
25
26
|
end
|
26
27
|
|
@@ -43,13 +44,13 @@ class TestDiscId < Test::Unit::TestCase
|
|
43
44
|
|
44
45
|
def teardown
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
# Test reading the disc id from a device.
|
48
49
|
# We would need some kind of small test data to do this.
|
49
50
|
#def test_read
|
50
51
|
# assert false, "Not implemented yet"
|
51
52
|
#end
|
52
|
-
|
53
|
+
|
53
54
|
# Test how read reacts on different arguments.
|
54
55
|
# Those reads should all fail, but they must never cause a segmentation fault.
|
55
56
|
def test_read_invalid_arguments
|
@@ -58,34 +59,35 @@ class TestDiscId < Test::Unit::TestCase
|
|
58
59
|
assert_raise(DiscId::DiscError) {DiscId.read('invalid_device')}
|
59
60
|
assert_raise(DiscId::DiscError) {DiscId.read(:invalid_device)}
|
60
61
|
end
|
61
|
-
|
62
|
+
|
62
63
|
def test_put_first_track_not_one
|
63
64
|
disc = DiscId.put(3, @fiction_sectors,
|
64
|
-
|
65
|
+
[0, 0, 150, 18901, 39738, 59557, 79152, 100126,
|
66
|
+
124833, 147278, 166336, 182560])
|
65
67
|
assert_equal 3, disc.first_track_number
|
66
68
|
assert_equal 12, disc.last_track_number
|
67
69
|
assert_equal 10, disc.tracks.size
|
68
70
|
end
|
69
|
-
|
71
|
+
|
70
72
|
# Test the tracks method and TrackInfo objects
|
71
73
|
def test_put_and_tracks
|
72
74
|
disc = nil
|
73
|
-
|
75
|
+
|
74
76
|
assert_nothing_raised do
|
75
77
|
disc = DiscId.put(@fiction_first_track, @fiction_sectors,
|
76
78
|
@fiction_offsets)
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
# Save a block for testing each track
|
80
82
|
number = 0
|
81
83
|
proc_test_track = lambda do |track|
|
82
84
|
assert_equal number + 1, track.number
|
83
|
-
|
85
|
+
|
84
86
|
assert_equal @fiction_offsets[number], track.offset
|
85
87
|
assert_equal @fiction_lengths[number], track.sectors
|
86
88
|
assert_equal @fiction_offsets[number]+ @fiction_lengths[number],
|
87
89
|
track.end_sector
|
88
|
-
|
90
|
+
|
89
91
|
assert_equal(DiscId.sectors_to_seconds(@fiction_offsets[number]),
|
90
92
|
track.start_time)
|
91
93
|
assert_equal(DiscId.sectors_to_seconds(@fiction_lengths[number]),
|
@@ -93,24 +95,24 @@ class TestDiscId < Test::Unit::TestCase
|
|
93
95
|
assert_equal(DiscId.sectors_to_seconds(
|
94
96
|
@fiction_offsets[number]+ @fiction_lengths[number]),
|
95
97
|
track.end_time)
|
96
|
-
|
98
|
+
|
97
99
|
number += 1
|
98
100
|
end
|
99
|
-
|
101
|
+
|
100
102
|
# Call track_info and retrieve an Array
|
101
|
-
track_info = []
|
103
|
+
track_info = []
|
102
104
|
assert_nothing_raised {track_info = disc.tracks}
|
103
105
|
assert track_info.is_a?(Array)
|
104
106
|
track_info.each(&proc_test_track)
|
105
107
|
assert_equal disc.last_track_number, number
|
106
|
-
|
108
|
+
|
107
109
|
# Calling track_info directly with a given block
|
108
110
|
# Reset the number of tracks (the above block is a closure, so this works)
|
109
111
|
number = 0
|
110
112
|
assert_equal nil, disc.tracks(&proc_test_track)
|
111
113
|
assert_equal disc.last_track_number, number
|
112
114
|
end
|
113
|
-
|
115
|
+
|
114
116
|
# Test the conversion from sectors to seconds
|
115
117
|
def test_sectors_to_seconds
|
116
118
|
assert_equal 0, DiscId.sectors_to_seconds(0)
|
@@ -128,7 +130,7 @@ class TestDiscId < Test::Unit::TestCase
|
|
128
130
|
assert(!DiscId.has_feature?("notafeature"),
|
129
131
|
"Feature 'notafeature' should not be supported")
|
130
132
|
end
|
131
|
-
|
133
|
+
|
132
134
|
def test_feature_list_must_contain_read
|
133
135
|
assert(DiscId.feature_list.include?(:read),
|
134
136
|
"Feature :read should be supported")
|
data/test/test_track.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Philipp Wolfer
|
1
|
+
# Copyright (C) 2013-2014 Philipp Wolfer
|
2
2
|
#
|
3
3
|
# This program is free software: you can redistribute it and/or modify
|
4
4
|
# it under the terms of the GNU Lesser General Public License as published by
|
@@ -13,6 +13,7 @@
|
|
13
13
|
# You should have received a copy of the GNU Lesser General Public License
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
|
+
require 'helper'
|
16
17
|
require 'test/unit'
|
17
18
|
require 'discid/track'
|
18
19
|
|
@@ -57,7 +58,7 @@ class TestTrack < Test::Unit::TestCase
|
|
57
58
|
|
58
59
|
def test_selector_access
|
59
60
|
track = DiscId::Track.new @number, @offset, @length, @isrc
|
60
|
-
|
61
|
+
|
61
62
|
assert_equal track.number, track[:number]
|
62
63
|
assert_equal track.offset, track[:offset]
|
63
64
|
assert_equal track.sectors, track[:sectors]
|
metadata
CHANGED
@@ -1,83 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Wolfer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: kramdown
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
111
|
description: ruby-discid provides Ruby bindings for the MusicBrainz DiscID library
|
@@ -89,9 +117,9 @@ executables: []
|
|
89
117
|
extensions: []
|
90
118
|
extra_rdoc_files: []
|
91
119
|
files:
|
92
|
-
- .gitignore
|
93
|
-
- .travis.yml
|
94
|
-
- .yardopts
|
120
|
+
- ".gitignore"
|
121
|
+
- ".travis.yml"
|
122
|
+
- ".yardopts"
|
95
123
|
- CHANGES
|
96
124
|
- Gemfile
|
97
125
|
- LICENSE
|
@@ -102,9 +130,11 @@ files:
|
|
102
130
|
- examples/readdiscid.rb
|
103
131
|
- lib/discid.rb
|
104
132
|
- lib/discid/disc.rb
|
133
|
+
- lib/discid/disc_error.rb
|
105
134
|
- lib/discid/lib.rb
|
106
135
|
- lib/discid/track.rb
|
107
136
|
- lib/discid/version.rb
|
137
|
+
- test/helper.rb
|
108
138
|
- test/test_disc.rb
|
109
139
|
- test/test_discid.rb
|
110
140
|
- test/test_track.rb
|
@@ -119,22 +149,23 @@ require_paths:
|
|
119
149
|
- lib
|
120
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
151
|
requirements:
|
122
|
-
- -
|
152
|
+
- - ">="
|
123
153
|
- !ruby/object:Gem::Version
|
124
154
|
version: 1.8.7
|
125
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
156
|
requirements:
|
127
|
-
- -
|
157
|
+
- - ">="
|
128
158
|
- !ruby/object:Gem::Version
|
129
159
|
version: 1.3.6
|
130
160
|
requirements:
|
131
161
|
- libdiscid >= 0.1.0
|
132
162
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.4.5.1
|
134
164
|
signing_key:
|
135
165
|
specification_version: 4
|
136
166
|
summary: Ruby bindings for libdiscid
|
137
167
|
test_files:
|
168
|
+
- test/helper.rb
|
138
169
|
- test/test_disc.rb
|
139
170
|
- test/test_discid.rb
|
140
171
|
- test/test_track.rb
|