diff --git a/dub.sdl b/dub.sdl index 6bd83ed..1b09b05 100644 --- a/dub.sdl +++ b/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" diff --git a/dub.selections.json b/dub.selections.json index 3400003..0c49b99 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -1,6 +1,7 @@ { "fileVersion": 1, "versions": { - "dfuse": {"path":"dfuse"} + "dfuse": {"path":"dfuse"}, + "exempi-d": "0.1.0" } } diff --git a/source/tagproviders/dublincore.d b/source/tagproviders/dublincore.d index e6c1eb9..dd8d88e 100644 --- a/source/tagproviders/dublincore.d +++ b/source/tagproviders/dublincore.d @@ -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