hydra-file_characterization 0.1.3 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +22 -8
- data/lib/hydra/file_characterization.rb +9 -12
- data/lib/hydra/file_characterization/characterizers.rb +2 -1
- data/lib/hydra/file_characterization/characterizers/ffprobe.rb +13 -0
- data/lib/hydra/file_characterization/version.rb +1 -1
- data/spec/lib/hydra/file_characterization/characterizers/ffprobe_spec.rb +19 -0
- data/spec/lib/hydra/file_characterization/characterizers_spec.rb +5 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aa0e27917882868e5356621f163eda7e6ab56a6
|
4
|
+
data.tar.gz: d3114a797679bcd25bc29f19ae31f70659828016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88e44705e2cb908b5732a3f220e90a2544b909834bbe3f96b07ea82c142b31cffaebd38d068493ad84cb0887fe6eec76aeff11e9fd874c116a24fa9295729e3c
|
7
|
+
data.tar.gz: 6932b2860c71bfb3171f0a952021fe0935121b880ea7fcd3aff5b4c5dd47e551143773f154be0e852f5b637f1f22e3a3a1d1949eaea392b38984793017eb7bb2
|
data/README.md
CHANGED
@@ -6,6 +6,28 @@ Hydra::FileCharacterization as (extracted from Sufia and Hydra::Derivatives)
|
|
6
6
|
|
7
7
|
To provide a wrapper for file characterization
|
8
8
|
|
9
|
+
## How To Use
|
10
|
+
|
11
|
+
If you are using Rails add the following to an initializer (./config/initializers/hydra-file_characterization_config.rb):
|
12
|
+
|
13
|
+
Hydra::FileCharacterization.configure do |config|
|
14
|
+
config.tool_path(:fits, '/path/to/fits')
|
15
|
+
end
|
16
|
+
|
17
|
+
To use the characterizer:
|
18
|
+
|
19
|
+
characterization_xml = Hydra.characterize(file.read, file.basename, :fits)
|
20
|
+
|
21
|
+
# This does not work at this point
|
22
|
+
fits_xml, ffprobe_xml = Hydra.characterize(file.read, file.basename, :fits, :ffprobe)
|
23
|
+
|
24
|
+
* Why `file.read`? To highlight that we want a string. In the case of ActiveFedora, we have a StringIO instead of a file.
|
25
|
+
* Why `file.basename`? In the case of Fits, the characterization takes cues from the extension name.
|
26
|
+
|
27
|
+
## Registering New Characterizers
|
28
|
+
|
29
|
+
This is possible by adding a characterizer to the `Hydra::FileCharacterization::Characterizers`' namespace.
|
30
|
+
|
9
31
|
## To Consider
|
10
32
|
|
11
33
|
How others are using the extract_metadata method
|
@@ -22,11 +44,3 @@ How others are using the extract_metadata method
|
|
22
44
|
- Allow characterization services to be chained together
|
23
45
|
- ~~This would involve renaming the Characterizer to something else (i.e. Characterizers::Fits)~~
|
24
46
|
- Provide an ActiveFedora Datastream that maps the raw XML stream to a datastructure
|
25
|
-
|
26
|
-
## How to configure path to fits tool
|
27
|
-
|
28
|
-
If you are using Rails add the following to an initializer (./config/initializers/hydra-file_characterization_config.rb):
|
29
|
-
|
30
|
-
Hydra::FileCharacterization.configure do |config|
|
31
|
-
config.tool_path(:fits, '/path/to/fits')
|
32
|
-
end
|
@@ -35,23 +35,20 @@ module Hydra
|
|
35
35
|
|
36
36
|
module FileCharacterization
|
37
37
|
|
38
|
-
class
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
class << self
|
39
|
+
attr_accessor :configuration
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.configure
|
43
|
+
self.configuration ||= Configuration.new
|
44
|
+
yield(configuration)
|
45
|
+
end
|
42
46
|
|
47
|
+
class Configuration
|
43
48
|
def tool_path(tool_name, tool_path)
|
44
49
|
Hydra::FileCharacterization.characterizer(tool_name).tool_path = tool_path
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
|
-
module_function
|
49
|
-
def configuration
|
50
|
-
@configuration ||= Configuration.new
|
51
|
-
end
|
52
|
-
|
53
|
-
def configure(&block)
|
54
|
-
configuration.configure(&block)
|
55
|
-
end
|
56
53
|
end
|
57
54
|
end
|
@@ -15,7 +15,7 @@ module Hydra::FileCharacterization
|
|
15
15
|
def characterizer_name_from(tool_name)
|
16
16
|
tool_name.to_s.gsub(/(?:^|_)([a-z])/) { $1.upcase }
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def characterize_with(tool_name, file_path)
|
20
20
|
tool_obj = characterizer(tool_name).new(file_path)
|
21
21
|
tool_obj.call
|
@@ -24,3 +24,4 @@ module Hydra::FileCharacterization
|
|
24
24
|
end
|
25
25
|
|
26
26
|
require 'hydra/file_characterization/characterizers/fits'
|
27
|
+
require 'hydra/file_characterization/characterizers/ffprobe'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'hydra/file_characterization/exceptions'
|
2
|
+
require 'hydra/file_characterization/characterizer'
|
3
|
+
|
4
|
+
module Hydra::FileCharacterization::Characterizers
|
5
|
+
class Ffprobe < Hydra::FileCharacterization::Characterizer
|
6
|
+
|
7
|
+
protected
|
8
|
+
def command
|
9
|
+
"#{tool_path} -i \"#{filename}\" -print_format xml -show_streams -v quiet"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'hydra/file_characterization/characterizers/ffprobe'
|
3
|
+
|
4
|
+
module Hydra::FileCharacterization::Characterizers
|
5
|
+
|
6
|
+
describe Ffprobe do
|
7
|
+
|
8
|
+
subject { Ffprobe.new(filename) }
|
9
|
+
|
10
|
+
describe 'invalidFile' do
|
11
|
+
let(:filename) { fixture_file('nofile.pdf') }
|
12
|
+
it "should raise an error if the path does not contain the file" do
|
13
|
+
expect {subject.call}.to raise_error(Hydra::FileCharacterization::FileNotFoundError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra-file_characterization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Treacy
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/hydra/file_characterization.rb
|
92
92
|
- lib/hydra/file_characterization/characterizer.rb
|
93
93
|
- lib/hydra/file_characterization/characterizers.rb
|
94
|
+
- lib/hydra/file_characterization/characterizers/ffprobe.rb
|
94
95
|
- lib/hydra/file_characterization/characterizers/fits.rb
|
95
96
|
- lib/hydra/file_characterization/exceptions.rb
|
96
97
|
- lib/hydra/file_characterization/to_temp_file.rb
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- spec/fixtures/brendan_behan.jpeg.fits.xml
|
102
103
|
- spec/fixtures/brendan_broken.dxxd
|
103
104
|
- spec/fixtures/brendan_broken.dxxd.fits.xml
|
105
|
+
- spec/lib/hydra/file_characterization/characterizers/ffprobe_spec.rb
|
104
106
|
- spec/lib/hydra/file_characterization/characterizers/fits_spec.rb
|
105
107
|
- spec/lib/hydra/file_characterization/characterizers_spec.rb
|
106
108
|
- spec/lib/hydra/file_characterization/to_temp_file_spec.rb
|
@@ -137,6 +139,7 @@ test_files:
|
|
137
139
|
- spec/fixtures/brendan_behan.jpeg.fits.xml
|
138
140
|
- spec/fixtures/brendan_broken.dxxd
|
139
141
|
- spec/fixtures/brendan_broken.dxxd.fits.xml
|
142
|
+
- spec/lib/hydra/file_characterization/characterizers/ffprobe_spec.rb
|
140
143
|
- spec/lib/hydra/file_characterization/characterizers/fits_spec.rb
|
141
144
|
- spec/lib/hydra/file_characterization/characterizers_spec.rb
|
142
145
|
- spec/lib/hydra/file_characterization/to_temp_file_spec.rb
|