rbpod 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,21 @@ require 'mkmf'
3
3
  # Fail immediately if we don't have libgpod-1.0 installed here.
4
4
  abort "Please install libgpod-1.0" unless pkg_config('libgpod-1.0')
5
5
 
6
+ puts "Taglib is not installed; ID3 tag parsing disabled." unless pkg_config('taglib_c')
7
+
6
8
  # Unfortunately, rdoc isn't capable of a lot of things.
7
9
  $defs.push("-DRDOC_CAN_PARSE_DOCUMENTATION=0")
8
10
 
9
11
  # Provide HAVE_STDDEF_H to the pre-processor.
10
12
  have_header('stddef.h')
11
13
 
14
+ # Provide HAVE_SYS_STAT_H to the pre-processor.
15
+ have_header('sys/stat.h')
16
+
12
17
  # Provide HAVE_GPOD_ITDB_H to the pre-processor.
13
18
  have_header('gpod/itdb.h')
14
19
 
20
+ # Provide HAVE_TAGLIB_TAG_C_H to the pre-processor.
21
+ have_header('taglib/tag_c.h')
22
+
15
23
  create_makefile('rbpod/rbpod')
@@ -9,10 +9,18 @@
9
9
  #include <stddef.h>
10
10
  #endif
11
11
 
12
+ #ifdef HAVE_SYS_STAT_H
13
+ #include <sys/stat.h>
14
+ #endif
15
+
12
16
  #ifdef HAVE_GPOD_ITDB_H
13
17
  #include <gpod/itdb.h>
14
18
  #endif
15
19
 
20
+ #ifdef HAVE_TAGLIB_TAG_C_H
21
+ #include <taglib/tag_c.h>
22
+ #endif
23
+
16
24
  /* Pre-processor macros. */
17
25
  #include "macros.h"
18
26
 
@@ -200,6 +200,69 @@ static VALUE rbpod_track_mark_unplayed_set(VALUE self, VALUE value)
200
200
  return Qnil;
201
201
  }
202
202
 
203
+ /*
204
+ * :nodoc:
205
+ */
206
+ static inline gchar *ensure_string(const gchar *buffer)
207
+ {
208
+ return (buffer == NULL || buffer[0] == '\0') ? NULL : g_strdup(buffer);
209
+ }
210
+
211
+ /*
212
+ * call-seq:
213
+ * parse!(source) -> RbPod::Track
214
+ *
215
+ * Parses a given file +source+, attempts to extract ID3 tags, and returns an RbPod::Track.
216
+ */
217
+ static VALUE rbpod_track_parse(VALUE klass, VALUE source)
218
+ {
219
+ VALUE self = rb_class_new_instance(1, &source, klass);
220
+ #ifdef HAVE_TAGLIB_TAG_C_H
221
+ Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
222
+ const TagLib_AudioProperties *properties = NULL;
223
+ TagLib_File *media = NULL;
224
+ TagLib_Tag *tag = NULL;
225
+ struct stat buffer;
226
+
227
+ taglib_set_strings_unicode(FALSE);
228
+
229
+ media = taglib_file_new(track->userdata);
230
+
231
+ if (media == NULL || taglib_file_is_valid(media) == FALSE) {
232
+ rb_raise(eRbPodError, "Track is invalid or does not have an ID3 tag.");
233
+ return Qnil;
234
+ }
235
+
236
+ if (stat(track->userdata, &buffer) == -1) {
237
+ rb_raise(eRbPodError, "Unable to stat() track; it probably doesn't exist.");
238
+ return Qnil;
239
+ }
240
+
241
+ track->size = buffer.st_size;
242
+
243
+ tag = taglib_file_tag(media);
244
+ properties = taglib_file_audioproperties(media);
245
+
246
+ track->title = ensure_string(taglib_tag_title(tag));
247
+ track->artist = ensure_string(taglib_tag_artist(tag));
248
+ track->album = ensure_string(taglib_tag_album(tag));
249
+ track->genre = ensure_string(taglib_tag_genre(tag));
250
+ track->comment = ensure_string(taglib_tag_comment(tag));
251
+
252
+ track->year = taglib_tag_year(tag);
253
+ track->track_nr = taglib_tag_track(tag);
254
+
255
+ track->bitrate = taglib_audioproperties_bitrate(properties);
256
+ track->samplerate = taglib_audioproperties_samplerate(properties);
257
+ track->tracklen = taglib_audioproperties_length(properties) * 1000;
258
+
259
+ taglib_tag_free_strings();
260
+ taglib_file_free(media);
261
+ #endif
262
+ return self;
263
+ }
264
+
265
+
203
266
  /*
204
267
  * call-seq:
205
268
  * initialize(source = nil) -> RbPod::Track
@@ -258,6 +321,8 @@ void Init_rbpod_track(void)
258
321
 
259
322
  rb_define_alloc_func(cRbPodTrack, rbpod_track_allocate);
260
323
 
324
+ rb_define_singleton_method(cRbPodTrack, "parse!", rbpod_track_parse, 1);
325
+
261
326
  rb_define_method(cRbPodTrack, "initialize", rbpod_track_initialize, -1);
262
327
 
263
328
  sMEDIA_TYPE_AUDIO_VIDEO = rb_intern("MEDIA_TYPE_AUDIO_VIDEO");
@@ -1,3 +1,3 @@
1
1
  module RbPod # :nodoc:
2
- VERSION = "0.0.7" # :nodoc:
2
+ VERSION = "0.0.8" # :nodoc:
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbpod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-28 00:00:00.000000000 Z
12
+ date: 2014-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 696726817
167
+ hash: -513999085
168
168
  required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: 696726817
176
+ hash: -513999085
177
177
  requirements:
178
178
  - libgpod-1.0
179
179
  rubyforge_project: