rtaglib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ require "mkmf"
2
+ $CFLAGS+=" -WAll"
3
+ dir_config("tag_c")
4
+ if have_library("tag_c") and have_header("taglib/tag_c.h")
5
+ #$CFLAGS+=`pkg-config --cflags taglib`
6
+ create_makefile("rtaglib")
7
+ else
8
+ print "*** ERROR: Need taglib library\n"
9
+ end
@@ -0,0 +1,23 @@
1
+ have_library: checking for main() in -ltag_c... -------------------- yes
2
+
3
+ "i686-pc-linux-gnu-gcc -o conftest -I/home/cdx/ruby/rtaglib/ext -I/usr/lib/ruby/1.8/i686-linux -O2 -march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -pipe -ffast-math -fPIC -WAll conftest.c -L'/usr/lib' -Wl,-R'/usr/lib' -lruby18-static -ltag_c -ldl -lcrypt -lm -lc"
4
+ checked program was:
5
+ /* begin */
6
+
7
+ /*top*/
8
+ int main() { return 0; }
9
+ int t() { main(); return 0; }
10
+ /* end */
11
+
12
+ --------------------
13
+
14
+ have_header: checking for taglib/tag_c.h... -------------------- yes
15
+
16
+ "i686-pc-linux-gnu-gcc -E -I/home/cdx/ruby/rtaglib/ext -I/usr/lib/ruby/1.8/i686-linux -O2 -march=athlon-xp -m3dnow -msse -mfpmath=sse -mmmx -pipe -ffast-math -fPIC -WAll conftest.c -o conftest.i"
17
+ checked program was:
18
+ /* begin */
19
+ #include <taglib/tag_c.h>
20
+ /* end */
21
+
22
+ --------------------
23
+
@@ -0,0 +1,356 @@
1
+ #include <ruby.h>
2
+ #include <taglib/tag_c.h>
3
+ #define GET_TL_TAG(self,tag) \
4
+ taglib_t *tl; \
5
+ Data_Get_Struct(self, taglib_t, tl); \
6
+ if(NULL==tl->file || tl->open==0) {tl_closed();} \
7
+ TagLib_Tag *tag=tl->tag;
8
+
9
+ #define GET_TL_CHECK(self,file) \
10
+ taglib_t *tl; \
11
+ Data_Get_Struct(self, taglib_t, tl); \
12
+ if(NULL==tl->file || tl->open==0) {tl_closed();} \
13
+ TagLib_File *file=tl->file;
14
+
15
+ typedef struct {
16
+ TagLib_File *file;
17
+ TagLib_Tag *tag;
18
+ const TagLib_AudioProperties *audio;
19
+ int open;
20
+ } taglib_t;
21
+
22
+ void
23
+ tl_closed()
24
+ {
25
+ rb_raise(rb_eException, "FileTag already closed");
26
+ }
27
+
28
+ static void
29
+ _tag_lib_file_free(taglib_t * t)
30
+ {
31
+ taglib_file_free(t->file);
32
+ free(t);
33
+ }
34
+
35
+
36
+ VALUE mTagFile;
37
+ VALUE cTagFileFile;
38
+ VALUE eBadPath;
39
+ VALUE eBadFile;
40
+ VALUE eBadTag;
41
+ VALUE eBadAudioProperties;
42
+
43
+ VALUE cTagFileFile_new(int argc, VALUE * argv, VALUE class);
44
+ VALUE cTagFileFile_close(VALUE self);
45
+ VALUE cTagFileFile_save(VALUE self);
46
+ VALUE cTagFileFile_init(VALUE self, VALUE path, VALUE file_type);
47
+ VALUE cTagFileFile_title(VALUE self);
48
+ VALUE cTagFileFile_artist(VALUE self);
49
+ VALUE cTagFileFile_album(VALUE self);
50
+ VALUE cTagFileFile_comment(VALUE self);
51
+ VALUE cTagFileFile_genre(VALUE self);
52
+ VALUE cTagFileFile_year(VALUE self);
53
+ VALUE cTagFileFile_track(VALUE self);
54
+
55
+ VALUE cTagFileFile_title_set(VALUE self, VALUE valor);
56
+ VALUE cTagFileFile_artist_set(VALUE self, VALUE valor);
57
+ VALUE cTagFileFile_album_set(VALUE self, VALUE valor);
58
+ VALUE cTagFileFile_comment_set(VALUE self, VALUE valor);
59
+ VALUE cTagFileFile_genre_set(VALUE self, VALUE valor);
60
+ VALUE cTagFileFile_year_set(VALUE self, VALUE valor);
61
+ VALUE cTagFileFile_track_set(VALUE self, VALUE valor);
62
+
63
+ VALUE cTagFileFile_length(VALUE self);
64
+ VALUE cTagFileFile_bitrate(VALUE self);
65
+ VALUE cTagFileFile_samplerate(VALUE self);
66
+ VALUE cTagFileFile_channels(VALUE self);
67
+
68
+
69
+ void
70
+ Init_rtaglib()
71
+ {
72
+ mTagFile = rb_define_module("TagFile");
73
+ cTagFileFile = rb_define_class_under(mTagFile, "File", rb_cObject);
74
+ eBadPath = rb_define_class_under(mTagFile, "BadPath", rb_eIOError);
75
+ eBadFile = rb_define_class_under(mTagFile, "BadFile", rb_eException);
76
+ eBadTag = rb_define_class_under(mTagFile, "BadTag", rb_eException);
77
+ eBadAudioProperties =
78
+ rb_define_class_under(mTagFile, "BadAudioProperties",
79
+ rb_eException);
80
+ rb_define_singleton_method(cTagFileFile, "new", cTagFileFile_new, -1);
81
+ rb_define_method(cTagFileFile, "initialize", cTagFileFile_init, 2);
82
+ rb_define_method(cTagFileFile, "save", cTagFileFile_save, 0);
83
+ rb_define_method(cTagFileFile, "close", cTagFileFile_close, 0);
84
+
85
+ struct {
86
+ const char *name;
87
+ VALUE(*func) ();
88
+ int args;
89
+ } instance_methods[] = {
90
+ {
91
+ "title", cTagFileFile_title, 0}, {
92
+ "title=", cTagFileFile_title_set, 1}, {
93
+ "artist", cTagFileFile_artist, 0}, {
94
+ "artist=", cTagFileFile_artist_set, 1}, {
95
+ "album", cTagFileFile_album, 0}, {
96
+ "album=", cTagFileFile_album_set, 1}, {
97
+ "comment", cTagFileFile_comment, 0}, {
98
+ "comment=", cTagFileFile_comment_set, 1}, {
99
+ "genre", cTagFileFile_genre, 0}, {
100
+ "genre=", cTagFileFile_genre_set, 0}, {
101
+ "track", cTagFileFile_track, 0}, {
102
+ "track=", cTagFileFile_track_set, 1}, {
103
+ "year", cTagFileFile_year, 0}, {
104
+ "year=", cTagFileFile_year, 1}, {
105
+ "length", cTagFileFile_length, 0}, {
106
+ "bitrate", cTagFileFile_bitrate, 0}, {
107
+ "samplerate", cTagFileFile_samplerate, 0}, {
108
+ "channels", cTagFileFile_channels, 0}, {
109
+ 0, NULL, 0}
110
+ };
111
+ int i = 0;
112
+ for (i = 0; instance_methods[i].name; i++) {
113
+ rb_define_method(cTagFileFile, instance_methods[i].name,
114
+ instance_methods[i].func,
115
+ instance_methods[i].args);
116
+ }
117
+ rb_define_attr(cTagFileFile, "path", 1, 0);
118
+ rb_define_attr(cTagFileFile, "file_type", 1, 0);
119
+ rb_define_const(mTagFile, "MPEG", INT2FIX(TagLib_File_MPEG));
120
+ rb_define_const(mTagFile, "OggVorbis", INT2FIX(TagLib_File_OggVorbis));
121
+ rb_define_const(mTagFile, "FLAC", INT2FIX(TagLib_File_FLAC));
122
+ rb_define_const(mTagFile, "MPC", INT2FIX(TagLib_File_MPC));
123
+ }
124
+
125
+ VALUE
126
+ cTagFileFile_new(int argc, VALUE * argv, VALUE class)
127
+ {
128
+ TagLib_File *tlf;
129
+ VALUE path;
130
+ VALUE file_type;
131
+ char *cpath;
132
+ rb_scan_args(argc, argv, "11", &path, &file_type);
133
+ Check_Type(path, T_STRING);
134
+ SafeStringValue(path);
135
+ cpath = StringValuePtr(path);
136
+ if (file_type != Qnil) {
137
+ FIXNUM_P(file_type);
138
+ tlf = taglib_file_new_type(cpath, FIX2INT(file_type));
139
+ } else {
140
+ tlf = taglib_file_new(cpath);
141
+ }
142
+ if (NULL == tlf) {
143
+ rb_raise(eBadFile, "Bad file");
144
+ return Qnil;
145
+ } else {
146
+ taglib_t *tl = ALLOC(taglib_t);
147
+ tl->file = tlf;
148
+ tl->tag = taglib_file_tag(tlf);
149
+ tl->open = 1;
150
+ if (NULL == tl->tag) {
151
+ rb_raise(eBadTag, "Bad Tag");
152
+ }
153
+ tl->audio = taglib_file_audioproperties(tlf);
154
+ if (NULL == tl->tag) {
155
+ rb_raise(eBadAudioProperties, "Bad Audio");
156
+ }
157
+ VALUE c_argv[2];
158
+ VALUE tdata =
159
+ Data_Wrap_Struct(class, 0, _tag_lib_file_free, tl);
160
+ c_argv[0] = path;
161
+ c_argv[1] = file_type;
162
+ rb_obj_call_init(tdata, 2, c_argv);
163
+ return tdata;
164
+ }
165
+ }
166
+
167
+ VALUE
168
+ cTagFileFile_init(VALUE self, VALUE path, VALUE file_type)
169
+ {
170
+ Check_Type(path, T_STRING);
171
+ rb_iv_set(self, "@path", path);
172
+ rb_iv_set(self, "@file_type", file_type);
173
+ return self;
174
+ }
175
+
176
+ VALUE
177
+ cTagFileFile_save(VALUE self)
178
+ {
179
+ GET_TL_CHECK(self, file);
180
+ return (taglib_file_save(file) ? Qtrue : Qfalse);
181
+ }
182
+ VALUE
183
+ cTagFileFile_close(VALUE self)
184
+ {
185
+ taglib_t *tl;
186
+ Data_Get_Struct(self, taglib_t, tl);
187
+ tl->open = 0;
188
+ // taglib_file_free(tl->file);
189
+ rb_iv_set(self, "@path", Qnil);
190
+ rb_iv_set(self, "@file_type", Qnil);
191
+ return Qtrue;
192
+ }
193
+ VALUE
194
+ _get_string(VALUE self, char *(*func) ())
195
+ {
196
+ VALUE string;
197
+ GET_TL_TAG(self, tag);
198
+ char *cstring = func(tag);
199
+ string = rb_str_new2(cstring);
200
+ taglib_tag_free_strings();
201
+ return string;
202
+ }
203
+
204
+ VALUE
205
+ _get_uint(VALUE self, unsigned int (*func) ())
206
+ {
207
+ GET_TL_TAG(self, tag);
208
+ return INT2FIX(func(tag));
209
+ }
210
+
211
+ VALUE
212
+ _get_audio_int(VALUE self, int (*func) ())
213
+ {
214
+ VALUE string;
215
+ taglib_t *tl;
216
+ Data_Get_Struct(self, taglib_t, tl);
217
+ if (NULL == tl->file) {
218
+ return Qnil;
219
+ } else {
220
+ return INT2FIX(func(tl->audio));
221
+ }
222
+ }
223
+
224
+
225
+ VALUE
226
+ _set_string(VALUE self, void (*func) (TagLib_Tag *, const char *),
227
+ VALUE texto)
228
+ {
229
+ VALUE string;
230
+ taglib_t *tl;
231
+ Data_Get_Struct(self, taglib_t, tl);
232
+ if (NULL == tl) {
233
+ return Qnil;
234
+ } else {
235
+ Check_Type(texto, T_STRING);
236
+ func(tl->tag, StringValuePtr(texto));
237
+ return Qtrue;
238
+ }
239
+ }
240
+
241
+ VALUE
242
+ _set_uint(VALUE self, void (*func) (TagLib_Tag *, unsigned int),
243
+ VALUE numero)
244
+ {
245
+ VALUE string;
246
+ taglib_t *tl;
247
+ Data_Get_Struct(self, taglib_t, tl);
248
+ if (NULL == tl) {
249
+ return Qnil;
250
+ } else {
251
+ FIXNUM_P(numero);
252
+ func(tl->tag, FIX2INT(numero));
253
+ return Qtrue;
254
+ }
255
+ }
256
+
257
+ VALUE
258
+ cTagFileFile_title(VALUE self)
259
+ {
260
+ return _get_string(self, taglib_tag_title);
261
+ }
262
+
263
+ VALUE
264
+ cTagFileFile_artist(VALUE self)
265
+ {
266
+ return _get_string(self, taglib_tag_artist);
267
+ }
268
+
269
+ VALUE
270
+ cTagFileFile_album(VALUE self)
271
+ {
272
+ return _get_string(self, taglib_tag_album);
273
+ }
274
+ VALUE
275
+ cTagFileFile_comment(VALUE self)
276
+ {
277
+ return _get_string(self, taglib_tag_comment);
278
+ }
279
+ VALUE
280
+ cTagFileFile_genre(VALUE self)
281
+ {
282
+ return _get_string(self, taglib_tag_genre);
283
+ }
284
+
285
+ VALUE
286
+ cTagFileFile_year(VALUE self)
287
+ {
288
+ return _get_uint(self, taglib_tag_year);
289
+ }
290
+ VALUE
291
+ cTagFileFile_track(VALUE self)
292
+ {
293
+ return _get_uint(self, taglib_tag_track);
294
+ }
295
+
296
+ VALUE
297
+ cTagFileFile_title_set(VALUE self, VALUE valor)
298
+ {
299
+ return _set_string(self, taglib_tag_set_title, valor);
300
+ }
301
+
302
+ VALUE
303
+ cTagFileFile_artist_set(VALUE self, VALUE valor)
304
+ {
305
+ return _set_string(self, taglib_tag_set_artist, valor);
306
+ }
307
+
308
+ VALUE
309
+ cTagFileFile_album_set(VALUE self, VALUE valor)
310
+ {
311
+ return _set_string(self, taglib_tag_set_album, valor);
312
+ }
313
+ VALUE
314
+ cTagFileFile_comment_set(VALUE self, VALUE valor)
315
+ {
316
+ return _set_string(self, taglib_tag_set_comment, valor);
317
+ }
318
+ VALUE
319
+ cTagFileFile_genre_set(VALUE self, VALUE valor)
320
+ {
321
+ return _set_string(self, taglib_tag_set_genre, valor);
322
+ }
323
+
324
+ VALUE
325
+ cTagFileFile_year_set(VALUE self, VALUE valor)
326
+ {
327
+ return _set_uint(self, taglib_tag_set_year, valor);
328
+ }
329
+ VALUE
330
+ cTagFileFile_track_set(VALUE self, VALUE valor)
331
+ {
332
+ return _set_uint(self, taglib_tag_set_track, valor);
333
+ }
334
+
335
+ VALUE
336
+ cTagFileFile_length(VALUE self)
337
+ {
338
+ return _get_audio_int(self, taglib_audioproperties_length);
339
+ }
340
+
341
+ VALUE
342
+ cTagFileFile_bitrate(VALUE self)
343
+ {
344
+ return _get_audio_int(self, taglib_audioproperties_bitrate);
345
+ }
346
+ VALUE
347
+ cTagFileFile_samplerate(VALUE self)
348
+ {
349
+ return _get_audio_int(self, taglib_audioproperties_samplerate);
350
+ }
351
+ VALUE
352
+ cTagFileFile_channels(VALUE self)
353
+ {
354
+ return _get_audio_int(self, taglib_audioproperties_channels);
355
+ }
356
+
@@ -0,0 +1 @@
1
+
Binary file
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require_gem 'rtaglib'
4
+ require 'test/unit'
5
+ class RtaglibTestCase < Test::Unit::TestCase
6
+
7
+ def initialize(*args)
8
+ super
9
+ @file=::TagFile::File.new(File.dirname(__FILE__)+"/saw.mp3")
10
+ end
11
+
12
+ end
13
+
14
+ # arch-tag: test
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: rtaglib
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2005-12-30 00:00:00 -03:00
8
+ summary: Bindings for taglib
9
+ require_paths:
10
+ - lib
11
+ email:
12
+ homepage: http://rtaglib.rubyforge.org
13
+ rubyforge_project: rtaglib
14
+ description: "Rtaglib is a C based binding for Taglib's library
15
+ (http://developer.kde.org/~wheeler/taglib.html). Uses the same interface of
16
+ ruby-taglib, but creates a true ruby extension."
17
+ autorequire: rtaglib
18
+ default_executable:
19
+ bindir: bin
20
+ has_rdoc: false
21
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
22
+ requirements:
23
+ -
24
+ - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ version:
28
+ platform: ruby
29
+ signing_key:
30
+ cert_chain:
31
+ authors:
32
+ - Claudio Bustos
33
+ files:
34
+ - "./ext"
35
+ - "./tests"
36
+ - "./ext/extconf.rb"
37
+ - "./ext/rtaglib.c"
38
+ - "./ext/mkmf.log"
39
+ - "./ext/test.rb"
40
+ - "./tests/saw.mp3"
41
+ - "./tests/test_audioinfo.rb"
42
+ - tests/saw.mp3
43
+ - tests/test_audioinfo.rb
44
+ - ext/extconf.rb
45
+ - ext/rtaglib.c
46
+ - ext/mkmf.log
47
+ - ext/test.rb
48
+ test_files: []
49
+ rdoc_options: []
50
+ extra_rdoc_files: []
51
+ executables: []
52
+ extensions:
53
+ - ext/extconf.rb
54
+ requirements:
55
+ - libtag >=1.4
56
+ dependencies: []