Drag Drop sorting by distance attempt
This commit is contained in:
16
Metadata/Models/Stateless/IMetadata.cs
Normal file
16
Metadata/Models/Stateless/IMetadata.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace View_by_Distance.Metadata.Models.Stateless;
|
||||
|
||||
public interface IMetadata
|
||||
{
|
||||
|
||||
string? TestStatic_GetFaceEncoding(string file) =>
|
||||
GetFaceEncoding(file);
|
||||
static string? GetFaceEncoding(string file) =>
|
||||
Metadata.GetFaceEncoding(file);
|
||||
|
||||
string? TestStatic_GetFaceLocation(string file) =>
|
||||
GetFaceLocation(file);
|
||||
static string? GetFaceLocation(string file) =>
|
||||
Metadata.GetFaceLocation(file);
|
||||
|
||||
}
|
58
Metadata/Models/Stateless/Metadata.cs
Normal file
58
Metadata/Models/Stateless/Metadata.cs
Normal file
@ -0,0 +1,58 @@
|
||||
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? GetFaceLocation(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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user