2 * Copyright (c) 2007 Tilman Sauerbeck (tilman at code-monkey de)
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include <discid/discid.h>
32 static VALUE eReadError;
41 discid_free (o->real);
51 return Data_Make_Struct (klass, RbDiscID, NULL, c_free, o);
56 * DiscID.default_device -> string
58 * Returns the default device that's used in DiscID::DiscID.read if
59 * the device isn't specified explicitly.
62 m_default_device (VALUE self)
64 return rb_str_new2 (discid_get_default_device ());
69 * DiscID::DiscID.read([device]) -> object
71 * Read the disc id from the medium in the given device.
72 * If the argument is ommitted, DiscID.default_device is used instead.
75 c_read (int argc, VALUE *argv, VALUE klass)
82 rb_scan_args (argc, argv, "01", &device);
85 cdev = StringValuePtr (device);
87 self = rb_class_new_instance (0, NULL, klass);
89 Data_Get_Struct (self, RbDiscID, o);
91 s = discid_read (o->real, cdev);
93 rb_raise (eReadError, discid_get_error_msg (o->real));
103 Data_Get_Struct (self, RbDiscID, o);
105 o->real = discid_new ();
112 * discid.id -> string
114 * Returns the MusicBrainz disc id.
122 Data_Get_Struct (self, RbDiscID, o);
124 s = discid_get_id (o->real);
126 return rb_str_new2 (s);
131 * discid.submission_url -> string
133 * Returns the submission url for the disc id.
136 c_submission_url (VALUE self)
141 Data_Get_Struct (self, RbDiscID, o);
143 s = discid_get_submission_url (o->real);
145 return rb_str_new2 (s);
150 * discid.freedb_id -> string
152 * Returns the FreeDB disc id.
155 c_freedb_id (VALUE self)
160 Data_Get_Struct (self, RbDiscID, o);
162 s = discid_get_freedb_id (o->real);
164 return rb_str_new2 (s);
168 Init_discid_ext (void)
173 m = rb_define_module ("DiscID");
174 c = rb_define_class_under (m, "DiscID", rb_cObject);
176 rb_define_alloc_func (c, c_alloc);
178 rb_define_module_function (m, "default_device", m_default_device, 0);
179 rb_define_singleton_method (c, "read", c_read, -1);
180 rb_define_method (c, "initialize", c_init, 0);
181 rb_define_method (c, "id", c_id, 0);
182 rb_define_method (c, "submission_url", c_submission_url, 0);
183 rb_define_method (c, "freedb_id", c_freedb_id, 0);
185 eDiscIDError = rb_define_class_under (m, "DiscIDError", rb_eStandardError);
186 eReadError = rb_define_class_under (m, "ReadError", eDiscIDError);