discid 1.3.2 → 1.4.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 +5 -5
- data/CHANGES.md +5 -0
- data/README.md +1 -1
- data/examples/discfromtoc.rb +33 -0
- data/examples/parsetoc.rb +32 -0
- data/lib/discid.rb +24 -1
- data/lib/discid/disc.rb +11 -4
- data/lib/discid/disc_error.rb +1 -0
- data/lib/discid/lib.rb +1 -0
- data/lib/discid/track.rb +1 -1
- data/lib/discid/version.rb +2 -2
- data/test/test_discid.rb +50 -4
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e54ccf0358d9377e073c158bc10c972410446882
|
4
|
+
data.tar.gz: a29145b466deb26a8830d537cb5471a346fc51bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dfed6d0c5d3e631ee3333f02cb86e7b46239b9eb48a9211b5fc4b7952b0a27bac01f42eb548b973b8fef9c89295a3123343c4dba0479814ff1d6f1e566759f1
|
7
|
+
data.tar.gz: 0ca29384229a241332b53d19613583bc5c95bb80ae51a95154b8612d7e71ed72652a89f1bb701acf09d0c61c97c49e0ada88fd01cfbfdefd280855c2e79b31e1
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.4.0 (2019-05-06)
|
4
|
+
* Fixed {DiscId.put} handling of first_track being > 1
|
5
|
+
* Added {DiscId.parse} to parse a TOC string
|
6
|
+
* Documentation fixes
|
7
|
+
|
3
8
|
## 1.3.2 (2017-12-19)
|
4
9
|
* Fixed call to {DiscId::Disc#toc_string} with native implementation
|
5
10
|
|
data/README.md
CHANGED
@@ -112,7 +112,7 @@ Please report any issues on the
|
|
112
112
|
[issue tracker](https://github.com/phw/ruby-discid/issues).
|
113
113
|
|
114
114
|
## License
|
115
|
-
ruby-discid Copyright (c) 2007-
|
115
|
+
ruby-discid Copyright (c) 2007-2019 by Philipp Wolfer <ph.wolfer@gmail.com>
|
116
116
|
|
117
117
|
ruby-discid is free software: you can redistribute it and/or modify
|
118
118
|
it under the terms of the GNU Lesser General Public License as published by
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script for DiscId.
|
4
|
+
#
|
5
|
+
# This script shows how to generate a disc ID for given TOC data
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# ./discid.rb /dev/dvd
|
9
|
+
|
10
|
+
# Just make sure we can run this example from the command
|
11
|
+
# line even if DiscId is not yet installed properly.
|
12
|
+
$: << 'lib/' << 'ext/' << '../ext/' << '../lib/'
|
13
|
+
|
14
|
+
require 'discid'
|
15
|
+
|
16
|
+
offsets = [150, 44942, 61305, 72755, 96360, 130485, 147315, 164275, 190702, 205412, 220437]
|
17
|
+
|
18
|
+
disc = DiscId.put(1, 242457, offsets)
|
19
|
+
|
20
|
+
|
21
|
+
print <<EOF
|
22
|
+
|
23
|
+
Device : #{disc.device}
|
24
|
+
DiscID : #{disc.id}
|
25
|
+
FreeDB ID : #{disc.freedb_id}
|
26
|
+
TOC string : #{disc.toc_string}
|
27
|
+
First track : #{disc.first_track_number}
|
28
|
+
Last track : #{disc.last_track_number}
|
29
|
+
Total length: #{disc.seconds} seconds
|
30
|
+
Sectors : #{disc.sectors}
|
31
|
+
|
32
|
+
Submit via #{disc.submission_url}
|
33
|
+
EOF
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example script for DiscId.
|
4
|
+
#
|
5
|
+
# This script shows how to generate a disc ID by parsing a given TOC string
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# ./discid.rb /dev/dvd
|
9
|
+
|
10
|
+
# Just make sure we can run this example from the command
|
11
|
+
# line even if DiscId is not yet installed properly.
|
12
|
+
$: << 'lib/' << 'ext/' << '../ext/' << '../lib/'
|
13
|
+
|
14
|
+
require 'discid'
|
15
|
+
|
16
|
+
toc = '1 11 242457 150 44942 61305 72755 96360 130485 147315 164275 190702 205412 220437'
|
17
|
+
|
18
|
+
disc = DiscId.parse(toc)
|
19
|
+
|
20
|
+
print <<EOF
|
21
|
+
|
22
|
+
Device : #{disc.device}
|
23
|
+
DiscID : #{disc.id}
|
24
|
+
FreeDB ID : #{disc.freedb_id}
|
25
|
+
TOC string : #{disc.toc_string}
|
26
|
+
First track : #{disc.first_track_number}
|
27
|
+
Last track : #{disc.last_track_number}
|
28
|
+
Total length: #{disc.seconds} seconds
|
29
|
+
Sectors : #{disc.sectors}
|
30
|
+
|
31
|
+
Submit via #{disc.submission_url}
|
32
|
+
EOF
|
data/lib/discid.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013 Philipp Wolfer
|
1
|
+
# Copyright (C) 2013-2017, 2019 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
|
@@ -120,6 +120,29 @@ module DiscId
|
|
120
120
|
return disc
|
121
121
|
end
|
122
122
|
|
123
|
+
# Parses a TOC string and returns a [Disc] instance for it.
|
124
|
+
#
|
125
|
+
# This function can be used if you already have a TOC string like e.g.
|
126
|
+
# `1 11 242457 150 44942 61305 72755 96360 130485 147315 164275 190702 205412 220437`
|
127
|
+
#
|
128
|
+
# @raise [DiscError] The TOC string was invalid and could not be parsed.
|
129
|
+
# @param toc [String] A TOC string in the format `1 11 242457 150 44942 61305 72755 96360 130485 147315 164275 190702 205412 220437`.
|
130
|
+
# @return [Disc]
|
131
|
+
def self.parse(toc)
|
132
|
+
if toc.nil? || toc.empty?
|
133
|
+
raise DiscError, "Invalid TOC #{toc.inspect}"
|
134
|
+
end
|
135
|
+
begin
|
136
|
+
parts = toc.split(' ')
|
137
|
+
first_track = Integer(parts[0])
|
138
|
+
sectors = Integer(parts[2])
|
139
|
+
offsets = parts[3..-1].map{|i| Integer(i)}
|
140
|
+
rescue ArgumentError, TypeError => e
|
141
|
+
raise DiscError, e
|
142
|
+
end
|
143
|
+
return self.put(first_track, sectors, offsets)
|
144
|
+
end
|
145
|
+
|
123
146
|
# Return the name of the default disc drive for this operating system.
|
124
147
|
#
|
125
148
|
# @return [String] An operating system dependent device identifier
|
data/lib/discid/disc.rb
CHANGED
@@ -18,6 +18,7 @@ require 'discid/disc_error'
|
|
18
18
|
require 'discid/lib'
|
19
19
|
require 'discid/track'
|
20
20
|
|
21
|
+
#
|
21
22
|
module DiscId
|
22
23
|
# This class holds information about a disc (TOC, MCN, ISRCs).
|
23
24
|
#
|
@@ -59,11 +60,14 @@ module DiscId
|
|
59
60
|
def put(first_track, sectors, offsets)
|
60
61
|
@read = false
|
61
62
|
@device = nil
|
62
|
-
last_track = offsets.length
|
63
|
+
last_track = first_track - 1 + offsets.length
|
63
64
|
|
64
65
|
# discid_put expects always an offsets array with exactly 100 elements.
|
65
66
|
FFI::MemoryPointer.new(:int, 100) do |p|
|
66
|
-
|
67
|
+
if last_track > offsets.length
|
68
|
+
offsets = Array.new(last_track - offsets.length, 0) + offsets
|
69
|
+
end
|
70
|
+
p.write_array_of_int(([sectors] + offsets)[0, 100])
|
67
71
|
result = Lib.put @handle, first_track, last_track, p
|
68
72
|
|
69
73
|
if result == 0
|
@@ -132,12 +136,15 @@ module DiscId
|
|
132
136
|
|
133
137
|
# Return a string representing CD Table Of Contents (TOC).
|
134
138
|
#
|
135
|
-
# The TOC suitable as value of the toc parameter when accessing the
|
139
|
+
# The TOC suitable as a value of the toc parameter when accessing the
|
136
140
|
# MusicBrainz Web Service. This enables fuzzy searching when the actual
|
137
141
|
# DiscID is not found.
|
138
142
|
#
|
139
143
|
# Note that this is the unencoded value, which still contains spaces.
|
140
144
|
#
|
145
|
+
# For libdiscid >= 0.6 the native implementation will be used. For older
|
146
|
+
# versions falls back to extract the TOC from {Disc#submission_url}.
|
147
|
+
#
|
141
148
|
# @since 1.3
|
142
149
|
#
|
143
150
|
# @raise [RuntimeError] get_toc_string is unsupported by libdiscid and
|
@@ -186,7 +193,7 @@ module DiscId
|
|
186
193
|
# Returns always `nil` if no ID was yet read. The block won't be
|
187
194
|
# called in this case.
|
188
195
|
#
|
189
|
-
# @yield [
|
196
|
+
# @yield [Track] If a block is given this method returns `nil` and
|
190
197
|
# instead iterates over the block calling the block with one argument.
|
191
198
|
# @yieldreturn [nil]
|
192
199
|
# @return [Array<Track>] Array of {Track} objects.
|
data/lib/discid/disc_error.rb
CHANGED
@@ -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
|
+
#
|
16
17
|
module DiscId
|
17
18
|
# This exception is thrown on errors reading the disc or setting the TOC.
|
18
19
|
class DiscError < StandardError
|
data/lib/discid/lib.rb
CHANGED
data/lib/discid/track.rb
CHANGED
data/lib/discid/version.rb
CHANGED
@@ -13,8 +13,8 @@
|
|
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
|
-
|
16
|
+
#
|
17
17
|
module DiscId
|
18
18
|
# The version of ruby-discid.
|
19
|
-
VERSION = "1.
|
19
|
+
VERSION = "1.4.0"
|
20
20
|
end
|
data/test/test_discid.rb
CHANGED
@@ -55,20 +55,25 @@ class TestDiscId < Test::Unit::TestCase
|
|
55
55
|
# Those reads should all fail, but they must never cause a segmentation fault.
|
56
56
|
def test_read_invalid_arguments
|
57
57
|
assert_raise(TypeError) {DiscId.read(NotAString.new)}
|
58
|
-
assert_raise(DiscId::DiscError) {DiscId.read(
|
59
|
-
assert_raise(DiscId::DiscError) {DiscId.read(
|
60
|
-
assert_raise(DiscId::DiscError) {DiscId.read(:invalid_device)}
|
58
|
+
assert_raise(DiscId::DiscError) { DiscId.read('invalid_device') }
|
59
|
+
assert_raise(DiscId::DiscError) { DiscId.read(:invalid_device) }
|
61
60
|
end
|
62
61
|
|
63
62
|
def test_put_first_track_not_one
|
64
63
|
disc = DiscId.put(3, @fiction_sectors,
|
65
|
-
[
|
64
|
+
[150, 18901, 39738, 59557, 79152, 100126,
|
66
65
|
124833, 147278, 166336, 182560])
|
67
66
|
assert_equal 3, disc.first_track_number
|
68
67
|
assert_equal 12, disc.last_track_number
|
69
68
|
assert_equal 10, disc.tracks.size
|
70
69
|
end
|
71
70
|
|
71
|
+
def test_put_invalid_track_count
|
72
|
+
assert_raise(DiscId::DiscError) {
|
73
|
+
disc = DiscId.put(1, @fiction_sectors, Array.new(101) {|i| i + 150 })
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
72
77
|
# Test the tracks method and TrackInfo objects
|
73
78
|
def test_put_and_tracks
|
74
79
|
disc = nil
|
@@ -113,6 +118,47 @@ class TestDiscId < Test::Unit::TestCase
|
|
113
118
|
assert_equal disc.last_track_number, number
|
114
119
|
end
|
115
120
|
|
121
|
+
def test_parse
|
122
|
+
toc = '1 11 242457 150 44942 61305 72755 96360 130485 147315 164275 190702 205412 220437'
|
123
|
+
assert_nothing_raised do
|
124
|
+
disc = DiscId.parse(toc)
|
125
|
+
assert_equal 'lSOVc5h6IXSuzcamJS1Gp4_tRuA-', disc.id
|
126
|
+
assert_equal toc, disc.toc_string
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_parse_minimal
|
131
|
+
toc = '1 1 44942 150'
|
132
|
+
assert_nothing_raised do
|
133
|
+
disc = DiscId.parse(toc)
|
134
|
+
assert_equal 'ANJa4DGYN_ktpzOwvVPtcjwP7mE-', disc.id
|
135
|
+
assert_equal toc, disc.toc_string
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_parse_first_track_not_one
|
140
|
+
toc = '3 12 242457 150 18901 39738 59557 79152 100126 124833 147278 166336 182560'
|
141
|
+
assert_nothing_raised do
|
142
|
+
disc = DiscId.parse(toc)
|
143
|
+
assert_equal 'fC1yNbC5bVjbvphqlAY9JyYoWEY-', disc.id
|
144
|
+
assert_equal toc, disc.toc_string
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_parse_invalid_empty
|
149
|
+
assert_raise(DiscId::DiscError) { DiscId.parse("") }
|
150
|
+
assert_raise(DiscId::DiscError) { DiscId.parse(nil) }
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_parse_invalid_nan
|
154
|
+
assert_raise(DiscId::DiscError) { DiscId.parse("1 2 242457 150 a") }
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_parse_invalid_not_enough_elements
|
158
|
+
assert_raise(DiscId::DiscError) { DiscId.parse("1 2 242457") }
|
159
|
+
assert_raise(DiscId::DiscError) { DiscId.parse("1 242457") }
|
160
|
+
end
|
161
|
+
|
116
162
|
# Test the conversion from sectors to seconds
|
117
163
|
def test_sectors_to_seconds
|
118
164
|
assert_equal 0, DiscId.sectors_to_seconds(0)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.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: 2019-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -122,7 +122,9 @@ files:
|
|
122
122
|
- LICENSE
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
|
+
- examples/discfromtoc.rb
|
125
126
|
- examples/discidinfo.rb
|
127
|
+
- examples/parsetoc.rb
|
126
128
|
- examples/readdiscid.rb
|
127
129
|
- lib/discid.rb
|
128
130
|
- lib/discid/disc.rb
|
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
159
|
requirements:
|
158
160
|
- libdiscid >= 0.1.0
|
159
161
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.6.14.4
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: Ruby bindings for libdiscid
|