Metadata
This commit is contained in:
@ -42,6 +42,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Property\Property.csproj" />
|
||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -4,8 +4,8 @@ using Phares.Shared;
|
||||
using ShellProgressBar;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Metadata.Query.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
namespace View_by_Distance.Metadata.Query;
|
||||
@ -56,18 +56,18 @@ public class MetadataQuery
|
||||
{ }
|
||||
}
|
||||
|
||||
private List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> GetCollection(long ticks)
|
||||
private List<(string FileName, string TagGroup, string TagIdName, string Value)> GetCollection(long ticks)
|
||||
{
|
||||
int count;
|
||||
string json;
|
||||
string message;
|
||||
string fileName;
|
||||
FileInfo fileInfo;
|
||||
FilePath filePath;
|
||||
FileHolder fileHolder;
|
||||
ProgressBar progressBar;
|
||||
ExifDirectory exifDirectory;
|
||||
const string fileSearchFilter = "*";
|
||||
const bool useCeilingAverage = true;
|
||||
const string directorySearchFilter = "*";
|
||||
Dictionary<string, List<KeyValuePair<string, string>>>? dictionary;
|
||||
List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> collection = [];
|
||||
List<(string FileName, string TagGroup, string TagIdName, string Value)> collection = [];
|
||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||
ReadOnlyCollection<string[]> filesCollection = Shared.Models.Stateless.Methods.IDirectory.GetFilesCollection(_PropertyConfiguration.RootDirectory, directorySearchFilter, fileSearchFilter, useCeilingAverage);
|
||||
foreach (string[] files in filesCollection)
|
||||
@ -78,57 +78,33 @@ public class MetadataQuery
|
||||
progressBar = new(files.Length, message, options);
|
||||
foreach (string file in files)
|
||||
{
|
||||
count = 0;
|
||||
progressBar.Tick();
|
||||
json = File.ReadAllText(file);
|
||||
fileName = Path.GetFileName(file);
|
||||
dictionary = JsonSerializer.Deserialize<Dictionary<string, List<KeyValuePair<string, string>>>>(json);
|
||||
if (dictionary is null)
|
||||
continue;
|
||||
foreach (KeyValuePair<string, List<KeyValuePair<string, string>>> keyValuePair in dictionary)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> keyValue in keyValuePair.Value)
|
||||
count++;
|
||||
}
|
||||
foreach (KeyValuePair<string, List<KeyValuePair<string, string>>> keyValuePair in dictionary)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> keyValue in keyValuePair.Value)
|
||||
collection.Add(new(fileName, count.ToString("000000"), keyValuePair.Key, keyValue.Key, keyValue.Value));
|
||||
}
|
||||
fileInfo = new(file);
|
||||
fileHolder = FileHolder.Get(fileInfo);
|
||||
filePath = FilePath.Get(_PropertyConfiguration, fileHolder, index: null);
|
||||
exifDirectory = Metadata.Models.Stateless.Methods.IMetadata.GetExifDirectory(filePath);
|
||||
// exifDirectory.ExifDirectoryBase.Artist;
|
||||
// exifDirectory.ExifDirectoryBase.WinComment;
|
||||
// exifDirectory.ExifDirectoryBase.Model;
|
||||
// exifDirectory.ExifDirectoryBase.CameraOwnerName;
|
||||
// exifDirectory.ExifDirectoryBase.Make;
|
||||
// exifDirectory.ExifDirectoryBase.BodySerialNumber;
|
||||
// exifDirectory.ExifDirectoryBase.LensSerialNumber;
|
||||
// exifDirectory.ExifDirectoryBase.Software;
|
||||
// collection.Add(new(fileInfo.Name, keyValuePair.Key, keyValue.Key, keyValue.Value));
|
||||
}
|
||||
progressBar.Dispose();
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
private static Dictionary<string, List<string>> GetKeyValuePairs(List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> matches)
|
||||
{
|
||||
string key;
|
||||
string line;
|
||||
List<string>? valuePairs;
|
||||
Dictionary<string, List<string>> keyValuePairs = [];
|
||||
foreach ((string fileName, string count, string tagGroup, string tagIdName, string value) in matches)
|
||||
{
|
||||
key = $"{tagGroup}\t{tagIdName}\t{value.Trim()}";
|
||||
line = $"{tagGroup}\t{tagIdName}\t{value.Trim()}\t{count}\t{fileName}";
|
||||
if (!keyValuePairs.TryGetValue(key, out valuePairs))
|
||||
{
|
||||
keyValuePairs.Add(key, []);
|
||||
if (!keyValuePairs.TryGetValue(key, out valuePairs))
|
||||
throw new Exception();
|
||||
}
|
||||
valuePairs.Add(line);
|
||||
}
|
||||
return keyValuePairs;
|
||||
}
|
||||
|
||||
private void MetadataQueryFilesInDirectories(ILogger<Program>? logger, long ticks)
|
||||
{
|
||||
List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> collection = GetCollection(ticks);
|
||||
List<(string FileName, string TagGroup, string TagIdName, string Value)> collection = GetCollection(ticks);
|
||||
logger?.LogInformation($"Ready to query {collection.Count} entries?");
|
||||
IEnumerable<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> enumerable()
|
||||
IEnumerable<(string FileName, string TagGroup, string TagIdName, string Value)> enumerable()
|
||||
{
|
||||
foreach ((string FileName, string Count, string TagGroup, string TagIdName, string Value) l in collection)
|
||||
foreach ((string FileName, string TagGroup, string TagIdName, string Value) l in collection)
|
||||
{
|
||||
if (l.TagIdName.StartsWith("42016\t") && l.Value != "00000000000000000000000000000000")
|
||||
{
|
||||
@ -136,19 +112,18 @@ public class MetadataQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> matches = enumerable().ToList();
|
||||
List<(string FileName, string TagGroup, string TagIdName, string Value)> matches = enumerable().ToList();
|
||||
if (matches.Count != 0)
|
||||
{
|
||||
matches.Sort();
|
||||
StringBuilder stringBuilder = new();
|
||||
Dictionary<string, List<string>> keyValuePairs = GetKeyValuePairs(matches);
|
||||
foreach (KeyValuePair<string, List<string>> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (keyValuePair.Value.Count != 2)
|
||||
continue;
|
||||
foreach (string line in keyValuePair.Value)
|
||||
_ = stringBuilder.AppendLine(line);
|
||||
}
|
||||
// foreach (KeyValuePair<string, List<string>> keyValuePair in keyValuePairs)
|
||||
// {
|
||||
// if (keyValuePair.Value.Count != 2)
|
||||
// continue;
|
||||
// foreach (string line in keyValuePair.Value)
|
||||
// _ = stringBuilder.AppendLine(line);
|
||||
// }
|
||||
string checkFile = $"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv";
|
||||
string text = stringBuilder.ToString();
|
||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, text, updateToWhenMatches: null, compareBeforeWrite: true, updateDateWhenMatches: false);
|
||||
|
Reference in New Issue
Block a user