58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
namespace View_by_Distance.Metadata.Models.Stateless;
|
|
|
|
internal class Metadata
|
|
{
|
|
|
|
internal static string? GetFaceEncoding(string file)
|
|
{
|
|
string? result;
|
|
List<string> results = new();
|
|
const string comment = "Comment: ";
|
|
if (File.Exists(file))
|
|
{
|
|
IReadOnlyList<MetadataExtractor.Directory> directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(file);
|
|
foreach (MetadataExtractor.Directory directory in directories)
|
|
{
|
|
if (directory.Name != "PNG-tEXt")
|
|
continue;
|
|
foreach (MetadataExtractor.Tag tag in directory.Tags)
|
|
{
|
|
if (tag.Name != "Textual Data" || string.IsNullOrEmpty(tag.Description))
|
|
continue;
|
|
if (!tag.Description.StartsWith(comment))
|
|
continue;
|
|
results.Add(tag.Description);
|
|
}
|
|
}
|
|
}
|
|
result = results.Any() ? results[0][comment.Length..] : null;
|
|
return result;
|
|
}
|
|
|
|
internal static string? GetFaceX(string file)
|
|
{
|
|
string? result;
|
|
List<string> results = new();
|
|
const string artist = "Artist: ";
|
|
if (File.Exists(file))
|
|
{
|
|
IReadOnlyList<MetadataExtractor.Directory> directories = MetadataExtractor.ImageMetadataReader.ReadMetadata(file);
|
|
foreach (MetadataExtractor.Directory directory in directories)
|
|
{
|
|
if (directory.Name != "PNG-tEXt")
|
|
continue;
|
|
foreach (MetadataExtractor.Tag tag in directory.Tags)
|
|
{
|
|
if (tag.Name != "Textual Data" || string.IsNullOrEmpty(tag.Description))
|
|
continue;
|
|
if (!tag.Description.StartsWith(artist))
|
|
continue;
|
|
results.Add(tag.Description);
|
|
}
|
|
}
|
|
}
|
|
result = results.Any() ? results[0][artist.Length..] : null;
|
|
return result;
|
|
}
|
|
|
|
} |