mb-discid 0.1.1-mswin32

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/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2007, Philipp Wolfer
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ 3. Neither the name of the RBrainz project nor the names of the
12
+ contributors may be used to endorse or promote products derived from
13
+ this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
+ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,36 @@
1
+ = MB-DiscID - Ruby bindings for MusicBrainz libdiscid
2
+
3
+ == About
4
+ MB-DiscID provides Ruby bindings for the MusicBrainz DiscID library libdsicid.
5
+ It allows you to calculate MusicBrainz DiscIDs from audio CDs which you can use
6
+ to find the release entry for your CD in the MusicBrainz database.
7
+
8
+ == Installation
9
+ Before installing rdiscid make sure you have libdiscid installed. See
10
+ http://musicbrainz.org/doc/libdiscid for more information on how to do this.
11
+
12
+ === Installation with RubyGems
13
+ gem install mb-discid
14
+
15
+ == Installation on Windows operating systems.
16
+ For Windows a binary gem "mb-discid-0.1.1-mswin32.gem" is available. To install
17
+ it follow the instructions below:
18
+
19
+ 1. Make sure you have at least Ruby 1.8.6 installed.
20
+ 2. Install RubyGems, if you don't already have it.
21
+ 3. Download "libdiscid-0.1.1-win32bin.zip" from
22
+ http://musicbrainz.org/doc/libdiscid.
23
+ 4. Copy the file "discid.dll" from "libdiscid-0.1.1-win32bin.zip" to your Ruby
24
+ bin directory (normally "C:\ruby\bin".
25
+ 5. Run "gem install mb-discid" to install MB-DiscID.
26
+ 6. To test the installation try to run "discid.rb" in the examples directory.
27
+
28
+ === Installing from source
29
+ rake install
30
+
31
+ == Usage
32
+ See the files in the examples directory for usage information.
33
+
34
+ == License
35
+ Copyright (c) 2007, Philipp Wolfer
36
+ Licensing information can be found in the file LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,111 @@
1
+ # $Id: Rakefile 67 2007-06-03 14:09:23Z phw $
2
+ # Copyright (c) 2007, Philipp Wolfer
3
+ # All rights reserved.
4
+ # See LICENSE for permissions.
5
+
6
+ # Rakefile for RDiscID
7
+
8
+ require 'rubygems'
9
+ require 'rake/gempackagetask'
10
+
11
+ task :default do
12
+ puts "Please see 'rake --tasks' for an overview of the available tasks."
13
+ end
14
+
15
+ # Packaging tasks: -------------------------------------------------------
16
+
17
+ PKG_NAME = 'mb-discid'
18
+ PKG_VERSION = '0.1.1'
19
+ PKG_SUMMARY = 'Ruby bindings for libdiscid.'
20
+ PKG_AUTHOR = 'Philipp Wolfer'
21
+ PKG_EMAIL = 'phw@rubyforge.org'
22
+ PKG_HOMEPAGE = 'http://rbrainz.rubyforge.org'
23
+ PKG_DESCRIPTION = <<EOF
24
+ Ruby bindings for libdiscid. See http://musicbrainz.org/doc/libdiscid
25
+ for more information on libdiscid and MusicBrainz.
26
+ EOF
27
+ PKG_FILES = FileList[
28
+ 'Rakefile', 'LICENSE', 'README',
29
+ 'examples/**/*',
30
+ 'ext/**/*.{c,rb}',
31
+ 'lib/**/*.rb'
32
+ ]
33
+
34
+ spec = Gem::Specification.new do |spec|
35
+ spec.name = PKG_NAME
36
+ spec.version = PKG_VERSION
37
+ spec.summary = PKG_SUMMARY
38
+ if ENV['BINARY_GEM'] == 'win32'
39
+ spec.platform = Gem::Platform::WIN32
40
+ spec.files = PKG_FILES << 'ext/MB_DiscID.so'
41
+ spec.bindir = 'bin'
42
+ spec.required_ruby_version = ">= #{RUBY_VERSION}"
43
+ else
44
+ spec.platform = Gem::Platform::RUBY
45
+ spec.files = PKG_FILES
46
+ spec.extensions << 'ext/extconf.rb'
47
+ end
48
+ spec.requirements << 'libdiscid (http://musicbrainz.org/doc/libdiscid)'
49
+ spec.require_paths = ['lib', 'ext']
50
+ spec.autorequire = spec.name
51
+ spec.description = PKG_DESCRIPTION
52
+ spec.author = PKG_AUTHOR
53
+ spec.email = PKG_EMAIL
54
+ spec.homepage = PKG_HOMEPAGE
55
+ spec.rubyforge_project = 'rbrainz'
56
+ end
57
+
58
+ Rake::GemPackageTask.new(spec) do |pkg|
59
+ pkg.need_zip = true
60
+ pkg.need_tar_gz= true
61
+ end
62
+
63
+ # Build tasks: -----------------------------------------------------------
64
+
65
+ desc 'Build all the extensions'
66
+ task :build do
67
+ extconf_args = ''
68
+
69
+ unless ENV['DISCID_DIR'].nil?
70
+ extconf_args = "--with-discid-dir=#{ENV['DISCID_DIR']}"
71
+ end
72
+
73
+ cd 'ext' do
74
+ unless system("ruby extconf.rb #{extconf_args}")
75
+ STDERR.puts "ERROR: could not configure extension!\n" +
76
+ "\n#{INFO_NOTE}\n"
77
+ break
78
+ end
79
+
80
+ unless system('make') or system('nmake')
81
+ STDERR.puts 'ERROR: could not build extension!'
82
+ break
83
+ end
84
+ end
85
+ end
86
+
87
+ desc 'Install (and build) extensions'
88
+ task :install => [:build] do
89
+ cd 'ext' do
90
+ unless system('make install')
91
+ STDERR.puts 'ERROR: could not install extension!'
92
+ break
93
+ end
94
+ end
95
+ end
96
+
97
+ desc 'Remove extension products'
98
+ task :clobber_build do
99
+ FileList['ext/**/*'].each do |file|
100
+ unless FileList['ext/**/*.{c,rb}'].include?(file)
101
+ rm_r file if File.exists?(file)
102
+ end
103
+ end
104
+ end
105
+
106
+ desc 'Force a rebuild of the extension files'
107
+ task :rebuild => [:clobber_build, :build]
108
+
109
+ desc 'Remove all files created during the build process'
110
+ task :clobber => [:clobber_build, :clobber_package]
111
+
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mb-discid'
4
+
5
+ # Read the device name from the command line or use the default.
6
+ device = $*[0] ? $*[0] : MusicBrainz::DiscID.default_device
7
+
8
+ disc = MusicBrainz::DiscID.new
9
+ disc.read(device)
10
+
11
+ print <<EOF
12
+ DiscID : #{disc.id}
13
+ Submit via : #{disc.submission_url}
14
+ FreeDB ID : #{disc.freedb_id}
15
+ First track: #{disc.first_track_num}
16
+ Last track : #{disc.last_track_num}
17
+ Sectors : #{disc.sectors}
18
+ EOF
19
+
20
+ track = disc.first_track_num
21
+ disc.tracks do |offset, length|
22
+ puts "Track #{track}: Offset #{offset}, Length #{length}"
23
+ track += 1
24
+ end
data/ext/MB_DiscID.so ADDED
Binary file
data/ext/extconf.rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # $Id: extconf.rb 68 2007-06-03 14:12:21Z phw $
3
+
4
+ require 'mkmf'
5
+
6
+ if have_library('discid', 'discid_new') or
7
+ have_library('discid.dll', 'discid_new')
8
+ # Remove -MD from compiler flags on Windows.
9
+ $CFLAGS.sub!('-MD', '') if RUBY_PLATFORM.include? 'win32'
10
+ create_makefile('MB_DiscID')
11
+ else
12
+ puts 'Required library libdiscid not found.'
13
+ end
data/ext/mb_discid.c ADDED
@@ -0,0 +1,267 @@
1
+ /*---------------------------------------------------------------------------
2
+ $Id: mb_discid.c 67 2007-06-03 14:09:23Z phw $
3
+ Copyright (c) 2007, Philipp Wolfer
4
+ All rights reserved.
5
+ See LICENSE for permissions.
6
+
7
+ Ruby bindings for libdiscid. See http://musicbrainz.org/doc/libdiscid
8
+ for more information on libdiscid and MusicBrainz.
9
+ ---------------------------------------------------------------------------*/
10
+
11
+ #include "ruby.h"
12
+ #include "discid/discid.h"
13
+
14
+ /**
15
+ * The MusicBrainz module.
16
+ */
17
+ static VALUE mMusicBrainz;
18
+
19
+ /**
20
+ * The DiscID class.
21
+ */
22
+ static VALUE cDiscID;
23
+
24
+ /**
25
+ * Returns the DiscID as a string.
26
+ *
27
+ * Returns nil if no ID was yet read.
28
+ */
29
+ static VALUE mb_discid_id(VALUE self)
30
+ {
31
+ if (rb_iv_get(self, "@read") == Qfalse)
32
+ return Qnil;
33
+ else
34
+ {
35
+ DiscId *disc;
36
+ Data_Get_Struct(self, DiscId, disc);
37
+
38
+ return rb_str_new2(discid_get_id(disc));
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Returns a submission URL for the DiscID as a string.
44
+ *
45
+ * Returns nil if no ID was yet read.
46
+ */
47
+ static VALUE mb_discid_submission_url(VALUE self)
48
+ {
49
+ if (rb_iv_get(self, "@read") == Qfalse)
50
+ return Qnil;
51
+ else
52
+ {
53
+ DiscId *disc;
54
+ Data_Get_Struct(self, DiscId, disc);
55
+
56
+ return rb_str_new2(discid_get_submission_url(disc));
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Return a FreeDB DiscID as a string.
62
+ *
63
+ * Returns nil if no ID was yet read.
64
+ */
65
+ static VALUE mb_discid_freedb_id(VALUE self)
66
+ {
67
+ if (rb_iv_get(self, "@read") == Qfalse)
68
+ return Qnil;
69
+ else
70
+ {
71
+ DiscId *disc;
72
+ Data_Get_Struct(self, DiscId, disc);
73
+
74
+ return rb_str_new2(discid_get_freedb_id(disc));
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Return the number of the first track on this disc.
80
+ *
81
+ * Returns nil if no ID was yet read.
82
+ */
83
+ static VALUE mb_discid_first_track_num(VALUE self)
84
+ {
85
+ if (rb_iv_get(self, "@read") == Qfalse)
86
+ return Qnil;
87
+ else
88
+ {
89
+ DiscId *disc;
90
+ Data_Get_Struct(self, DiscId, disc);
91
+
92
+ return INT2FIX(discid_get_first_track_num(disc));
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Return the number of the last track on this disc.
98
+ *
99
+ * Returns nil if no ID was yet read.
100
+ */
101
+ static VALUE mb_discid_last_track_num(VALUE self)
102
+ {
103
+ if (rb_iv_get(self, "@read") == Qfalse)
104
+ return Qnil;
105
+ else
106
+ {
107
+ DiscId *disc;
108
+ Data_Get_Struct(self, DiscId, disc);
109
+
110
+ return INT2FIX(discid_get_last_track_num(disc));
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Return the length of the disc in sectors.
116
+ *
117
+ * Returns nil if no ID was yet read.
118
+ */
119
+ static VALUE mb_discid_sectors(VALUE self)
120
+ {
121
+ if (rb_iv_get(self, "@read") == Qfalse)
122
+ return Qnil;
123
+ else
124
+ {
125
+ DiscId *disc;
126
+ Data_Get_Struct(self, DiscId, disc);
127
+
128
+ return INT2FIX(discid_get_sectors(disc));
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Returns an array of [offset, length] tuples for each track.
134
+ *
135
+ * If a block is given this method returns nil and instead iterates over the
136
+ * block calling the block with two arguments |offset, length|.
137
+ *
138
+ * Returns always nil if no ID was yet read. The block won't be called in
139
+ * this case.
140
+ */
141
+ static VALUE mb_discid_tracks(VALUE self)
142
+ {
143
+ if (rb_iv_get(self, "@read") == Qfalse)
144
+ return Qnil;
145
+ else
146
+ {
147
+ DiscId *disc;
148
+ Data_Get_Struct(self, DiscId, disc);
149
+
150
+ { // Stupid MS compiler.
151
+
152
+ VALUE result = rb_ary_new(); // Array of all [offset, length] tuples
153
+ VALUE tuple; // Array to store one [offset, length] tuple.
154
+ int track = discid_get_first_track_num(disc); // Track number
155
+ while (track <= discid_get_last_track_num(disc))
156
+ {
157
+ tuple = rb_ary_new3(2,
158
+ INT2FIX(discid_get_track_offset(disc, track)),
159
+ INT2FIX(discid_get_track_length(disc, track)) );
160
+
161
+ if (rb_block_given_p())
162
+ rb_yield(tuple);
163
+ else
164
+ rb_ary_push(result, tuple);
165
+
166
+ track++;
167
+ }
168
+
169
+ if (rb_block_given_p())
170
+ return Qnil;
171
+ else
172
+ return result;
173
+
174
+ } // Stupid MS compiler.
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Read the disc ID from the given device.
180
+ *
181
+ * If no device is given the default device of the platform will be used.
182
+ */
183
+ static VALUE mb_discid_read(int argc, VALUE *argv, VALUE self)
184
+ {
185
+ DiscId *disc;
186
+ Data_Get_Struct(self, DiscId, disc);
187
+
188
+ { // Stupid MS compiler.
189
+
190
+ VALUE device = Qnil; // The device string as a Ruby string.
191
+ char* cdevice; // The device string as a C string.
192
+
193
+ // Check the number of arguments
194
+ if (argc > 1)
195
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
196
+ // Convert the given device to a T_STRING
197
+ else if (argc > 0)
198
+ device = rb_funcall(argv[0], rb_intern("to_s"), 0, 0);
199
+
200
+ // Use the default device if none was given.
201
+ if (argc < 1 || RSTRING(device)->len == 0)
202
+ cdevice = discid_get_default_device();
203
+ else
204
+ cdevice = STR2CSTR(device);
205
+
206
+ // Read the discid
207
+ if (discid_read(disc, cdevice) == 0)
208
+ rb_raise(rb_eException, discid_get_error_msg(disc));
209
+ else // Remember that we already read the ID.
210
+ rb_iv_set(self, "@read", Qtrue);
211
+
212
+ return Qnil;
213
+
214
+ } // Stupid MS compiler.
215
+ }
216
+
217
+ /**
218
+ * Construct a new DiscID object.
219
+ *
220
+ * As an optional argument the name of the device to read the ID from
221
+ * may be given. If you don't specify a device here you can later read
222
+ * the ID with the read method.
223
+ */
224
+ VALUE mb_discid_new(int argc, VALUE *argv, VALUE class)
225
+ {
226
+ DiscId *disc = discid_new();
227
+ VALUE tdata = Data_Wrap_Struct(class, 0, discid_free, disc);
228
+ rb_obj_call_init(tdata, 0, 0);
229
+ rb_iv_set(tdata, "@read", Qfalse);
230
+
231
+ // Check the number of arguments
232
+ if (argc > 1)
233
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
234
+ // If a device was given try to read the disc id from this device.
235
+ else if (argc > 0)
236
+ rb_funcall(tdata, rb_intern("read"), 1, argv[0]);
237
+
238
+ return tdata;
239
+ }
240
+
241
+ /**
242
+ * Returns a device string for the default device for this platform.
243
+ */
244
+ VALUE mb_discid_default_device(VALUE class)
245
+ {
246
+ return rb_str_new2(discid_get_default_device());
247
+ }
248
+
249
+ /**
250
+ * Initialize the DiscID class and make it available in Ruby.
251
+ */
252
+ void Init_MB_DiscID() {
253
+ mMusicBrainz = rb_define_module("MusicBrainz");
254
+ cDiscID = rb_define_class_under(mMusicBrainz, "DiscID", rb_cObject);
255
+ rb_define_singleton_method(cDiscID, "new", mb_discid_new, -1);
256
+ rb_define_singleton_method(cDiscID, "default_device",
257
+ mb_discid_default_device, 0);
258
+
259
+ rb_define_method(cDiscID, "read", mb_discid_read, -1);
260
+ rb_define_method(cDiscID, "id", mb_discid_id, 0);
261
+ rb_define_method(cDiscID, "submission_url", mb_discid_submission_url, 0);
262
+ rb_define_method(cDiscID, "freedb_id", mb_discid_freedb_id, 0);
263
+ rb_define_method(cDiscID, "first_track_num", mb_discid_first_track_num, 0);
264
+ rb_define_method(cDiscID, "last_track_num", mb_discid_last_track_num, 0);
265
+ rb_define_method(cDiscID, "sectors", mb_discid_sectors, 0);
266
+ rb_define_method(cDiscID, "tracks", mb_discid_tracks, 0);
267
+ }
data/lib/mb-discid.rb ADDED
@@ -0,0 +1,12 @@
1
+ # $Id:mb-discid.rb 67 2007-06-03 14:09:23Z phw $
2
+ # Copyright (c) 2007, Philipp Wolfer
3
+ # All rights reserved.
4
+ # See LICENSE for permissions.
5
+
6
+ # Just a helper file to allow loading the MB-DiscID library with
7
+ # <tt>require 'mb-discid'</tt>, which is the only recommended way
8
+ # to load the library.
9
+ # This file may even provide extensions to the library in the future
10
+ # to avoid to have to write everything in C.
11
+
12
+ require 'MB_DiscID.so'
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: mb-discid
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.1
7
+ date: 2007-06-03 00:00:00 +02:00
8
+ summary: Ruby bindings for libdiscid.
9
+ require_paths:
10
+ - lib
11
+ - ext
12
+ email: phw@rubyforge.org
13
+ homepage: http://rbrainz.rubyforge.org
14
+ rubyforge_project: rbrainz
15
+ description: Ruby bindings for libdiscid. See http://musicbrainz.org/doc/libdiscid for more information on libdiscid and MusicBrainz.
16
+ autorequire: mb-discid
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: false
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.8.6
25
+ version:
26
+ platform: mswin32
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - Philipp Wolfer
32
+ files:
33
+ - Rakefile
34
+ - LICENSE
35
+ - README
36
+ - examples/discid.rb
37
+ - ext/mb_discid.c
38
+ - ext/extconf.rb
39
+ - lib/mb-discid.rb
40
+ - ext/MB_DiscID.so
41
+ test_files: []
42
+
43
+ rdoc_options: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ requirements:
52
+ - libdiscid (http://musicbrainz.org/doc/libdiscid)
53
+ dependencies: []
54
+