discid 1.0.0.a1 → 1.0.0.rc1
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.
- data/.yardopts +1 -1
- data/CHANGES +20 -17
- data/README.md +15 -3
- data/discid.gemspec +3 -2
- data/examples/discid.rb +4 -4
- data/lib/discid.rb +74 -5
- data/lib/discid/disc.rb +6 -2
- data/lib/discid/lib.rb +42 -9
- data/lib/discid/track_info.rb +5 -1
- data/lib/discid/version.rb +1 -1
- data/test/test_discid.rb +5 -0
- metadata +5 -4
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--no-private --markup markdown
|
1
|
+
--no-private --markup markdown --markup-provider kramdown - CHANGES
|
data/CHANGES
CHANGED
@@ -1,42 +1,45 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.0.0
|
4
|
+
* Support libdiscid versions 0.1.0 through 0.5.0
|
5
|
+
* Compatible with JRuby
|
6
|
+
|
7
|
+
## 1.0.0.a1 (2013-04-22)
|
3
8
|
* Use FFI instead of C module
|
4
9
|
* Completely overhauled API
|
5
10
|
* Full support for MCN, ISRC and libdiscid feature detection
|
6
11
|
* Renamed from mb-discid to just discid
|
7
12
|
|
8
|
-
|
13
|
+
## 0.2.0 (2013-02-17)
|
9
14
|
* Support for MCN and ISRC (requires libdiscid >= 0.3)
|
10
15
|
|
11
|
-
|
16
|
+
## 0.1.5 (2011-07-02)
|
12
17
|
* Added binding for get_webservice_url()
|
13
18
|
* Add lib path detection, allows out-of-the-box install when your
|
14
19
|
libdiscid is in /usr/local (Matt Patterson)
|
15
20
|
|
16
|
-
|
17
|
-
* Fixed calling
|
21
|
+
## 0.1.4 (2009-11-19)
|
22
|
+
* Fixed calling read method without argument
|
18
23
|
|
19
|
-
|
20
|
-
* Added singleton method
|
21
|
-
* Added method
|
22
|
-
* Added method
|
24
|
+
## 0.1.3 (2009-11-19)
|
25
|
+
* Added singleton method sectors_to_seconds to convert sectors into seconds
|
26
|
+
* Added method seconds to retrieve disc length in seconds
|
27
|
+
* Added method track_info for accessing more detailed information about tracks
|
23
28
|
* Fixed building with Ruby 1.9 (Mihaly Csomay)
|
24
29
|
|
25
|
-
|
26
|
-
* Support the method
|
30
|
+
## 0.1.2 (2007-07-04)
|
31
|
+
* Support the method put to set the TOC information directly instead of
|
27
32
|
reading it from a device.
|
28
|
-
* Fixed possible core dump if
|
33
|
+
* Fixed possible core dump if read was called twice and failed the
|
29
34
|
second time.
|
30
35
|
* New to_s method (returns string representation of the ID itself).
|
31
36
|
* Complete RDoc documentation.
|
32
37
|
|
33
|
-
|
38
|
+
## 0.1.1 (2007-06-03)
|
34
39
|
* Minor changes to source to support MS compiler
|
35
40
|
* Provide Win32 binary gem
|
36
41
|
* Changed require of library to "require 'mb-discid'" (was "require 'DiscID'"
|
37
42
|
before, which was likely to cause problems)
|
38
43
|
|
39
|
-
|
44
|
+
## 0.1.0 (2007-06-02)
|
40
45
|
* Initial release
|
41
|
-
|
42
|
-
$Id$
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ the library can extract the MCN/UPC/EAN and the ISRCs from disc.
|
|
8
8
|
## Requirements
|
9
9
|
* Ruby >= 1.8.6
|
10
10
|
* Ruby-FFI
|
11
|
-
* libdiscid >= 0.
|
11
|
+
* libdiscid >= 0.1.0
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
Before installing ruby-discid make sure you have libdiscid installed. See
|
@@ -23,6 +23,7 @@ Or install it from the source tarball:
|
|
23
23
|
rake install
|
24
24
|
|
25
25
|
## Usage
|
26
|
+
|
26
27
|
### Read only the TOC
|
27
28
|
|
28
29
|
require 'discid'
|
@@ -52,5 +53,16 @@ Or install it from the source tarball:
|
|
52
53
|
puts " ISRC : %s" % track.isrc
|
53
54
|
end
|
54
55
|
|
55
|
-
See the documentation
|
56
|
-
more usage information.
|
56
|
+
See the [API documentation](http://rubydoc.info/github/phw/ruby-discid/master/frames)
|
57
|
+
of {DiscId} or the files in the `examples` directory for more usage information.
|
58
|
+
|
59
|
+
## Contribute
|
60
|
+
The source code for ruby-discid is available on
|
61
|
+
[GitHub](https://github.com/phw/ruby-discid).
|
62
|
+
|
63
|
+
Please report any issues on the
|
64
|
+
[issue tracker](https://github.com/phw/ruby-discid/issues).
|
65
|
+
|
66
|
+
## License
|
67
|
+
ruby-discid is released under the GNU Lesser General Public License Version 3.
|
68
|
+
See LICENSE.txt for details.
|
data/discid.gemspec
CHANGED
@@ -11,7 +11,8 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = %q{ruby-discid provides Ruby bindings for the MusicBrainz DiscID library libdiscid. It allows calculating DiscIDs (MusicBrainz and freedb) for Audio CDs. Additionally the library can extract the MCN/UPC/EAN and the ISRCs from disc.}
|
12
12
|
spec.summary = %q{Ruby bindings for libdiscid}
|
13
13
|
spec.homepage = "https://github.com/phw/ruby-discid"
|
14
|
-
spec.license = "
|
14
|
+
spec.license = "LGPL-3"
|
15
|
+
spec.post_install_message = %q{Please make sure you have libdiscid (http://musicbrainz.org/doc/libdiscid) installed.}
|
15
16
|
|
16
17
|
spec.files = `git ls-files`.split($/)
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -23,5 +24,5 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "rake"
|
25
26
|
spec.add_development_dependency "yard"
|
26
|
-
spec.add_development_dependency "
|
27
|
+
spec.add_development_dependency "kramdown"
|
27
28
|
end
|
data/examples/discid.rb
CHANGED
@@ -41,10 +41,11 @@ First track : #{disc.first_track_num}
|
|
41
41
|
Last track : #{disc.last_track_num}
|
42
42
|
Total length: #{disc.seconds} seconds
|
43
43
|
Sectors : #{disc.sectors}
|
44
|
-
MCN : #{disc.mcn}
|
45
|
-
|
46
44
|
EOF
|
47
45
|
|
46
|
+
puts "MCN : #{disc.mcn}" if DiscId.has_feature?(:mcn)
|
47
|
+
puts
|
48
|
+
|
48
49
|
# Print information about individual tracks:
|
49
50
|
disc.tracks do |track|
|
50
51
|
puts "Track ##{track.number}"
|
@@ -54,10 +55,9 @@ disc.tracks do |track|
|
|
54
55
|
[track.start_time / 60, track.start_time % 60, track.start_sector]
|
55
56
|
puts " End : %02d:%02d (sector %i)" %
|
56
57
|
[track.end_time / 60, track.end_time % 60, track.end_sector]
|
57
|
-
puts " ISRC : %s" % track.isrc
|
58
|
+
puts " ISRC : %s" % track.isrc if DiscId.has_feature?(:isrc)
|
58
59
|
end
|
59
60
|
|
60
61
|
# Print a submission URL that can be used to submit
|
61
62
|
# the disc ID to MusicBrainz.org.
|
62
63
|
puts "\nSubmit via #{disc.submission_url}"
|
63
|
-
#puts "\nWebservice #{disc.webservice_url}"
|
data/lib/discid.rb
CHANGED
@@ -20,6 +20,50 @@ require 'discid/version'
|
|
20
20
|
# The DiscId module allows calculating DiscIDs (MusicBrainz and freedb)
|
21
21
|
# for Audio CDs. Additionally the library can extract the MCN/UPC/EAN and
|
22
22
|
# the ISRCs from disc.
|
23
|
+
#
|
24
|
+
# The main interface for using this module are the {read} and {put}
|
25
|
+
# methods which both return an instance of {Disc}. {read} allows you to
|
26
|
+
# read the data from an actual CD drive while {put} allows you to
|
27
|
+
# calculate the DiscID for a previously read CD TOC.
|
28
|
+
#
|
29
|
+
# Depending on the version of libdiscid and the operating system used
|
30
|
+
# additional features like reading the MCN or ISRCs from the disc
|
31
|
+
# might be available. You can check for supported features with {has_feature?}.
|
32
|
+
#
|
33
|
+
# @see http://musicbrainz.org/doc/libdiscid#Feature_Matrix
|
34
|
+
#
|
35
|
+
# @example Read the TOC, MCN and ISRCs
|
36
|
+
# require 'discid'
|
37
|
+
#
|
38
|
+
# device = "/dev/cdrom"
|
39
|
+
# disc = DiscId.read(device, :mcn, :isrc)
|
40
|
+
#
|
41
|
+
# # Print information about the disc:
|
42
|
+
# puts "DiscID : #{disc.id}"
|
43
|
+
# puts "FreeDB ID : #{disc.freedb_id}"
|
44
|
+
# puts "Total length: #{disc.seconds} seconds"
|
45
|
+
# puts "MCN : #{disc.mcn}"
|
46
|
+
#
|
47
|
+
# # Print information about individual tracks:
|
48
|
+
# disc.tracks do |track|
|
49
|
+
# puts "Track ##{track.number}"
|
50
|
+
# puts " Length: %02d:%02d (%i sectors)" %
|
51
|
+
# [track.seconds / 60, track.seconds % 60, track.sectors]
|
52
|
+
# puts " ISRC : %s" % track.isrc
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# @example Get the DiscID for an existing TOC
|
56
|
+
# require 'discid'
|
57
|
+
#
|
58
|
+
# first_track = 1
|
59
|
+
# sectors = 82255
|
60
|
+
# offsets = [150, 16157, 35932, 57527]
|
61
|
+
# disc = DiscId.put(first_track, sectors, offsets)
|
62
|
+
# puts disc.id # Output: E5VLOkhodzhvsMlK8LSNVioYOgY-
|
63
|
+
#
|
64
|
+
# @example Check for supported MCN feature
|
65
|
+
# disc = DiscId.read(nil, :mcn)
|
66
|
+
# puts "MCN: #{disc.mcn}" if DiscId.has_feature?(:mcn)
|
23
67
|
module DiscId
|
24
68
|
|
25
69
|
# Read the disc in the given CD-ROM/DVD-ROM drive extracting only the
|
@@ -39,14 +83,20 @@ module DiscId
|
|
39
83
|
# @example Read the TOC, MCN and ISRCs:
|
40
84
|
# disc = DiscId.read(device, :mcn, :isrc)
|
41
85
|
#
|
86
|
+
# @note libdiscid >= 0.5.0 is required for the feature selection to work.
|
87
|
+
# Older versions will allways read MCN and ISRCs when supported. See
|
88
|
+
# {http://musicbrainz.org/doc/libdiscid#Feature_Matrix} for a list of
|
89
|
+
# supported features by version and platform.
|
90
|
+
#
|
42
91
|
# @raise [TypeError] `device` can not be converted to a String.
|
43
92
|
# @raise [Exception] Error reading from `device`. `Exception#message` contains
|
44
93
|
# error details.
|
45
|
-
# @param device [String] The device identifier.
|
46
|
-
#
|
94
|
+
# @param device [String] The device identifier. If set to `nil` {default_device}
|
95
|
+
# will be used.
|
96
|
+
# @param features [:mcn, :isrc] List of features to use.
|
47
97
|
# `:read` is always implied.
|
48
98
|
# @return [Disc]
|
49
|
-
def self.read(device, *features)
|
99
|
+
def self.read(device = nil, *features)
|
50
100
|
disc = Disc.new
|
51
101
|
disc.read device, *features
|
52
102
|
return disc
|
@@ -79,12 +129,31 @@ module DiscId
|
|
79
129
|
|
80
130
|
# Check if a certain feature is implemented on the current platform.
|
81
131
|
#
|
132
|
+
# You can obtain a list of supported features with {feature_list}.
|
133
|
+
#
|
134
|
+
# @note libdiscid >= 0.5.0 required. Older versions will return `true`
|
135
|
+
# for `:read` and `false` for anything else.
|
136
|
+
#
|
82
137
|
# @param feature [:read, :mcn, :isrc]
|
83
138
|
# @return [Boolean] True if the feature is implemented and false if not.
|
84
139
|
def self.has_feature?(feature)
|
85
140
|
feature = feature.to_sym if feature.respond_to? :to_sym
|
86
|
-
|
87
|
-
|
141
|
+
return self.feature_list.include? feature
|
142
|
+
end
|
143
|
+
|
144
|
+
# A list of features supported by the current platform.
|
145
|
+
#
|
146
|
+
# Currently the following features are available:
|
147
|
+
#
|
148
|
+
# * :read
|
149
|
+
# * :mcn
|
150
|
+
# * :isrc
|
151
|
+
#
|
152
|
+
# @note libdiscid >= 0.5.0 required. Older versions will return only [:read].
|
153
|
+
#
|
154
|
+
# @return [Array<Symbol>]
|
155
|
+
def self.feature_list
|
156
|
+
return Lib::Features.symbols.select {|f| Lib.has_feature(f) == 1}
|
88
157
|
end
|
89
158
|
|
90
159
|
# Converts sectors to seconds.
|
data/lib/discid/disc.rb
CHANGED
@@ -36,7 +36,7 @@ module DiscId
|
|
36
36
|
# @private
|
37
37
|
def read(device, *features)
|
38
38
|
@read = false
|
39
|
-
device =
|
39
|
+
device = DiscId.default_device if device.nil?
|
40
40
|
|
41
41
|
if not device.respond_to? :to_s
|
42
42
|
raise TypeError, 'wrong argument type (expected String)'
|
@@ -123,7 +123,11 @@ module DiscId
|
|
123
123
|
#
|
124
124
|
# Requires libdiscid >= 0.5. If not supported this method will always
|
125
125
|
# return `nil`.
|
126
|
-
#
|
126
|
+
#
|
127
|
+
# @note libdiscid >= 0.3.0 required. Older versions will always return nil.
|
128
|
+
# Not available on all platforms, see
|
129
|
+
# {http://musicbrainz.org/doc/libdiscid#Feature_Matrix}.
|
130
|
+
#
|
127
131
|
# @return [String] MCN or `nil` if no ID was yet read.
|
128
132
|
def mcn
|
129
133
|
return nil unless @read
|
data/lib/discid/lib.rb
CHANGED
@@ -18,7 +18,8 @@ require "ffi"
|
|
18
18
|
module DiscId
|
19
19
|
|
20
20
|
# This module encapsulates the C interface for libdiscid using FFI.
|
21
|
-
# The Lib module is intended for internal use only and should be
|
21
|
+
# The Lib module is intended for internal use only and should be
|
22
|
+
# considered private.
|
22
23
|
#
|
23
24
|
# @private
|
24
25
|
module Lib
|
@@ -29,8 +30,15 @@ module DiscId
|
|
29
30
|
|
30
31
|
attach_function :free, :discid_free, [:pointer], :void
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
begin
|
34
|
+
attach_function :read, :discid_read_sparse, [:pointer, :string, :uint], :int
|
35
|
+
rescue FFI::NotFoundError
|
36
|
+
attach_function :legacy_read, :discid_read, [:pointer, :string], :int
|
37
|
+
|
38
|
+
def self.read(handle, device, features)
|
39
|
+
legacy_read(handle, device)
|
40
|
+
end
|
41
|
+
end
|
34
42
|
|
35
43
|
attach_function :put, :discid_put, [:pointer, :int, :int, :pointer], :int
|
36
44
|
|
@@ -54,27 +62,52 @@ module DiscId
|
|
54
62
|
|
55
63
|
attach_function :get_track_length, :discid_get_track_length, [:pointer, :int], :int
|
56
64
|
|
57
|
-
|
65
|
+
begin
|
66
|
+
attach_function :get_mcn, :discid_get_mcn, [:pointer], :string
|
67
|
+
rescue FFI::NotFoundError
|
68
|
+
def self.get_mcn(handle)
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
end
|
58
72
|
|
59
|
-
|
73
|
+
begin
|
74
|
+
attach_function :get_track_isrc, :discid_get_track_isrc, [:pointer, :int], :string
|
75
|
+
rescue FFI::NotFoundError
|
76
|
+
def self.get_track_isrc(handle, track)
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
end
|
60
80
|
|
61
81
|
Features = enum(:feature, [:read, 1 << 0,
|
62
82
|
:mcn, 1 << 1,
|
63
83
|
:isrc, 1 << 2])
|
64
84
|
|
65
|
-
|
85
|
+
begin
|
86
|
+
attach_function :has_feature, :discid_has_feature, [:feature], :int
|
87
|
+
rescue FFI::NotFoundError
|
88
|
+
def self.has_feature(feature)
|
89
|
+
return feature.to_sym == :read ? 1 : 0
|
90
|
+
end
|
91
|
+
end
|
66
92
|
|
67
93
|
#attach_function :get_feature_list, :discid_get_feature_list, [:pointer], :void
|
68
94
|
|
69
|
-
|
70
|
-
|
95
|
+
begin
|
96
|
+
attach_function :get_version_string, :discid_get_version_string, [], :string
|
97
|
+
rescue FFI::NotFoundError
|
98
|
+
def self.get_version_string
|
99
|
+
return "libdiscid < 0.4.0"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
71
103
|
def self.features_to_int(features)
|
72
104
|
feature_flag = 0
|
73
105
|
features.each do |feature|
|
74
106
|
if feature.respond_to? :to_sym
|
75
107
|
feature = feature.to_sym
|
76
108
|
feature_flag |= self::Features[feature] if
|
77
|
-
self::Features.symbols.include?(feature)
|
109
|
+
self::Features.symbols.include?(feature) and
|
110
|
+
self.has_feature(feature)
|
78
111
|
end
|
79
112
|
end
|
80
113
|
|
data/lib/discid/track_info.rb
CHANGED
@@ -55,7 +55,11 @@ module DiscId
|
|
55
55
|
# @return [Integer]
|
56
56
|
attr_reader :start_sector
|
57
57
|
|
58
|
-
# ISRC number of the
|
58
|
+
# ISRC number of the track.
|
59
|
+
#
|
60
|
+
# @note libdiscid >= 0.3.0 required. Older versions will always return nil.
|
61
|
+
# Not available on all platforms, see
|
62
|
+
# {http://musicbrainz.org/doc/libdiscid#Feature_Matrix}.
|
59
63
|
#
|
60
64
|
# @return [String]
|
61
65
|
attr_reader :isrc
|
data/lib/discid/version.rb
CHANGED
data/test/test_discid.rb
CHANGED
@@ -159,4 +159,9 @@ class TestDiscID < Test::Unit::TestCase
|
|
159
159
|
"Feature 'notafeature' should not be supported")
|
160
160
|
end
|
161
161
|
|
162
|
+
def test_feature_list_must_contain_read
|
163
|
+
assert(DiscId.feature_list.include?(:read),
|
164
|
+
"Feature :read should be supported")
|
165
|
+
end
|
166
|
+
|
162
167
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: kramdown
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -119,8 +119,9 @@ files:
|
|
119
119
|
- test/test_discid.rb
|
120
120
|
homepage: https://github.com/phw/ruby-discid
|
121
121
|
licenses:
|
122
|
-
-
|
123
|
-
post_install_message:
|
122
|
+
- LGPL-3
|
123
|
+
post_install_message: Please make sure you have libdiscid (http://musicbrainz.org/doc/libdiscid)
|
124
|
+
installed.
|
124
125
|
rdoc_options: []
|
125
126
|
require_paths:
|
126
127
|
- lib
|