Use exempi-d instead of exiftool
This commit is contained in:
parent
1b43c4965d
commit
5243d77d37
1
dub.sdl
1
dub.sdl
|
@ -4,3 +4,4 @@ authors "Les De Ridder"
|
|||
copyright "Copyright © 2016, Les De Ridder"
|
||||
license "NCSA"
|
||||
dependency "dfuse" version="~>0.3.0"
|
||||
dependency "exempi-d" version="~>0.1.0"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"fileVersion": 1,
|
||||
"versions": {
|
||||
"dfuse": {"path":"dfuse"}
|
||||
"dfuse": {"path":"dfuse"},
|
||||
"exempi-d": "0.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,33 +4,71 @@ import std.process;
|
|||
import std.string;
|
||||
import std.algorithm;
|
||||
import std.array;
|
||||
import std.stdio;
|
||||
|
||||
import exempi.xmp;
|
||||
import exempi.xmpconsts;
|
||||
|
||||
import dtagfs.tagprovider;
|
||||
|
||||
class DublinCoreTagProvider : TagProvider
|
||||
{
|
||||
private XmpPtr _xmp;
|
||||
|
||||
override string[] getTags(string path)
|
||||
{
|
||||
//TODO: Make prefixes configurable
|
||||
|
||||
string[] tags;
|
||||
|
||||
tags ~= map!(a => a)(getElementData!"Subject"(path)).array;
|
||||
tags ~= map!(a => "copyright:" ~ a)(getElementData!"Rights"(path)).array;
|
||||
tags ~= map!(a => "relation:" ~ a)(getElementData!"Relation"(path)).array;
|
||||
tags ~= map!(a => "type:" ~ a)(getElementData!"Type"(path)).array;
|
||||
tags ~= getElementData!"subject"(path).map!(a => a).array;
|
||||
tags ~= getElementData!"rights"(path).map!(a => "copyright:" ~ a).array;
|
||||
tags ~= getElementData!"relation"(path).map!(a => "relation:" ~ a).array;
|
||||
tags ~= getElementData!"type"(path).map!(a => "type:" ~ a).array;
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
string[] getElementData(string element)(string path)
|
||||
{
|
||||
//TODO: Use a proper metadata library instead of exiftool
|
||||
string[] data;
|
||||
|
||||
auto exiftool = execute(["exiftool", "-b", "-" ~ element, path]);
|
||||
auto rawData = exiftool.output;
|
||||
auto file = xmp_files_open_new(path.toStringz(), XmpOpenFileOptions.XMP_OPEN_READ);
|
||||
|
||||
return splitLines(rawData);
|
||||
xmp_files_get_xmp(file, _xmp);
|
||||
|
||||
auto iterator = xmp_iterator_new(_xmp, NS_DC.ptr, element, XmpIterOptions.XMP_ITER_JUSTLEAFNODES);
|
||||
|
||||
auto property = xmp_string_new();
|
||||
while(xmp_iterator_next(iterator, null, null, property, null))
|
||||
{
|
||||
auto propertyString = fromStringz(xmp_string_cstr(property)).dup;
|
||||
if(propertyString != "x-default")
|
||||
{
|
||||
data ~= propertyString.idup;
|
||||
}
|
||||
}
|
||||
xmp_string_free(property);
|
||||
|
||||
xmp_iterator_free(iterator);
|
||||
|
||||
xmp_files_free(file);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
this()
|
||||
{
|
||||
xmp_init();
|
||||
|
||||
_xmp = xmp_new_empty();
|
||||
}
|
||||
|
||||
~this()
|
||||
{
|
||||
xmp_free(_xmp);
|
||||
|
||||
xmp_terminate();
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue