|
|
|
@ -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 file = xmp_files_open_new(path.toStringz(), XmpOpenFileOptions.XMP_OPEN_READ);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
auto exiftool = execute(["exiftool", "-b", "-" ~ element, path]);
|
|
|
|
|
auto rawData = exiftool.output;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this()
|
|
|
|
|
{
|
|
|
|
|
xmp_init();
|
|
|
|
|
|
|
|
|
|
_xmp = xmp_new_empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~this()
|
|
|
|
|
{
|
|
|
|
|
xmp_free(_xmp);
|
|
|
|
|
|
|
|
|
|
return splitLines(rawData);
|
|
|
|
|
xmp_terminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|