extractor 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,10 @@
1
+ This is a simple binding for libextractor http://gnunet.org/libextractor/.
2
+ It allows you to read metadata from a wide number of file types.
3
+
4
+ It can be used this way
5
+ require 'extractor'
6
+ metadata = Extractor.extract('happy.mp3')
7
+ puts metadata['mimetype']
8
+ puts metadata['artist']
9
+ Sometimes there will be more than one entry for a metadata type. For example, an mp3 may have two artists. If this is the case then you might have
10
+ metadata['artist'] == ['Puff Daddy', 'The Family']
@@ -0,0 +1,61 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'fileutils'
7
+ include FileUtils
8
+
9
+ CLEAN.add %w{ extractor.o }
10
+ CLOBBER.add %w{ Makefile mkmf.log extractor.bundle }
11
+
12
+ PKGFILES = FileList.new
13
+ PKGFILES.add %w{ README Rakefile extconf.rb extractor.c test/*}
14
+
15
+ file "Makefile" do |t|
16
+ ruby "extconf.rb"
17
+ end
18
+
19
+ task :default => [:compile, :test]
20
+
21
+ desc "Compile the code"
22
+ task :compile => ["Makefile"] do |t|
23
+ sh 'make'
24
+ end
25
+
26
+ Rake::RDocTask.new do |rd|
27
+ rd.main = "README"
28
+ rd.rdoc_files = Rake::FileList['README', 'extractor.c']
29
+ end
30
+
31
+ Rake::TestTask.new do |t|
32
+ t.test_files = ['test/test.rb']
33
+ t.verbose = true
34
+ end
35
+
36
+ spec = Gem::Specification.new do |s|
37
+ s.summary = "A binding for libextractor; allows you to read metadata from a number of file types."
38
+ s.name = 'extractor'
39
+ s.author = 'Ry Dahl'
40
+ s.email = 'ry@tinyclouds.org'
41
+ s.version = '0.1'
42
+
43
+ s.rubyforge_project = 'extractor'
44
+
45
+ s.has_rdoc = true
46
+ s.extra_rdoc_files = ['README', 'extractor.c']
47
+
48
+ s.test_files = ['test/test.rb']
49
+
50
+ s.extensions = ['extconf.rb']
51
+
52
+ #s.requirements << 'extractor'
53
+ s.require_path = '.'
54
+ s.autorequire = 'rake'
55
+
56
+ s.files = PKGFILES.to_a
57
+ end
58
+
59
+ Rake::GemPackageTask.new(spec) do |pkg|
60
+ pkg.need_zip = true
61
+ end
@@ -0,0 +1,7 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("libextractor")
4
+
5
+ if have_library('extractor') and have_header('extractor.h')
6
+ create_makefile ('extractor')
7
+ end
@@ -0,0 +1,46 @@
1
+ #include <ruby.h>
2
+ #include <extractor.h>
3
+
4
+ EXTRACTOR_ExtractorList *rb_extractor_libraries;
5
+
6
+ /* Extracts from the filename parameter a hash of metadata. */
7
+ VALUE rb_extractor_extract(VALUE module, VALUE filename)
8
+ {
9
+ EXTRACTOR_KeywordList *keywords, *k;
10
+ VALUE new_value, old_value, hash_key, hash = rb_hash_new();
11
+
12
+
13
+ keywords = EXTRACTOR_getKeywords(rb_extractor_libraries, STR2CSTR(filename));
14
+
15
+ for(k = keywords; k; k = k->next) {
16
+ hash_key = rb_str_new2(EXTRACTOR_getKeywordTypeAsString(k->keywordType));
17
+ old_value = rb_hash_aref(hash, hash_key);
18
+ new_value = rb_str_new2(k->keyword);
19
+
20
+ // if there is no value yet, then set it
21
+ if(TYPE(old_value) == T_NIL) {
22
+ rb_hash_aset(hash, hash_key, new_value);
23
+
24
+ // if we have a string, then create an array with both values
25
+ } else if(TYPE(old_value) == T_STRING) {
26
+ rb_hash_aset(hash, hash_key,
27
+ rb_ary_new3(2, old_value, new_value));
28
+
29
+ // if we have an array already, add the new value
30
+ } else {
31
+ rb_ary_push(old_value, new_value);
32
+ }
33
+ }
34
+
35
+ EXTRACTOR_freeKeywords(keywords);
36
+
37
+ return hash;
38
+ }
39
+
40
+ void Init_extractor ()
41
+ {
42
+ VALUE mExtractor;
43
+ rb_extractor_libraries = EXTRACTOR_loadDefaultLibraries();
44
+ mExtractor = rb_define_module("Extractor");
45
+ rb_define_module_function (mExtractor, "extract", rb_extractor_extract, 1);
46
+ }
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../extractor'
3
+
4
+ class BasicTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @mp3_filename = File.dirname(__FILE__) + '/things_fall_apart.mp3'
8
+ end
9
+
10
+ def test_extract_types
11
+ metadata = Extractor.extract(@mp3_filename)
12
+
13
+ metadata.each do |type, keyword|
14
+ assert_kind_of( String, type )
15
+ if keyword.kind_of?(Array)
16
+ keyword.each { |k| assert_kind_of( String, k ) }
17
+ else
18
+ assert_kind_of( String, keyword )
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+
25
+ def test_extract
26
+ metadata = Extractor.extract(@mp3_filename)
27
+ assert_equal(metadata['mimetype'], 'audio/mpeg')
28
+ assert_equal(metadata['artist'], 'The Roots')
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.1
3
+ specification_version: 1
4
+ name: extractor
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2007-02-26 00:00:00 +01:00
8
+ summary: A binding for libextractor; allows you to read metadata from a number of file types.
9
+ require_paths:
10
+ - .
11
+ email: ry@tinyclouds.org
12
+ homepage:
13
+ rubyforge_project: extractor
14
+ description:
15
+ autorequire: rake
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Ry Dahl
31
+ files:
32
+ - README
33
+ - Rakefile
34
+ - extconf.rb
35
+ - extractor.c
36
+ - test/test.rb
37
+ - test/things_fall_apart.mp3
38
+ test_files:
39
+ - test/test.rb
40
+ rdoc_options: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ - extractor.c
45
+ executables: []
46
+
47
+ extensions:
48
+ - extconf.rb
49
+ requirements: []
50
+
51
+ dependencies: []
52
+