Implement basic Dublin Core tag provider

This commit is contained in:
Les De Ridder 2016-10-16 02:49:21 +02:00
parent ec3545f119
commit 5187be0e01
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
2 changed files with 60 additions and 1 deletions

View File

@ -1,6 +1,9 @@
module dtagfs.tagprovider;
class TagProvider
interface TagProvider
{
string[] getTags(string path);
@property
bool cacheReads();
}

View File

@ -0,0 +1,56 @@
module dtagfs.dublincore;
import std.process;
import std.string;
import std.algorithm;
import std.array;
import dtagfs.tagprovider;
class DublinCoreTagProvider : TagProvider
{
override string[] getTags(string path)
{
//TODO: Make prefixes configurable
string[] tags;
std.stdio.writeln(path);
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;
return tags;
}
string[] getElementData(string element)(string path)
{
//TODO: Use a proper metadata library instead of exiftool
auto exiftool = execute(["exiftool", "-b", "-" ~ element, path]);
auto rawData = exiftool.output;
string[] data;
foreach(line; splitLines(rawData))
{
if(indexOf(line, ' ') == -1)
{
data ~= line;
}
else
{
data ~= '"' ~ line ~ '"';
}
}
return data;
}
@property
override bool cacheReads()
{
return true;
}
}