immich improvements
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "immichpathtraverser.h"
|
||||
#include "logger.h"
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QSaveFile>
|
||||
|
||||
ImmichPathTraverser::ImmichPathTraverser(const ImmichConfig &configIn)
|
||||
: PathTraverser(""),
|
||||
@@ -17,6 +20,7 @@ void ImmichPathTraverser::loadAssets()
|
||||
{
|
||||
assetIds.clear();
|
||||
assetNames.clear();
|
||||
assetDateTimes.clear();
|
||||
QVector<ImmichAsset> assets = client.fetchAssets();
|
||||
for (const auto &asset : assets)
|
||||
{
|
||||
@@ -24,6 +28,8 @@ void ImmichPathTraverser::loadAssets()
|
||||
continue;
|
||||
assetIds.append(asset.id);
|
||||
assetNames.insert(asset.id, asset.originalFileName);
|
||||
if (!asset.exifDateTime.isEmpty())
|
||||
assetDateTimes.insert(asset.id, asset.exifDateTime);
|
||||
}
|
||||
Log("Immich assets loaded: ", assetIds.size());
|
||||
lastRefresh = QDateTime::currentDateTime();
|
||||
@@ -44,6 +50,12 @@ const std::string ImmichPathTraverser::getImagePath(const std::string image) con
|
||||
QString assetId = QString::fromStdString(image);
|
||||
QString name = assetNames.value(assetId);
|
||||
QString path = cache.getCachedPath(assetId, name, client);
|
||||
if (!path.isEmpty())
|
||||
{
|
||||
QString dateTime = assetDateTimes.value(assetId);
|
||||
if (!dateTime.isEmpty())
|
||||
writeExifSidecar(path, dateTime);
|
||||
}
|
||||
return path.toStdString();
|
||||
}
|
||||
|
||||
@@ -66,3 +78,29 @@ bool ImmichPathTraverser::shouldReloadImages() const
|
||||
{
|
||||
return refreshDue();
|
||||
}
|
||||
|
||||
void ImmichPathTraverser::writeExifSidecar(const QString &imagePath, const QString &dateTime) const
|
||||
{
|
||||
if (imagePath.isEmpty() || dateTime.isEmpty())
|
||||
return;
|
||||
|
||||
QString sidecarPath = imagePath + ".exif";
|
||||
QFileInfo info(sidecarPath);
|
||||
if (info.exists())
|
||||
{
|
||||
QFile existing(sidecarPath);
|
||||
if (existing.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QString current = QString::fromUtf8(existing.readAll()).trimmed();
|
||||
existing.close();
|
||||
if (current == dateTime.trimmed())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QSaveFile file(sidecarPath);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
file.write(dateTime.trimmed().toUtf8());
|
||||
file.commit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user